LinkedIn访问令牌请求 - 签名无效

时间:2012-11-12 10:27:32

标签: c# asp.net-mvc linkedin

我有以下代码。在第一阶段(获取OAuth令牌)期间一切正常,但在回调中(在获取访问令牌期间)我得到签名无效错误。有谁能帮我解答我做错了什么?

        public ActionResult LinkedInTest(string text)
    {
        var credentials = new OAuthCredentials
                              {
                                  CallbackUrl = "http://localhost:60739/Calendar/Callback",
                                  ConsumerKey = ApiKey,
                                  ConsumerSecret = ApiSecret,
                                  Verifier = "123456",
                                  Type = OAuthType.RequestToken
                              };

        var client = new RestClient {Authority = "https://api.linkedin.com/uas/oauth", Credentials = credentials};
        var request = new RestRequest {Path = "requestToken"};
        RestResponse response = client.Request(request);

        token = response.Content.Split('&')[0].Split('=')[1];
        textToPost = text;
        Response.Redirect("https://api.linkedin.com/uas/oauth/authorize?oauth_token=" + token);
        return null;
    }

    public ActionResult Callback()
    {
        token = Request["oauth_token"];
        verifier = Request["oauth_verifier"];
        var credentials = new OAuthCredentials
                              {
                                  ConsumerKey = ApiKey,
                                  ConsumerSecret = ApiSecret,
                                  Token = token,
                                  TokenSecret = "",
                                  Verifier = verifier,
                                  Type = OAuthType.AccessToken,
                                  ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                                  SignatureMethod = OAuthSignatureMethod.HmacSha1,
                                  Version = "1.0"
                              };

        var client = new RestClient
                         {
                             Authority = "https://api.linkedin.com/uas/oauth",
                             Credentials = credentials,
                             Method = WebMethod.Post
                         };
        var request = new RestRequest {Path = "accessToken"};
        RestResponse response = client.Request(request);
        return Content(response.Content);
    }

1 个答案:

答案 0 :(得分:0)