The gcloud auth print-identity-token
命令打印指定帐户的身份令牌。
$(gcloud auth print-identity-token \
--audiences=https://example.com \
--impersonate-service-account my-s[email protected] /cdn-cgi/l/email-protection \
--include-email)
我如何使用 Python 来做同样的事情?
这是一个代码示例(不是那么简单且有详细记录)
import google.auth.transport.requests
from google.auth.impersonated_credentials import IDTokenCredentials
SCOPES = ['https://www.googleapis.com/auth/cloud-platform']
request = google.auth.transport.requests.Request()
audience = 'my_audience'
creds, _ = google.auth.default(scopes=SCOPES)
icreds = google.auth.impersonated_credentials.Credentials(
source_credentials=creds,
target_principal="SA TO IMPERSONATE",
target_scopes=SCOPES)
id = IDTokenCredentials(icreds, target_audience=audience,include_email=True)
id.refresh(request)
print(id.token)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)