2012-03-02 33 views
0

我爲什麼得到openAuth protocol errordotnetOpenAuth在協議錯誤上失敗。它是否是TokenManager的ServiceProviderDescription?

{"The remote server returned an error: (400) Bad Request."}

at System.Net.HttpWebRequest.GetResponse() at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options) in c:\BuildAgent\work\a02b428f36957bca\src\DotNetOpenAuth\Messaging\StandardWebRequestHandler.cs:line 126

public static readonly ServiceProviderDescription ServiceDescription = new ServiceProviderDescription 
{ 
    RequestTokenEndpoint = 
     new MessageReceivingEndpoint("https://www.google.com/account/OAuthGetRequestToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest), 
    UserAuthorizationEndpoint = 
     new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthAuthorizeToken", 
HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest), 
    AccessTokenEndpoint = 
     new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetAccessToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest), 
    TamperProtectionElements = 
     new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() }, 
    }; 



public void StartOAuth() 
{ 
    var consumer = new WebConsumer(GoogleConsumer.ServiceDescription, new InMemoryTokenManager("user", "pass")); 
// Url to redirect to 
    var authUrl = new Uri("http://www.google.com"); 
// request access 
    consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(authUrl, null, null)); 

     throw new NoRedirectToAuthPageException(); 
    } 

回答

0

我不知道這是否會導致你看到的錯誤,但你傳遞谷歌自己的URL作爲回調URL?這似乎是錯誤的。您需要將URL傳遞到您自己的站點(將調用WebConsumer.ProcessUserAuthorization)作爲PrepareRequestUserAuthorization方法的第一個參數。

我也注意到,你在你的請求令牌URL中缺少一個「s」:https://www.google.com/account*s*/OAuthGetRequestToken

這很可能會打破它。

+0

我仍然在本地主機上運行。試圖改變到一些本地主機的網址,但它沒有幫助。我想使用DNOA,但是我認爲它在http://www.matlus.com/oauth-c-library/ – 2012-03-04 08:59:47

+0

中出現的標題中缺少一些內容,可能的罪魁禍首是更新的答案。 – 2012-03-05 01:32:58

相關問題