2014-01-09 5 views
0

가 나는 사용자를 호출하는 것을 시도하고있다dotnetopenauth 트위터 API 1.1 서명 요청

enter code here 

트위터 1.1 API/show.json API에 대한 DNOA 라이브러리를 사용하여 stuсk

protected override AuthenticationResult VerifyAuthenticationCore(AuthorizedTokenResponse response) 
    { 
     string accessToken = response.AccessToken; 
     string str2 = response.ExtraData["user_id"]; 
     string userName = response.ExtraData["screen_name"]; 
     Uri location = new Uri("https://api.twitter.com/1.1/users/show.json?user_id=" + str2); 
     MessageReceivingEndpoint profileEndpoint = new MessageReceivingEndpoint(location, HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest); 
     HttpWebRequest request = base.WebWorker.PrepareAuthorizedRequest(profileEndpoint, accessToken); 
     Dictionary<string, string> dictionary = new Dictionary<string, string>(); 
     dictionary.Add("accesstoken", accessToken); 
     try 
     { 
      using (WebResponse wresponse = request.GetResponse()) 
      { 
       var str = Utilities.ProcessResponse(wresponse); 
       var json = JObject.Parse(str); 
       dictionary.AddNotEmpty("name", json.Value<string>("name")); 
       dictionary.AddNotEmpty("location", json.Value<string>("location")); 
       dictionary.AddNotEmpty("description", json.Value<string>("description")); 
       dictionary.AddNotEmpty("url", json.Value<string>("url")); 
      } 
     } 
     catch (Exception) 
     { 
     } 
     return new AuthenticationResult(true, base.ProviderName, str2, userName, dictionary); 
    } 

무엇이 트위터로 전송

GET https://api.twitter.com/1.1/users/show.json?user_id=2193937074 HTTP/1.1 
Authorization: OAuth oauth_token="2193937074-cgmZbmJIIb75f7MkQgbdjuvQaen2xzM1WFXXC7G",oauth_consumer_key="XVCgN3fkwzTGgeSm1FBa1Q",oauth_nonce="93UjjRkP",oauth_signature_method="HMAC-SHA1",oauth_signature="YzfXzU3VeEI9xl2SfuknPB33%2FiM%3D",oauth_version="1.0",oauth_timestamp="1389265955" 
Host: api.twitter.com 

responce는

012입니다 주요 차이점은 oauth_nonce의 길이처럼

GET https://api.twitter.com/1.1/users/show.json?user_id=2193937074 HTTP/1.1 
Authorization: OAuth oauth_consumer_key="XVCgN3fkwzTGgeSm1FBa1Q", oauth_nonce="dbf6f6c1aa6dc226de25265da3d63167", oauth_signature="K3Qfyc9qANFgckQNyqsaDWCnh%2BY%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1389266681", oauth_token="2193937074-cgmZbmJIIb75f7MkQgbdjuvQaen2xzM1WFXXC7G", oauth_version="1.0" 
Host: api.twitter.com 

그것은의를 loook : 3,121,278,656,146,916,878,903,210

dev.twitter의 OAuth를 도구 서명 헤더의 유효 샘플을 보여줍니다?

DNOA - oauth_nonce = "93UjjRkP"

의 OAuth 도구 - oauth_nonce = "dbf6f6c1aa6dc226de25265da3d63167"

답변

0

나는이 문제를 해결했다.

주된 문제는 서명이 어떻게 생성되는지, TokenSecret은 형성되는 것에서 제외된다는 것입니다. 이 동작의 핵심은 Base DotNetOpenAuth.AspNet.Clients.TwitterClient 클래스 내부에서 사용되는 AuthenticationOnlyCookieOAuthTokenManager 관리자입니다.

public class AuthenticationOnlyCookieOAuthTokenManager : IOAuthTokenManager 
{ 
... 
    public virtual void ReplaceRequestTokenWithAccessToken(string requestToken, string accessToken, string accessTokenSecret) 
    { 
     HttpCookie cookie = new HttpCookie("OAuthTokenSecret") { 
      Value = string.Empty, //<<< now it's empty 
      Expires = DateTime.UtcNow.AddDays(-5.0) 
     }; 
     this.Context.Response.Cookies.Set(cookie); 
    } 
... 
} 

tokenSecret을 제거하면됩니다.

해결 방법은 DotNetOpenAuth.AspNet.Clients.InMemoryOAuthTokenManager 클래스를 사용하는 것입니다. 익숙한 포스트 Custom OAuth client in MVC4/DotNetOpenAuth - missing access token secret

를 발견했다 또한

public class TwitterClient : DotNetOpenAuth.AspNet.Clients.OAuthClient 
{ 
    protected TwitterClient(string appKey, string appSecret) : 
     base ("twitter", 
      new DotNetOpenAuthWebConsumer(
       TwitterServiceDescription, 
       new InMemoryOAuthTokenManager(appKey, appSecret))) 
    { } 
... 
} 

: 그래서 당신은 필요 OAuthClient에서 파생 적절한 생성자를 구현