google-api - 我想永远使用 Google API 刷新 token

标签 google-api google-oauth google-developers-console

Google API 有一个通过OAuth 认证获取refresh token 的过程,然后从refresh token 中获取access token 来验证回执。

前几天刷新 token 突然过期,收据验证失败。我们的服务停止处理计费。 以下是失败时的错误。

{
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
}

我以为每次使用刷新 token 都会重置它们的到期日期,那么它们为什么会过期呢? 我认为以下规则不适用。

You must write your code to anticipate the possibility that a granted refresh token might no longer work. these reasons:

  • The user has revoked your app's access.
  • The refresh token has not been used for six months.
  • The user changed passwords and the refresh token contains Gmail scopes.
  • The user account has exceeded a maximum number of granted (live) refresh tokens.
  • The user belongs to a Google Cloud Platform organization that has session control policies in effect. (https://developers.google.com/identity/protocols/oauth2)

我想永远使用刷新 token 。 提前谢谢你。

最佳答案

刷新 token 不会按设计过期有一些事情可能会导致它们过期,如您所列。但是还有一个你没有列出。

如果您查看 Experation 的文档你会发现它也说。

enter image description here

如果您的应用处于测试阶段,请将其设置为生产环境,您的刷新 token 将停止过期。

enter image description here

因此,只要您的应用处于生产状态,用户就不会撤销您的访问权限,并且他们为该用户提供的未完成刷新 token 少于 50 个,并且您在过去六个月中至少使用过一次。 (gmail 范围内用户不更改密码)。刷新 token 不应过期。

话虽这么说,您的系统应该设计为处理刷新 token 过期并再次请求用户访问。如果这是后端系统,则通知管理员。

关于google-api - 我想永远使用 Google API 刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71777420/

相关文章:

google-api - Google DriveService C# 泄漏 HttpConnection 对象

android - 在 Android 中使用 Google Books API

google-api - 在数据库中存储谷歌刷新 token ?

objective-c - YouTube API v3示例项目引发GTLJSONRPCErrorDomain -32602未经授权的错误

azure - Google Cloud Vision 反向图像搜索在 Azure 应用服务上失败,因为找不到 GOOGLE_APPLICATION_CREDENTIALS 文件

c# - 在 Web API 和 Swagger 中使用 Google 进行身份验证

perl - 使用 shuttlecloud 获取谷歌联系人

android - 谷歌开发控制台测试,无需将 apk 发送到生产环境

android - 播放控制台中的暂停音轨是什么意思

google-play - 坚持拒绝和更新循环谷歌播放控制台