【问题标题】:Authenticate Google Admin in Cloud Function在 Cloud Function 中对 Google 管理员进行身份验证
【发布时间】:2019-10-27 11:41:12
【问题描述】:

我正在尝试使用 ServiceAccountCredentials.from_json() 对 Google Admin SDK 进行身份验证。我正在使用 Google Cloud Platform 来运行 Cloud Function。 Cloud Function 从 Cloud Storage 获取文件,对其进行解密,然后使用该文件对服务进行身份验证。根据this,我可以使用from_json_keyfile_name 进行身份验证。我不会有直接路径,所以我尝试使用来自Google Console -> API -> Download credentials 的文件内容进行身份验证。该 json 具有以下键:

  • 类型
  • project_id
  • private_key_id
  • private_key
  • client_email
  • client_id
  • auth_uri
  • token_uri
  • auth_provider_x509_cert_url
  • client_x509_cert_url

但是,ServiceAccountCredentials.from_json() 会查找 _private_key_pkcs12。这不在下载的 json 中。

【问题讨论】:

  • 我无法理解问题所在以及您要完成的工作。您能否详细说明您遇到的问题是什么?
  • @Maxim 当然。基本上,我需要使用 json 为 Google Admin 创建一个服务帐户。不是 json 文件,而是实际的 json。 ServiceAccountCredentials.from_json() 可以做到这一点,但它不包括像 _private_key_pkcs12 这样的数据,这些数据在从 Google 控制台下载的 json 文件中找不到。

标签: google-cloud-platform google-cloud-functions google-cloud-storage google-authentication service-accounts


【解决方案1】:

oauth2client is deprecated。使用google.oauth2.service_account

例子

from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_info(sa_json)
return build(service_name, service_version, credentials=credentials)

【讨论】:

    猜你喜欢
    • 2011-09-18
    • 2019-01-21
    • 2013-07-10
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多