【发布时间】:2019-11-13 02:38:39
【问题描述】:
我的 Flask 应用程序在部署后进行身份验证,但显然我想在本地运行它以进行测试,但是它需要通过 google 进行身份验证。我在部署时使用以下内容进行身份验证,但是如何在本地创建 JWT 令牌?
def invoke_cloud_function(function_url, payload):
# Make sure to replace variables with appropriate values
receiving_function_url = function_url
# Set up metadata server request
metadata_server_token_url = 'http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience='
token_request_url = metadata_server_token_url + receiving_function_url
token_request_headers = {'Metadata-Flavor': 'Google'}
# Fetch the token
token_response = requests.get(token_request_url, headers=token_request_headers)
jwt = token_response.content.decode("utf-8")
# Provide the token in the request to the receiving function
receiving_function_headers = {'Authorization': f'bearer {jwt}'}
function_response = requests.get(receiving_function_url, params=payload, headers=receiving_function_headers)
return function_response.json()
它试图指向metadata_server_token_url = 'http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=,这将只在已部署的应用引擎本地。
我需要一种适合所有方式来验证云功能。我确实将环境变量设置为服务帐户密钥,但这没有帮助。
【问题讨论】:
标签: google-app-engine google-cloud-functions