【问题标题】:Gmail auth token expires within an hourGmail 身份验证令牌会在一小时内过期
【发布时间】:2021-01-29 03:52:04
【问题描述】:

Gmail 身份验证令牌在一小时后过期,有没有办法将令牌的生命周期延长至 24 小时或更长时间? 我正在使用以下方法:

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

【问题讨论】:

    标签: gmail google-oauth gmail-api google-authentication oauth2client


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您有一个刷新令牌,因此无需增加令牌 TTL

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

      令牌过期时间由所使用的 Google API 给出,这就是您获得刷新令牌的原因。根据Google Identity Platform Documentation 所说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.

      没有必要延长令牌的生命周期,在不再需要令牌时撤销令牌是一种很好的做法。只需确保您关注policies 即可确保您的应用程序安全。

      请记住,refresh token might stop working 出于以下原因之一:

      • 用户已撤消您应用的访问权限。
      • 刷新令牌已有六个月未使用。
      • 用户更改了密码,并且刷新令牌包含 Gmail 范围。
      • 用户帐户已超过授予(实时)刷新令牌的最大数量。

      参考

      Using OAuth 2.0 to Access Google APIs

      OAuth 2.0 Policies

      【讨论】:

        猜你喜欢
        • 2021-01-10
        • 2015-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-27
        • 2016-04-03
        • 2019-12-05
        相关资源
        最近更新 更多