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 的文档你会发现它也说。
如果您的应用处于测试阶段,请将其设置为生产环境,您的刷新 token 将停止过期。
因此,只要您的应用处于生产状态,用户就不会撤销您的访问权限,并且他们为该用户提供的未完成刷新 token 少于 50 个,并且您在过去六个月中至少使用过一次。 (gmail 范围内用户不更改密码)。刷新 token 不应过期。
话虽这么说,您的系统应该设计为处理刷新 token 过期并再次请求用户访问。如果这是后端系统,则通知管理员。
关于google-api - 我想永远使用 Google API 刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71777420/