默认的appengine服务帐户没有client_id。为什么或?

时间:2016-02-13 17:22:38

标签: python google-app-engine oauth service-accounts

我可以使用默认服务帐户<appengine_app_id>@appspot.gserviceaccount.com来获取access_token并发出请求。

接收appenine应用的oauth提供商收到&#39; anonymous&#39;对于get_client_id(SCOPE)。我使用此SCOPE = "https://www.googleapis.com/auth/userinfo.email"

提出请求:

access_token = app_identity.get_access_token(SCOPE)[0]    
response = urlfetch.fetch(
        "https://my-other.appspot.com/provider",
        method=urlfetch.POST,
        payload=...,
        follow_redirects=False,
        headers={"Content-Type": "application/json",
                 "Authorization": "Bearer " + access_token})

处理请求:

class ProviderHandler(webapp2.RequestHandler):

    def post(self):
        logging.info('app_id=' + self.request.headers['X-Appengine-Inbound-Appid'])
        token_audience = oauth.get_client_id(SCOPE)  # anonymous ??

创建新服务帐户时,请提供新的私钥并使用:

        credentials = ServiceAccountCredentials.from_json_keyfile_name(<json_file_name>, SCOPE)
        acees_token = credentials.get_access_token().access_token

它工作正常。

0 个答案:

没有答案