Linkedin Oauth问题-oauth_verifier [英] Linkedin Oauth Issue - oauth_verifier

查看:88
本文介绍了Linkedin Oauth问题-oauth_verifier的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将我的JSAPI令牌交换为REST Oauth令牌时遇到一些问题( https://developer.linkedin.com/documents/exchange-jsapi-tokens-rest-api-oauth-tokens )

Having some problems trying to exchange my JSAPI tokens for REST Oauth Tokens (https://developer.linkedin.com/documents/exchange-jsapi-tokens-rest-api-oauth-tokens)

我正在使用此库- http://code.google.com/p/oauth-php/-与PECL扩展相反,因为我无法在服务器上安装扩展.

I'm using this library - http://code.google.com/p/oauth-php/ - As opposed to the PECL extension as I'm unable to install extensions onto the server.

似乎有很多类似的问题,但没有一个能真正回答这个问题-如何使用上述库向Linkedin进行身份验证.

There seem to be plenty of similar questions, but none which actually answer the question - How to use the above library to authenticate with Linkedin.

我的代码如下:

    $cookie_name        = "linkedin_oauth_" . $this->_c->linkedin_api_key;
    $credentials_json   = stripslashes($_COOKIE[$cookie_name]);
    $credentials        = json_decode($credentials_json);

    // Get the Access Token + Secret
    $access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken';

    OAuthStore::instance("2Leg", array(
        'consumer_key'      => $this->_c->linkedin_api_key,
        'consumer_secret'   => $this->_c->linkedin_api_secret
    ));

    try {

        $request = new OAuthRequester($access_token_url, 'POST', array(
            'xoauth_oauth2_access_token' => $credentials->access_token
        ));

        $result = $request->doRequest();

    } catch(OAuthException2 $e) {

        print_r($e->getMessage());

    }

catch语句输出:

The catch statement outputs:

Request failed with code 400: oauth_problem=parameter_absent&oauth_parameters_absent=oauth_verifier

如何获取此oauth_verifier?据我了解,如果我已经通过了xoauth_oauth2_access_token,就不需要它了吗?

How do I get this oauth_verifier? It was my understanding that I shouldn't need it if I was passing the xoauth_oauth2_access_token already?

我已经检查了所有变量I.E. $ credentials和$ this-> _ c以及所有变量都正确传递.

I've checked all of the variables I.E. $credentials and $this->_c and all of the variables are passing through correctly.

推荐答案

这实际上是oauth-php库中的错误.该库错误地处理了以xoauth_ *为前缀的参数,并以与处理oauth_ *参数相同的方式对待它们.这违反了OAuth规范,并且大多数(所有?)其他OAuth库都没有此问题.解决方法是执行以下操作:

This is actually a bug in the oauth-php library. The library is incorrectly handling parameters which are prefixed with xoauth_* and treating them the same way it handles oauth_* parameters. This is in violation of the OAuth spec and most (all?) other OAuth libraries don't have this issue. The fix is to do the following:

在文件OAuthRequestSigner.php中,找到以下内容:

Inside the file OAuthRequestSigner.php, find the following:

1)在getAuthorizationHeader函数中,找到显示以下内容的行:

1) inside the getAuthorizationHeader function, find the line which reads:

if (strncmp($name, 'oauth_', 6) == 0 || strncmp($name, 'xoauth_', 7) == 0)

并将其更改为:

if (strncmp($name, 'oauth_', 6) == 0)

2)在函数getQueryString中,找到以下内容:

2) Inside the function getQueryString, find the line which reads:

||  (strncmp($name, 'oauth_', 6) != 0 && strncmp($name, 'xoauth_', 7) != 0))

并将其更改为:

||  (strncmp($name, 'oauth_', 6) != 0)

此后,您所需要做的基本上与您已经在做的相同,如下所示:

After that, all you need to do is essentially the same as you were already doing, which is the following:

try {

    $request = new OAuthRequester($access_token_url, "POST", array('xoauth_oauth2_access_token' => $access_token));

    $result = $request->doRequest();

    var_dump($result);

} catch(OAuthException2 $e) {

    print_r($e->getMessage());

}

您应该已经准备就绪.如果您还有其他问题,请随时与我们的开发者论坛和我本人联系.否则团队中的其他人将很乐意为您提供帮助.

And you should be all set. If you have any further issues, please do not hesitate to reach out on our developer forums and either myself or someone else on the team would be happy to help.

享受!

-杰里米

这篇关于Linkedin Oauth问题-oauth_verifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆