ProcessUserAuthorization上的错误请求(DotNetOpenAuth 4.2.2.13055)

时间:2013-03-04 23:13:49

标签: dotnetopenauth

我正在尝试在Google dotnet客户端库中将DotNetOpenAuth版本升级为4.2.2.13055。 所以我下载了最新的dll - DotNetOpenAuth.Core,DotNetOpenAuth.OAuth2等(我们仍然无法使用NuGet)。

我做了一个小改动(改变了我用client_id和client_secret构建NativeApplcationClient的方式)来支持新版本。 然后,我尝试运行我们在示例存储库中的示例(例如https://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples),并且出现了错误的请求错误,如下所示:

 DotNetOpenAuth.Messaging.ProtocolException: Error occurred while sending a direct message or getting the response. --->
 System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetResponse()
   at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions opt
ions)
   --- End of inner exception stack trace ---
   at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions opt
ions)
   at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request)
   at DotNetOpenAuth.Messaging.Channel.GetDirectResponse(HttpWebRequest webRequest)
   at DotNetOpenAuth.Messaging.Channel.RequestCore(IDirectedProtocolMessage request)
   at DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage)
   at DotNetOpenAuth.OAuth2.ClientBase.UpdateAuthorizationWithResponse(IAuthorizationState authorizationState, EndUserAu
thorizationSuccessAuthCodeResponse authorizationSuccess)
   at DotNetOpenAuth.OAuth2.UserAgentClient.ProcessUserAuthorization(IAuthorizationState authorizationState, IDirectedPr
otocolMessage response)
   at DotNetOpenAuth.OAuth2.UserAgentClient.ProcessUserAuthorization(Uri actualRedirectUrl, IAuthorizationState authoriz
ationState)
   at Google.Apis.Authentication.OAuth2.DotNetOpenAuth.NativeApplicationClient.ProcessUserAuthorization(String authCode,
 IAuthorizationState authorizationState) in c:\code.google.com\google-api-dotnet-client\default_oauth2\Src\GoogleApis.Au
thentication.OAuth2\DotNetOpenAuth\NativeApplicationClient.cs:line 102
   at Google.Apis.Samples.TasksOAuth2.Program.GetAuthorization(NativeApplicationClient arg) in c:\code.google.com\google
-api-dotnet-client\samples_oauth2\Tasks.SimpleOAuth2\Program.cs:line 73
   at Google.Apis.Authentication.OAuth2.OAuth2Authenticator`1.LoadAccessToken() in c:\code.google.com\google-api-dotnet-
client\default_oauth2\Src\GoogleApis.Authentication.OAuth2\OAuth2Authenticator.cs:line 124

我还注意到第二个请求中存在不同(在使用令牌交换代码时):请求中添加了授权标头,并且正文缺少我的client_id和client_secret。

类似的代码适用于旧版本 - 4.0.0.11165, 我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

我想知道问题是新版DNOA版本是否支持默认情况下将客户端凭据放入HTTP标头 。如果您创建Client类,将其他客户端凭据提供程序传递到构造函数中,它可能适合您。

要将使用HTTP Authorization标头的行为更改回POST实体中传递客户端凭据,请实例化ClientBase派生类,将其作为参数传递给构造函数:

ClientCredentialApplicator.PostParameter(clientSecret)