【问题标题】:How TO Get Refresh Token using Google Service Account?如何使用 Google 服务帐户获取刷新令牌?
【发布时间】:2020-07-14 05:29:29
【问题描述】:

我想使用 Google 服务帐户生成刷新令牌。通过使用刷新令牌,我将生成访问令牌并调用 Google API。请务必让我知道。谢谢

【问题讨论】:

  • 这是一个奇怪的用例......但是无论如何,你的语言是什么?
  • @guillaumeblaquiere, javascript
  • @guillaumeblaquiere,您能否分享有关如何从服务帐户获取刷新令牌的步骤。谢谢

标签: google-cloud-platform google-cloud-storage google-contacts-api service-accounts refresh-token


【解决方案1】:

这里是使用默认服务帐户的示例:

    const {GoogleAuth} = require('google-auth-library');
    const auth = new GoogleAuth()
    const adc = await auth.getApplicationDefault()
    const refresh_token = await adc.credential.getAccessToken()
                 .then(value => value.res.data.refresh_token);

根据需要调整此代码!

【讨论】:

  • 但是我们在哪里传递私人、clientId 等服务帐户详细信息?是否有任何 API 可以使用服务帐户生成刷新令牌?
  • 对我来说最简单的方法是将服务帐户文件定义为 env var,即使在 nodeJS 中和调用getApplicationDefault() 之前,就像这样process.env.GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json";
猜你喜欢
  • 2021-04-24
  • 2019-03-20
  • 2014-08-17
  • 1970-01-01
  • 2015-04-29
  • 2016-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多