有一种内置的设置方式 oauth在 App Engine 方面,它非常适合来 self 的本地计算机且具有 GoogleCredentials 生成的 token 的请求。 get_application_default (),但它不适用于来自 App Engine 端出现 NotAllowedError
异常的 Compute Engine 的请求。
我多次尝试将请求范围配置为包含 https://www.googleapis.com/auth/userinfo.emails
作为其必需的范围,但没有成功。
最佳答案
事实证明,当您使用允许 API 访问同一项目中的所有 Google Cloud 服务
创建实例时,它不包含所需的用户信息范围。
要包含“用户信息”范围,您必须取消选中允许 API 访问同一项目中的所有 Google Cloud 服务。
,转到访问和安全
选项卡并显式启用用户信息范围。
更新2018-11-15
现在设置电子邮件范围的正确方法是使用 gcloud 命令:
gcloud compute instances set-service-account INSTANCE-ID --zone=us-central1-f --service-account=PROJECT-ID-compute@developer.gserviceaccount.com --scopes https://www.googleapis.com/auth/userinfo.email,cloud-platform
关于python - 从 Compute Engine 与 App Engine 通信的安全方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34368039/