【问题标题】:Magento oAuth authorisation failedMagento oAuth 授权失败
【发布时间】:2017-08-11 19:41:46
【问题描述】:

我在 magento 中遇到了 oAuth 身份验证问题。

我使用以下指南创建连接: http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html

首先,我为 magento / System / WebServices / REST 中的所有帐户授予了所有权限......我还创建了 oAuth Consumer。我得到了两个变量(密钥和秘密)。

根据指南(获取未经授权的请求令牌),我为 Firefox 配置了 RESTClient。选择 oAuth 1.0 选项,从 magento 插入数据并将它们添加到标题中。

现在我有类似的东西:

http://www.mg19.local/oauth/initiate

OAuth oauth_version="1.0",
oauth_signature_method="PLAINTEXT",
oauth_nonce="pzmp8IZuroEP6gf",
oauth_timestamp="1410271763",
oauth_consumer_key="9ad2067e70a4c3b799ab2799203b3e3b",
oauth_signature="a37633084e79432568181ef00410140e%26"

如果我提交这个,我会得到以下错误:

状态码:400 错误请求

oauth_problem=parameter_absent&oauth_parameters_absent=oauth_callback

我不知道回调链接的主要用途,所以我使用了随机链接。例如:http://www.mg19.local

当我提交时

http://www.mg19.local/oauth/initiate/?oauth_callback=http://www.mg19.local

我得到以下结果:

oauth_token=e00fc8386ba523bdd1d79a2fe61d59cb&oauth_token_secret=ca0d999010b2b149e2d51feefc328722&oauth_callback_confirmed=true

根据指南,我移至第二步(用户授权):

我从对请求的响应中复制了数据。并转发链接:

http://www.mg19.local/oauth/authorize

我重定向到以下页面:

授权申请 邮递员请求访问您的帐户

授权后应用程序将可以访问您的帐户。

授权 |拒绝

当我选择授权时,我收到以下错误:

发生错误。您的授权请求无效。

使用xDebug我发现问题就在附近:

/**
 * Load token object, validate it depending on request type, set access data and save
 *
 * @return Mage_Oauth_Model_Server
 * @throws Mage_Oauth_Exception
 */
protected function _initToken()
{
....
        } elseif (self::REQUEST_AUTHORIZE == $this->_requestType) {
            if ($this->_token->getAuthorized()) {
                $this->_throwException('', self::ERR_TOKEN_USED);
...

我不确定,但我认为,一旦成功完成自动化,我就会从索引转到帐户区域页面,当授权再次开始时 - 它失败了,我再次进入索引。

请给点建议。

【问题讨论】:

    标签: php rest magento oauth


    【解决方案1】:

    就我所见,回调 URL 是搞砸了整个事情的那个。回调是 OAuth 中最重要的环节。回调应该是指向您网站的有效 URL。

    一旦用户登录身份验证服务器(在您的情况下为 Magneto),Magneto 将对您使用 oauth_verifier 提供的回调 URI 进行回调。如下:

    /callback?oauth_token=tz2kmxyf3lagl3o95xnox9ia15k6mpt3&oauth_verifier=cbwwh03alr5huiz5c76wi4l21zf05eb0
    

    然后您的服务器应该所有令牌 API /oauth/token 以及下面所有必需的授权标头。从您提供的 Magneto 文档链接粘贴

    oauth_consumer_key - the Consumer Key value provided after the registration of the application.
    oauth_nonce - a random value, uniquely generated by the application.
    oauth_signature_method - name of the signature method used to sign the request. Can have one of the following values: HMAC-SHA1, RSA-SHA1, and PLAINTEXT.
    oauth_signature - a generated value (signature).
    oauth_timestamp - a positive integer, expressed in the number of seconds since January 1, 1970 00:00:00 GMT.
    oauth_token - the oauth_token value (Request Token) received from the previous steps.
    oauth_verifier - the verification code that is tied to the Request Token.
    oauth_version - OAuth version.
    

    希望这能说明问题。请阅读您粘贴的链接的用户授权和获取访问令牌部分。

    【讨论】:

      【解决方案2】:

      我正在使用 Guzzle,但我真的很难用它。就我而言,它失败了,因为我使用的是oauth_callback 而不是callback,当我将其更改为:

          use GuzzleHttp\Client;
          use GuzzleHttp\HandlerStack;
          use GuzzleHttp\Subscriber\Oauth\Oauth1;
      
          $stack = HandlerStack::create();
      
          $middleware = new Oauth1([
              'consumer_key'    => $key,
              'consumer_secret' => $secret,
              'token'           => null,
              'token_secret'    => null,
              'callback'    => 'https://callback.co.uk'
          ]);
          $stack->push($middleware);
      
          $client = new Client([
              'base_uri' => $magentoCredentials->shopUrl,
              'handler' => $stack
          ]);
      
          $res = $client->post('/oauth/initiate?oauth_callback', ['auth' => 'oauth']);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-15
        • 2014-02-14
        • 2020-04-03
        • 2021-06-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多