我想從我的ASP.NET MVC C#應用程序中使用OAuth驗證FreshBooks API。以下是我迄今爲止:通過DotNetOpenAuth驗證FreshBooks
我在這裏使用DotNetOpenAuth是代碼我在我的控制器操作
if (TokenManager != null)
{
ServiceProviderDescription provider = new ServiceProviderDescription();
provider.ProtocolVersion = ProtocolVersion.V10a;
provider.AccessTokenEndpoint = new MessageReceivingEndpoint ("https://myfbid.freshbooks.com/oauth/oauth_access.php", DotNetOpenAuth.Messaging.HttpDeliveryMethods.PostRequest);
provider.RequestTokenEndpoint = new DotNetOpenAuth.Messaging.MessageReceivingEndpoint("https://myfbid.freshbooks.com/oauth/oauth_request.php", DotNetOpenAuth.Messaging.HttpDeliveryMethods.PostRequest);
provider.UserAuthorizationEndpoint = new DotNetOpenAuth.Messaging.MessageReceivingEndpoint("https://myfbid.freshbooks.com/oauth/oauth_authorize.php", DotNetOpenAuth.Messaging.HttpDeliveryMethods.GetRequest);
provider.TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() };
var consumer = new WebConsumer(provider, TokenManager);
var response = consumer.ProcessUserAuthorization();
if (response != null)
{
this.AccessToken = response.AccessToken;
}
else
{
// we need to request authorization
consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(
new Uri("http://localhost:9876/home/testoauth/"), null, null));
}
}
的TokenManager是具備DotNetOpenAuth樣本同一類的,我我設定了FreshBooks給我的消費者祕密。
在consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(...))
我有以下異常:
"The remote server returned an error: (400) Bad Request.".
上午我做正確嗎?基於FreshBooks文檔和應能正常工作的DotNetOpenAuth示例。
是否有一種更簡單的方法來使用OAuth進行身份驗證,因爲DotNetOpenAuth對於簡單地使用OAuth身份驗證有點巨大?
感謝分享,我承認你的庫使用簡單,雖然我已經得到了相同的400錯誤的請求錯誤,我要開始認爲我與FreshBooks有關而不是我的實施。我會直接與他們覈對。 – 2011-02-12 13:03:06