I am trying to access products through Customer account. To achieve this I am using sample code from oauth_customer.php magento documentation page.
Everything i
At last I found the solution myself. I decided to post here so it might be helpful for someone. Well by following the sample code from : https://docs.google.com/file/d/0BzCDl5a0zmSVdWdFMG9jMTB1TXM/edit?pli=1
I was able to get the redirect url. But the redirected path moved to 404 page as the redirect adds the redirect link with site URL. The code for redirecting to URL was $this->_redirectUrl($session->getBeforeAuthUrl(true));
I changed this code to header( "refresh:1;url=".$session->getBeforeAuthUrl(true));
So it redirected to the Authorization page successfully. I assume that magento takes some miliseconds to create its cookies. So I added some refresh time to it. Here is the AccountController class code:
{yourmagento}/app / code / community / Chalkfy / OAuthRedirect / controllers / AccountController.php
<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class Chalkfly_OAuthRedirect_AccountController extends Mage_Customer_AccountController {
protected function _loginPostRedirect()
{
$session = $this->_getSession();
// if this redirect is a result of the OAuth process, force the redirect
if(stristr($session->getBeforeAuthUrl(),"oauth/authorize?oauth_token=") == 0 )
{
echo "Redirecting Please Wait..";
// Redirect to the URL after get
header( "refresh:1;url=".$session->getBeforeAuthUrl(true));
// $this->_redirect($session->getBeforeAuthUrl(true));
}
else {
parent::_loginPostRedirect();
}
}
}
As bas_van_poppel said, by adding the form key to the appropiate phtml, you get rid of the redirect to the regular login page.
In order to avoid the redirection to the dashboard page and get redirected to your app, you need to remove the call to setAfterAuthUrl
in the _initForm
method on app/code/core/Mage/Oauth/controllers/AuthorizeController.php
:
/** @var $helper Mage_Core_Helper_Url */
$helper = Mage::helper('core/url');
$session // We don't want this: ->setAfterAuthUrl(Mage::getUrl('customer/account/login', array('_nosid' => true)))
->setBeforeAuthUrl($helper->getCurrentUrl());
After a successful login, Magento redirects the customer to the after_auth_url value in the customer session, if the value is not specified, it will redirect you to the value of before_auth_url.
This is just for illustrative purposes, you should follow best practices to override this core controller.
When using Oauth, the oauth consumer login form redirects to customer/account/loginPost.
The loginPost function redirects you to customer/account/login because the parameter formkey is missing.
Just add this in app/design/frontend/package/theme/template/oauth/authorize/form/login.phtml at the end of the form tag:
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
Redirect will work fine when you add this. Tested in Magento CE 1.9.0.0, EE 1.14.1.x
You can overwrite the controller or create an observer.
Here is a link that fix you issue: http://blog.belvg.com/magento-tips-how-to-redirect-a-user-to-other-page-than-his-account-page-after-login-in-magento.html