Gmail身份验证令牌将在一小时内过期



Gmail身份验证令牌将在一小时内过期,有什么方法可以将令牌的使用寿命延长到24小时或更长时间吗?我使用以下方法:

const oAuth2Client = await new google.auth.OAuth2(client_id, client_secret, redirect);
// got the token
oAuth2Client.setCredentials(tokens);

您不需要增加令牌TTL,因为您有刷新令牌

首先看一看Gmail API示例,看看刷新令牌会发生什么。

令牌到期时间由所使用的Google API给定,这就是您获得刷新令牌的原因。根据谷歌身份平台文档,Access tokens have limited lifetimes. If your application needs access to a Google API beyond the lifetime of a single access token, it can obtain a refresh token. A refresh token allows your application to obtain new access tokens.

不需要增加令牌的生存期,在不再需要时撤销令牌是一种很好的做法。只要确保您遵循使应用程序安全的策略即可。

请记住,刷新令牌可能会因以下原因之一而停止工作:

  • 用户已吊销您的应用程序访问权限
  • 刷新令牌已经六个月没有使用了
  • 用户更改了密码,刷新令牌包含Gmail范围
  • 用户帐户已超过授予(实时(刷新令牌的最大数量

参考

使用OAuth 2.0访问Google API

OAuth 2.0策略

它应该过期,您只需要使用刷新令牌来刷新它。

最新更新