已经有一段时间了,仍然不知道原因。 我们正在使用DotNetOpenAuth.OAuth2通过Google登录登录我的后台办公室网站。我们在这里所做的是,我们创建了一个从WebServerClient扩展而来的google客户端,其中包含我们的google api TokenEndpoint和AuthorizationEndpoint
public GoogleClient(string clientIdentifier, string clientCredentialApplicator)
: base(new AuthorizationServerDescription
{
TokenEndpoint = new Uri(@"https://accounts.google.com/o/oauth2/token"),
AuthorizationEndpoint = new Uri(@"https://accounts.google.com/o/oauth2/auth"),
ProtocolVersion = ProtocolVersion.V20,
})
{
ClientIdentifier = clientIdentifier;
ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(clientCredentialApplicator);
}
然后初始化此googleclient后,我们称为Authenticate,
client.RequestUserAuthorization(returnTo: callback,
scope: new string[] {"https://www.googleapis.com/auth/userinfo.profile"});
然后,当我们收到Google的回电后,我们将使用此客户端获取授权,例如这样的代码
var authorization = client.ProcessUserAuthorization(); = client.ProcessUserAuthorization();
在此步骤中,我们尝试从Google获取授予的AccessToken,但始终会返回“远程服务器返回错误:(400)错误的请求。”,以前有人遇到过此问题吗?
附上我收到的异常:
at DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options)
at DotNetOpenAuth.Messaging.Channel.RequestCore(IDirectedProtocolMessage request)
at DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage)
at DotNetOpenAuth.OAuth2.ClientBase.UpdateAuthorizationWithResponse(IAuthorizationState authorizationState, EndUserAuthorizationSuccessAuthCodeResponse authorizationSuccess)
at DotNetOpenAuth.OAuth2.WebServerClient.ProcessUserAuthorization(HttpRequestBase request)
谢谢