I have successfully authenticated with Google OAuth API. For the first time its running correctly. For accessing the same for the second time I am getting the following error:
"Error occurred while sending a direct message or getting the response."
Stack trace:
[WebException: The remote server returned an error: (400) Bad Request.]
System.Net.HttpWebRequest.GetResponse() +6038435
DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options) +410
[ProtocolException: Error occurred while sending a direct message or getting the response.]
DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options) +1618
DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request) +73
DotNetOpenAuth.Messaging.Channel.GetDirectResponse(HttpWebRequest webRequest) +82
DotNetOpenAuth.Messaging.Channel.RequestCore(IDirectedProtocolMessage request) +357
DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage) +158
DotNetOpenAuth.OAuth2.ClientBase.UpdateAuthorizationWithResponse(IAuthorizationState authorizationState, EndUserAuthorizationSuccessAuthCodeResponse authorizationSuccess) +319
DotNetOpenAuth.OAuth2.WebServerClient.ProcessUserAuthorization(HttpRequestInfo request) +885
for the method
private IAuthorizationState GetAuthorization(WebServerClient client)
{
String accesstoken = "";
IAuthorizationState state = AuthState;
if (state != null)
{
return state;
}
state = client.ProcessUserAuthorization(new HttpRequestInfo(HttpContext.Current.Request));
if (state != null && (!string.IsNullOrEmpty(state.AccessToken)
|| !string.IsNullOrEmpty(state.RefreshToken)))
{
accesstoken = state.AccessToken;
HttpContext.Current.Session["AUTH_STATE"] = _state = state;
return null;
}
string scope = TasksService.Scopes.TasksReadonly.GetStringValue();
OutgoingWebResponse response = client.PrepareRequestUserAuthorization(new[] {
scope,
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
});
response.Send();
return null;
}
private IAuthorizationState AuthState
{
get
{
return _state ?? HttpContext.Current.Session["AUTH_STATE"] as IAuthorizationState;
}
}
in the line
state = client.ProcessUserAuthorization(new HttpRequestInfo(HttpContext.Current.Request));
waiting for valuable responses and comments
Please check that you're calling client.ProcessUserAuthorization only once. Starting from second call with the same parameters it could proceed the "sending a direct message or getting the response" error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.