问题交换LInkedIn javascript令牌以休息oauth令牌

时间:2015-05-20 14:28:13

标签: oauth linkedin

我正在使用位于https://developer-programs.linkedin.com/documents/exchange-jsapi-tokens-rest-api-oauth-tokens的文章将我的Javascript访问令牌交换为REST OAuth令牌。

按照此处的说明操作后,无论我做什么,我只会收到 400 Bad Request 回复。

我用于Facebook并希望用LinkedIn重新创建的流程是;前端对LinkedIn进行身份验证并将访问令牌传递给我的API,然后API获取所有必要的用户信息并将我自己的持票人令牌传递回客户端,等等。

不幸的是,LinkedIn并没有很好地使用它,我需要将我的令牌从其Javascript令牌转换为OAuth令牌。

我通过了LinkedIn给我的API我的API,它看起来像下面的那样(OAuthBase是http://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs

access_token: "oxmKI9aU4RCfksdegZ3obZGHK-vo6Q4-4FSQk"
member_id: "AmjWCF7ExN"
signature: "t8KEbLjJ+r6uM42tUwfJm5yWp70="
signature_method: "HMAC-SHA1"
signature_order: ["access_token","member_id"]
signature_version: "1"

然后我试图打电话给https://api.linkedin.com/uas/oauth/accessToken进行实际交换。我的代码是:

public async Task<IHttpActionResult> ConvertLinkedInToken(LinkedInCovertTokenObject val)
    {
        string normalizeduri;
        string normalizedparams;            

        OAuthBase o = new OAuthBase();
        string signature = o.GenerateSignature(new Uri("https://api.linkedin.com/uas/oauth/accessToken"), Startup.linkedInAuthOptions.ClientId, Startup.linkedInAuthOptions.ClientSecret, val.access_token, null, "POST", o.GenerateTimeStamp(), o.GenerateNonce(), out normalizeduri, out normalizedparams);

        var client = new HttpClient();
        var uri = new Uri("https://api.linkedin.com/uas/oauth/accessToken?" +
            "oauth_consumer_key=" + Startup.linkedInAuthOptions.ClientId +
            "&xoauth_oauth2_access_token=" + val.access_token +
            "&signature_method=HMAC-SHA1" +
            "&signature=" + signature
        );

        var response = await client.GetAsync(uri);

        return Ok();
    }

无论我怎么玩,我从LinkedIn回来都是一个400 Bad Request,没有任何其他有用的信息。

1)如何在我的c#api

中将LinkedIn JS令牌转换为Rest OAuth令牌

2 个答案:

答案 0 :(得分:3)

这就是我实现的目标:

在前端:

IN.User.authorize(function(){
  // here you can find oauth token
  var oauth_token = IN.ENV.auth.oauth_token;
  // send this token to your API endpoint
});

在你的API(curl示例)上,当然用前端收到的令牌替换OAUTH_TOKEN。

curl -X GET \
  'https://api.linkedin.com/v1/people/~:
(id,firstName,lastName,siteStandardProfileRequest,picture-url,email-
address)?format=json' \
  -H 'oauth_token: OAUTH_TOKEN'

答案 1 :(得分:1)

您正在查看LinkedIn的旧文档。从5月12日开始,LinkedIn已经开始在其API中进行新的更改,其中包括身份验证。据我所知,LinkedIn不再使用OAuth,因此您需要OAuth2.0进行身份验证。您应该查看此链接以获取更多信息: https://developer.linkedin.com/docs/signin-with-linkedin

相关问题