的OAuth2"无效格兰特"从服务器响应 [英] OAuth2 "Invalid Grant" response from server

查看:235
本文介绍了的OAuth2"无效格兰特"从服务器响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问我的客户打在这个网址与他授权的Gmail帐户与他创建了谷歌API项目。

<$p$p><$c$c>https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=$c$c&access_type=offline&redirect_uri=http://www.XXXXXXXX.com/oauth2callback&client_id=XXXXXX.apps.googleusercontent.com&state=profile&approval_prompt=force

,然后请他给我提供了code参数从重定向的URL

<$p$p><$c$c>http://www.XXXXXXXX.com/oauth2callback?$c$c=4/jUxc2MdX0xmF-b4_I6v2SLMQMuxO.cvQLVEpcJMUXOl05ti8ZT3ZvsT9ddwI

然后我自己张贴此形式下的信息。

 &LT;形式的行动=htt​​ps://accounts.google.com/o/oauth2/token方法=后&GT;&LT;输入类型=隐藏的名字=grant_typeVALUE =authorization_ code&GT;
&LT;输入类型=TEXTNAME =code值=**是我从previous一步收到一个**&GT;
&LT;输入类型=隐藏的名字=CLIENT_IDVALUE =XXXXXXX.apps.googleusercontent.com&GT;
&LT;输入类型=隐藏的名字=client_secretVALUE =XXXXXXXXXXXX&GT;
&LT;输入类型=隐藏的名字=REDIRECT_URIVALUE =htt​​p://www.XXXXXX.com/oauth2callback&GT;
&LT;输入类型=提交值=提交&GT;&LT; /表及GT;

然后我得到以下错误

  {
    错误:invalid_grant
}

当我产生code URL参数我和执行下一步。我很顺利美元,以下响应psented p $

  {
 ACCESS_TOKEN:XXXXXXStBkRnGyZ2mUYOLgls7QVBxOg82XhBCFo8UIT5gM,
 token_type:旗手,
 expires_in:3600,
 refresh_token:XXXXXX3SEBX7F2cfrHcqJEa3KoAHYeXES6nmho
}

但是,如果客户端生成URL参数code然后我看到了无效授予错误。

我的客户是英国,我在另一个国家。任何人都可以请确认是否它是错误的,因为客户端生成在另一国code参数和我使用的code在另一个国家?

先谢谢了。


解决方案

您可以要求在客户端生成code以及后续的刷新令牌自己。给他访问上述生成refresh_token所在的形式。

然后你可以用refresh_token生成access_tokens。

希望它可以解决你的问题。

I ask my client to hit at this URL with his authorized gmail account with which he has created the google api project.

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=http://www.XXXXXXXX.com/oauth2callback&client_id=XXXXXX.apps.googleusercontent.com&state=profile&approval_prompt=force

and then ask him to provide me the code parameter from the redirected URL

http://www.XXXXXXXX.com/oauth2callback?code=4/jUxc2MdX0xmF-b4_I6v2SLMQMuxO.cvQLVEpcJMUXOl05ti8ZT3ZvsT9ddwI

Then i myself post this form with following info.

<form action="https://accounts.google.com/o/oauth2/token" method="post" >

<input type="hidden" name="grant_type" value="authorization_code" >
<input type="text" name="code" value="**is the one i recieved from previous step**">
<input type="hidden" name="client_id" value="XXXXXXX.apps.googleusercontent.com" >
<input type="hidden" name="client_secret" value="XXXXXXXXXXXX" >
<input type="hidden" name="redirect_uri" value="http://www.XXXXXX.com/oauth2callback" >
<input type="submit" value="Submit">

</form>

and then i get the following error

{
    "error" : "invalid_grant"
}

When i generate the code url param myself and perform the next step. i am successfully presented with following response

{
  "access_token" : "XXXXXXStBkRnGyZ2mUYOLgls7QVBxOg82XhBCFo8UIT5gM",
  "token_type" : "Bearer",
  "expires_in" : 3600,
  "refresh_token" : "XXXXXX3SEBX7F2cfrHcqJEa3KoAHYeXES6nmho"
}

But if the client generate the url param "code" then i see the invalid grant error.

My Client is in UK and i am in another country. Can anybody please confirm if it's the error because client is generating the code param in another country and i am using that code in another country ?

Thanks in advance.

解决方案

You may ask the client to generate the code PLUS the subsequent refresh token himself. Give him the access to the form above where the refresh_token is generated.

Then you can use refresh_token to generate access_tokens.

Hope it fixes your problem.

这篇关于的OAuth2&QUOT;无效格兰特&QUOT;从服务器响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆