1

我正在尝试将版本升级DotNetOpenAuth4.2.2.13055, 在 Google dotnet 客户端库中。所以我下载了最新的 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,我错过了什么吗?

4

1 回答 1

2

我想知道问题是否在于较新的 DNOA 版本默认支持将客户端凭据放在 HTTP 标头中。如果您创建您的客户端类,将不同的客户端凭据提供程序传递给构造函数,它可能对您有用。

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

ClientCredentialApplicator.PostParameter(clientSecret)
于 2013-03-05T05:23:13.557 回答