我当前的设置
-
Google Cloud Engine托管在Google App Engine上 .
-
Google Echo教程(https://cloud.google.com/endpoints/docs/frameworks/python/get-started-frameworks-python)
-
Python本地服务器向echo API发出请求 .
echo教程已启动并正在运行 . 我可以在我的机器上使用python脚本调用打开 endpoints 和需要API密钥的 endpoints . 我无法使用Google ID令牌进行授权的API调用 . 到目前为止,Google的所有示例都没有奏效 .
根据我的理解,工作流程应该是
-
使用密钥文件授权服务帐户生成JWT .
-
使用JWT生成Google ID令牌 .
Google示例:https://cloud.google.com/endpoints/docs/openapi/service-account-authentication#using_a_google_id_token(密钥文件)代码失败 . 函数get_id_token()返回res ['id_token']失败,res中没有id_token .
Has anyone gotten the example to work? Does anyone have an example of making an authorized API call to an Endpoint API with a Google ID token from a service account?
1 回答
主要问题是生成JWT,下面是适用于我的代码 . 我还没有找到一种更好的方法来做到这一点 . 如果您知道更好的方法,请在下面提交您的答案或添加评论 . 从JWT生成Google ID令牌的代码完全来自Google文档(https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/endpoints/getting-started/clients/service_to_service_google_id_token/main.py)get_id_token函数 .