Skip to content

Instantly share code, notes, and snippets.

@SchumacherFM
Created March 26, 2014 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SchumacherFM/9774636 to your computer and use it in GitHub Desktop.
Save SchumacherFM/9774636 to your computer and use it in GitHub Desktop.
Magento 1.7 and maybe 1.8 OAuth redirect bug according http://www.magentocommerce.com/boards/viewthread/438434/ This solution integrates without any rewrites or overrides.
<?xml version="1.0"?>
<config>
<modules>
<Zookal_Customer>
<version>0.0.1</version>
</Zookal_Customer>
</modules>
<frontend>
<events>
<customer_login>
<observers>
<zookalcustomer_customer_login_oauth>
<class>zookalcustomer/observer_controller_oAuth</class>
<method>saveOAuthRedirectUrl</method>
</zookalcustomer_customer_login_oauth>
</observers>
</customer_login>
<controller_action_postdispatch_customer_account_loginPost>
<observers>
<zookalcustomer_customer_apply_oauth_url>
<class>zookalcustomer/observer_controller_oAuth</class>
<method>applyOAuthRedirectUrl</method>
</zookalcustomer_customer_apply_oauth_url>
</observers>
</controller_action_postdispatch_customer_account_loginPost>
</events>
</frontend>
</config>
<?php
class Zookal_Customer_Model_Observer_Controller_OAuth
{
/**
* @param string $url
*
* @return bool
*/
protected function _isOAuthUrl($url)
{
return strstr(strtolower($url), 'oauth/authorize?oauth_token=') !== FALSE;
}
/**
* Retrieve customer session model object
*
* @return Mage_Customer_Model_Session
*/
protected function _getSession()
{
return Mage::getSingleton('customer/session');
}
/**
* @see http://www.magentocommerce.com/boards/viewthread/438434/
*
* @fire customer_login
*/
public function saveOAuthRedirectUrl()
{
$session = $this->_getSession();
//if this redirect is a result of the OAuth process, force the redirect
if (TRUE === $this->_isOAuthUrl($session->getBeforeAuthUrl())) {
$session->setOauthRedirectUrl($session->getBeforeAuthUrl(TRUE));
}
}
/**
* @fire controller_action_postdispatch_customer_account_loginPost
*
* @param Varien_Event_Observer $observer
*/
public function applyOAuthRedirectUrl(Varien_Event_Observer $observer)
{
$session = $this->_getSession();
/** @var Mage_Customer_AccountController $controller */
$controller = $observer->getEvent()->getControllerAction();
if (TRUE === $this->_isOAuthUrl($session->getOauthRedirectUrl())) {
$controller->getResponse()->setRedirect($session->getOauthRedirectUrl());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment