有一种内置的方法可以在应用程序引擎端设置oauth,对于来自我的本地计算机的请求(使用GoogleCredentials生成的令牌)非常有用。get_application_default(第页),但对于来自计算引擎的请求(应用程序引擎端有NotAllowedError异常)则不起作用。
我多次尝试将请求作用域配置为包含https://www.googleapis.com/auth/userinfo.emails作为其所需的作用域,但没有成功。

最佳答案

结果发现,当您使用Allow API access to all Google Cloud services in the same project.创建实例时,它不包括所需的用户信息范围。
python - 通过Compute Engine与App Engine通信的安全方式-LMLPHP
要包含用户信息作用域,必须取消选中Allow API access to all Google Cloud services in the same project.,转到Access & Security选项卡并显式启用用户信息作用域。
python - 通过Compute Engine与App Engine通信的安全方式-LMLPHP
更新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/

10-14 19:08
查看更多