3-legged OAuth with Provisioning API and desktop apps

49 views
Skip to first unread message

Timur Shevekhman

unread,
Sep 1, 2011, 8:03:53 PM9/1/11
to google-app...@googlegroups.com
It's been mentioned here that OAuth Playground can be used to generate an OAuth token and store it for future use with applications that run as scheduled tasks. I am straggling to make this process to work.

Here are the steps I am taking on OAuth Playground:

2. Signature method: HMAC-SHA1. Enter consumer key and secret from the cpanel.
3. Click Request token.
4. Click Authorize. Click Grant access
5. Click Access token

At this point I have the token and the token secret.

I am attempting to use them in the following Python code with gdata library:

CONSUMER_KEY = 'domain.com'
CONSUMER_SECRET = 'secret'

SIG_METHOD = gdata.auth.OAuthSignatureMethod.HMAC_SHA1

TOKEN = "token"
TOKEN_SECRET = "token secret"

client = gdata.apps.service.AppsService(source='app', domain='domain.com')
client.SetOAuthInputParameters(SIG_METHOD, CONSUMER_KEY, consumer_secret=CONSUMER_SECRET)

client.SetOAuthToken(gdata.auth.OAuthToken(key=TOKEN, secret=TOKEN_SECRET))
client.RetrieveUser("domainuser")

the last line of the code throws the following error:
'NoneType' object has no attribute 'requestor_id'

Am I missing any of the steps? Is the code I am using incorrect?

Thank you.

Gunjan Sharma

unread,
Sep 1, 2011, 11:23:02 PM9/1/11
to google-app...@googlegroups.com
Hi Timur

I think this may not be the best practice to adopt. Reason being you are using two different things. The Playground is to give you a feel of the oauth flow where as gdata libraries are for the users to use the API easily.

Now mistakes in the code snippet are:
when you call SetAuthToken it puts another token on the token_store which obviously doesn't have the Input parameters set. So this is the first mistake.
Second now if you again do a SetOauthInputParams it will put another request token whose value will not be equal to the access token.
There is a possible work around this problems:

client = gdata.apps.service.AppsService(source='app', domain='domain.com')
client.SetOAuthInputParameters(SIG_METHOD, CONSUMER_KEY, consumer_secret=CONSUMER_SECRET)
temp_token = gdata.auth.OAuthToken(key=TOKEN, secret=TOKEN_SECRET)  #make a new temp token

temp_token.oauth_input_params = client.GetOAuthInputParameters()  #make its input  
                                                                  #parameters equal to the                                                          
                                                                  #values u just set
client.SetOAuthToken(temp_token)             #now set Oauth token equal to this temp token
print client.RetrieveUser("username")

So here the new temp token will take the top of your toke_store and the things will start working.

But still the best way is to do it entirely using gdata-libraries refer the following example.

Timur Shevekhman

unread,
Sep 2, 2011, 1:19:25 PM9/2/11
to google-app...@googlegroups.com
Thank you for your response, Gunjan. Your corrections to the code solved my problem.
I was also successful in converting the sample code you linked to use the Provisioning API.

Reply all
Reply to author
Forward
0 new messages