从 Google Oauth 获取访问令牌时获得无效授权

Getting invalid grant while fetching access token from Google Oauth

我知道这个问题被问过很多次,但目前我们在从 Google Oauth 获取访问令牌时遇到问题。实际上,“使用 Google 登录”对某些帐户有效,但对某些帐户无效。所以我们无法捕捉到确切的问题。

其实从googleapis...auth?...中获取code没有问题-> returncode.

但是获取访问令牌 return 错误:

https://oauth2.googleapis.com/token?code=4/0AY0...
&client_id=....apps.googleusercontent.com
&client_secret=...
&redirect_uri=...
&grant_type=authorization_code

我们遇到的一些情况:

{
    "error": "invalid_grant",
    "error_description": "Bad Request"
}

有什么建议吗?

注意:我做了一些研究,但 none 的建议有所帮助(拼写、检查服务器时间、将 access_type=offline 添加到第一个 OAuth 步骤 url 等。 )

解法:

当我多次尝试使用相同代码获取令牌时,google 抛出 invalid_grant 错误。

1. call https://oauth2.googleapis.com/token?code=my_code -> returns OK.
2. call same request again https://oauth2.googleapis.com/token?code=my_code -> returns invalid_grant.

当您尝试使用相同的代码多次获取令牌时,google 会抛出 invalid_grant 错误。

1. call https://oauth2.googleapis.com/token?code=my_code -> returns OK.
2. call same request again https://oauth2.googleapis.com/token?code=my_code -> returns invalid_grant.