Using AppAssertionCredentials

65 views
Skip to first unread message

rba...@hugeinc.com

unread,
Oct 28, 2016, 5:29:13 PM10/28/16
to Google API Python Client
The docs seem relatively straight forward but this isn't working (oauth2client-4.0.0):

1) went to console and downloaded p12 file for appengine default service account XXX
2) generated PEM: cat xxx.p12 | openssl pkcs12 -nodes -nocerts -passin pass:notasecret | openssl rsa > key.pem
3) updated dev_appserver: --appidentity_email_address=X...@appspot.gserviceaccount.com --appidentity_private_key_path=key.pem
4) python:

import httplib2
from oauth2client.contrib.appengine import AppAssertionCredentials
from google.appengine.api import memcache
credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/userinfo.email')
http = credentials.authorize(httplib2.Http(memcache))
response = http.request(
    uri=url,
    method='POST',
    body={'email': email}
)

5) response: 302


6) Receiving Handler:

class TestHandler(webapp2.RequestHandler):
    def post(self):
        userEmail = self.request.POST.get('email')
        from google.appengine.api import users
        user = users.get_current_user()
        msg = 'account: {ae} - user: {ue}'.format(ue=userEmail, ae=user.email())
        self.response.write(msg)

I've done traces. It seems to be fetching the token, adding the header, etc. But all the requests get a 302 no matter what I do to them...
Reply all
Reply to author
Forward
0 new messages