【问题标题】:Magento API REST customer not redirecting to Authentication PageMagento API REST 客户未重定向到身份验证页面
【发布时间】:2014-06-02 11:02:12
【问题描述】:

我正在尝试通过客户帐户访问产品。为此,我使用来自oauth_customer.php magento 文档页面的示例代码。
Everything is okay and working fine; but the thing I am facing is that whenever I login as customer after successful login page redirects to the Customer Dashboard instead of redirecting to the Authentication URL. 为此,我必须再次手动传递 URL 链接,因此它会重定向到身份验证页面,并在身份验证后显示我想要的任何内容。
我还尝试从链接中的示例代码扩展帐户控制器: https://docs.google.com/file/d/0BzCDl5a0zmSVdWdFMG9jMTB1TXM/edit?pli=1
但仍然没有运气。有没有像我们在管理员身份验证端一样在登录后再次创建回调 URL?

【问题讨论】:

    标签: api magento authentication redirect


    【解决方案1】:

    最后我自己找到了解决方案。我决定在这里发帖,这样可能对某人有帮助。好吧,通过以下示例代码:https://docs.google.com/file/d/0BzCDl5a0zmSVdWdFMG9jMTB1TXM/edit?pli=1 我能够获得重定向 url。但是重定向路径移动到 404 页面,因为重定向添加了带有站点 URL 的重定向链接。重定向到 URL 的代码是 $this->_redirectUrl($session->getBeforeAuthUrl(true));
    我将此代码更改为header( "refresh:1;url=".$session->getBeforeAuthUrl(true)); 所以它成功重定向到授权页面。我假设 magento 需要一些毫秒来创建它的 cookie。所以我添加了一些刷新时间。这是 AccountController 类代码: {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();
            }
    
    
        }
    
    
    }
    

    【讨论】:

      【解决方案2】:

      使用 Oauth 时,oauth 消费者登录表单会重定向到 customer/account/loginPost。

      loginPost 函数将您重定向到客户/帐户/登录,因为缺少参数 formkey。

      只需在 app/design/frontend/package/theme/template/oauth/authorize/form/login.phtml 的表单标签末尾添加这个:

      <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
      

      添加此项后,重定向将正常工作。在 Magento CE 1.9.0.0、EE 1.14.1.x 中测试

      【讨论】:

      • 好吧,这似乎阻止了 oauth 登录页面重定向到常规登录页面 - 但现在它只是重定向到仪表板。你如何让它重定向回应用程序?例如,如果您碰巧在另一个选项卡中登录了商店,那么 oauth“消费者”应用程序会导致 oauth 授权页面而不是 oauth 登录页面,并且授权页面会重定向回应用程序就好了。登录应该能够做到这一点。
      【解决方案3】:

      您可以覆盖控制器或创建观察者。

      这里有一个链接可以解决你的问题:http://blog.belvg.com/magento-tips-how-to-redirect-a-user-to-other-page-than-his-account-page-after-login-in-magento.html

      【讨论】:

        【解决方案4】:

        正如bas_van_poppel 所说,通过将表单键添加到适当的 phtml 中,您可以摆脱对常规登录页面的重定向。

        为了避免重定向到仪表板页面并重定向到您的应用程序,您需要在app/code/core/Mage/Oauth/controllers/AuthorizeController.php_initForm 方法中删除对setAfterAuthUrl 的调用:

            /** @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());
        

        成功登录后,Magento 将客户重定向到客户会话中的 after_auth_url 值,如果未指定该值,则会将您重定向到 before_auth_url 的值。

        这仅用于说明目的,您应该遵循最佳实践来覆盖此核心控制器。

        【讨论】:

          猜你喜欢
          • 2013-01-20
          • 1970-01-01
          • 2020-07-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多