【问题标题】:Google Cloud: Get authorization token from Json for PostmanGoogle Cloud:从 Json 获取 Postman 的授权令牌
【发布时间】:2021-08-06 21:12:42
【问题描述】:

我正在尝试使用 Postman 触发经过身份验证的 GCP 云函数。

为此,我创建了一个具有“Cloud Functions Invoker”角色的专用服务帐户,并下载了一个 .json 密钥,其结构如下:

{
  "type": "service_account",
  "project_id": "xxx",
  "private_key_id": "xxx",
  "private_key": "-----BEGIN PRIVATE KEY-----\n1234=\n-----END PRIVATE KEY-----\n",
  "client_email": "xxx.iam.gserviceaccount.com",
  "client_id": "xxxx",
  "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_x509_cert_url": "xxx.iam.gserviceaccount.com"
}

我尝试将整个“private_key”(-----BEGIN PRIVATE KEY-----\n1234=\n-----END PRIVATE KEY-----\n)粘贴为 Bearer Token,但我收到以下错误:

<title>401 Unauthorized</title>  

现在,如何使用 GCP 中的 .json 文件通过 Postman 进行身份验证?我应该使用哪些参数?

【问题讨论】:

    标签: google-cloud-platform google-cloud-functions postman bearer-token


    【解决方案1】:

    Google Cloud Functions 需要 OAuth 身份令牌进行授权。

    Postman 无法处理 Google Cloud 服务帐号 JSON 密钥来为您生成令牌。

    您可以使用 CLI 生成令牌:

    gcloud auth print-identity-token
    

    令牌的有效期为一小时(3600 秒)。

    在 HTTP 标头 Authorization: bearer TOKEN 中包含此令牌。

    gcloud auth print-identity-token

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 2016-10-13
      • 2018-06-23
      • 2021-07-29
      • 2020-07-19
      • 2015-02-24
      • 2021-08-19
      • 1970-01-01
      • 2012-10-14
      相关资源
      最近更新 更多