Php Magento oAuth授权失败

Php Magento oAuth授权失败,php,rest,magento,oauth,Php,Rest,Magento,Oauth,我对magento中的oAuth身份验证有问题 我使用以下指南创建连接: 首先,我为magento/System/WebServices/REST中的所有帐户授予了所有权限。。。我还创建了oAuth Consumer。我得到了两个变量(key和secret) 根据指南(获取未经授权的请求令牌),我为Firefox配置了RESTClient。选择oAuth 1.0选项,从magento插入数据并将其添加到标题中 现在我有了这样的东西: http://www.mg19.local/oauth/in

我对magento中的oAuth身份验证有问题

我使用以下指南创建连接:

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

根据指南(获取未经授权的请求令牌),我为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_缺席&oauth_parameters_缺席=oauth_回调

我不知道回调链接的主要用途,因此我使用了随机链接。例如:

当我提交

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);
...
我不确定,但我认为,一旦自动化成功完成,然后我从索引移动到帐户区域页面,当授权再次启动时——它失败了,我再次在索引上移动


请给出任何建议。

据我所见,回调URL正是把整个事情搞砸的URL。回调是OAuth中最重要的链接。回调应该是指向您的站点的有效URL

一旦用户登录到auth服务器(在您的例子中是磁电机),磁电机将对您随oauth_验证器提供的回调URI进行回调。如下图所示:

/callback?oauth_token=tz2kmxyf3lagl3o95xnox9ia15k6mpt3&oauth_verifier=cbwwh03alr5huiz5c76wi4l21zf05eb0
然后,您的服务器应该安装所有令牌API
/oauth/token
,以及下面所有必需的授权头。从您提供的文档链接粘贴

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.

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

我正在使用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']);