【问题标题】:Getting invalid grant while fetching access token from Google Oauth从 Google Oauth 获取访问令牌时获得无效授权
【发布时间】:2021-03-24 12:51:35
【问题描述】:

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

其实从googleapis...auth?...获取代码是没有问题的->返回码。

但是获取访问令牌返回错误:

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"
}

有什么建议吗?

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

解决方案:

当我尝试多次使用相同代码获取令牌时,谷歌会抛出 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.

【问题讨论】:

    标签: oauth-2.0 google-oauth


    【解决方案1】:

    当您尝试多次使用相同代码获取令牌时,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.
    

    【讨论】:

      猜你喜欢
      • 2015-02-24
      • 1970-01-01
      • 1970-01-01
      • 2018-10-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      相关资源
      最近更新 更多