通过Compute Engine与App Engine进行通信的安全方式

时间:2015-12-19 06:30:14

标签: python google-app-engine oauth-2.0 google-compute-engine google-cloud-platform

有一种在App Engine端设置oauth的内置方法,它适用于来自我的本地计算机的请求,其中包含由GoogleCredentials生成的令牌。get_application_default(),但它没有适用于计算引擎的请求,App Engine端有NotAllowedError例外。

我多次尝试配置请求范围以包含https://www.googleapis.com/auth/userinfo.emails作为必需范围,但没有运气。

1 个答案:

答案 0 :(得分:4)

事实证明,当您使用Allow API access to all Google Cloud services in the same project.创建实例时,包含所需的用户信息范围。

enter image description here

要包含用户信息范围,您必须取消选中Allow API access to all Google Cloud services in the same project.,转到Access & Security标签并明确启用用户信息范围。

enter image description here

更新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