2013-10-11 15 views
0

我使用DotNetOpenAuthWebConsumer.ProcessUserAuthorization返回null

所以..我越來越看好response其中有狀態Authenticated

這很好。

現在我想獲取用戶資料信息,但總是得到NULL

這是代碼。

private ServiceProviderDescription GetServiceDescription() 
     { 
      string ValidateTokenEndPoint = ConfigurationManager.AppSettings["identityOAuthValidateTokenEndPointUrl"]; 
      string ValidateAuthorizationHeaderEndPoint = ConfigurationManager.AppSettings["identityOAuthValidateAuthorizationHeaderEndPointUrl"]; 
      string AccessTokenEndPoint = ConfigurationManager.AppSettings["identityOAuthAccessTokenURL"]; 
      bool UseVersion10A = Convert.ToBoolean(ConfigurationManager.AppSettings["identityOAuthUseVersion10a"]); 
      string RequestTokenStr = ConfigurationManager.AppSettings["identityOAuthRequestTokenURL"]; 
      string UserAuthStr = ConfigurationManager.AppSettings["identityOAuthAuthorizeUserURL"]; 
      string AccessTokenStr = ConfigurationManager.AppSettings["identityOAuthAccessTokenURL"]; 
      string InvalidateTokenStr = ConfigurationManager.AppSettings["identityOAuthRequestInvalidateTokenURL"]; 

      return new ServiceProviderDescription 
      { 
       AccessTokenEndpoint = new MessageReceivingEndpoint(AccessTokenStr, HttpDeliveryMethods.PostRequest), 
       RequestTokenEndpoint = new MessageReceivingEndpoint(RequestTokenStr, HttpDeliveryMethods.PostRequest), 
       UserAuthorizationEndpoint = new MessageReceivingEndpoint(UserAuthStr, HttpDeliveryMethods.PostRequest), 
       TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() }, 
       ProtocolVersion = DotNetOpenAuth.OAuth.ProtocolVersion.V10a 
      }; 
     } 

void GetUserProfile() 
{ 
    var tokenManager = TokenManagerFactory.GetTokenManager(TokenManagerType.InMemoryTokenManager); 
    tokenManager.ConsumerKey = ConfigurationManager.AppSettings["identityOAuthConsumerKey"]; 
    tokenManager.ConsumerSecret = ConfigurationManager.AppSettings["identityOAuthConsumerSecret"]; 

var serviceDescription = GetServiceDescription(); 
var consumer = new WebConsumer(serviceDescription, tokenManager); 
var result = consumer.ProcessUserAuthorization(response); 

if (result != null) // It is always null 
{ 

} 

那麼我檢查了10次,我非常確定所有創建ServiceProviderDescription的URL都是正確的。

任何線索?

回答

0

最後檢查你的web.config應用程序鍵

添加鍵= 「identityOAuthConsumerKey」 值= 「把這裏正確的數據!」
add key =「identityOAuthConsumerSecret」value =「把這裏正確的數據!!!」

,如果你使用的hosts文件,你必須把正確的站點名稱以及

127.0.0.1 site1.host1.com