OAuth in Google App Engine


This sample demonstrates a basic structure that you can use to perform 3-legged OAuth using the Google Data Python client library in Google App Engine. This particular example talks to the Documents List Data API.

App Engine (Python) + OAuth sample

Note: The sample is available in two versions, one that signs requests with RSA-SHA1 and another that signs with HMAC-SHA1.

4 comments:

egilchri said...

Hi, I've been studying this code pretty intensely, since I'm trying to implement authorization over a mobile device.

So I plan to have them do the initial setup, using a browser, but after that, they should be able to call in and invoke services from their phone. I'll use their caller ID to get to their access token, which your code has conveniently stored in a table called TokenCollection. I do this by associating phone numbers with email ids. These email ids are my indexes into your TokenCollection table.

How is the value of "access_token" passed from MainPage->get to FetchData->post? You don't seem to pass it as a parameter.

Thanks, Ted Gilchrist

Eric (Google) said...

Hi Ted,

Thanks for the comment.

The short answer is that the token is passed as a property of the client/service object.

The Python lib stores both AuthSub (session) and OAuth (access) tokens inside a token_store or within a current_token property, depending on the setup. By default, I believe the token_store is used.

The service object recalls the token later on like this:
http://code.google.com/p/gdata-python-client/source/browse/trunk/src/gdata/service.py#418.

This process is dead simple on App Engine b/c tokens are stored for the current logged in user. All you need to do is recall the token later on:
access_token = client.token_store.find_token(SCOPE)

Hope this helps,
Eric

Rahul Garg said...

Hi
can OAuth in Google App Engine be implemented by using java.Plz help
thank you

Eric (Google) said...

Hi Rahul,

There's a GAE Java + Google Data + OAuth sample here:
http://oauthexample.appspot.com/Welcome

the source is available here:
http://code.google.com/p/googleappengine/source/browse/#svn/trunk/java/demos/oauth

Cheers,
Eric