【问题标题】:Why doesn't the credentials.json I download from Google Cloud Platform include a refresh_token?为什么我从 Google Cloud Platform 下载的 credentials.json 不包含 refresh_token?
【发布时间】:2022-01-20 16:53:54
【问题描述】:

我为我的应用设置了OAuth consent screen,用户类型为 external,我自己是测试用户。然后,我为 Web 应用程序设置了 OAuth 2.0 客户端 ID。当我从 here 下载生成的 JSON 时,它包含以下对象,但没有 refresh_token。这是为什么呢?

{
  "web": {
    "client_id": "...",
    "project_id": "...",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "...",
    "redirect_uris": [
      "http://localhost/"
    ]
  }
}

我在文档中找不到它:

【问题讨论】:

标签: google-cloud-platform


【解决方案1】:

客户端机密文件标识 OAuth 身份提供者。刷新令牌是在身份验证期间根据用户身份生成的(OAuth 流程)。将其视为两种类型的秘密:提供者和用户。

【讨论】:

    【解决方案2】:

    最初的问题——“为什么我从 Google Cloud Platform 下载的 credentials.json 不包含 refresh_token?”——在 a comment in the question Jake Nelson linked 中得到了回答:

    刷新令牌与经过身份验证的身份相关联,而不是客户端机密凭据的一部分。

    我没有refresh_token 的根本问题是这样解决的:

    • 我在同意屏幕中的用户类型曾经是内部的,但我按照文档将其更改为外部
    • 更改后,我不得不通过将 prompt='consent' 添加到我的 flow.run_local_server 调用 (source) 来强制 API 再次征求我的同意

    【讨论】:

      猜你喜欢
      • 2017-01-24
      • 2023-03-23
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 2020-10-20
      • 2019-03-01
      • 2018-07-21
      • 2020-10-18
      相关资源
      最近更新 更多