omab/django-social-auth — Issue #229: "Invalid AuthSub token" trying to access Google apis
Author: yekibud
Created: 2012-01-19 01:30:50+00:00
State: open

Is this a bug or am I doing this wrong?

Accoring to [the Google Calendar API Python developers guide]( http://code.google.com/apis/calendar/data/2.0/developers_guide_python.html#AuthAuthSub):

>Once your application has successfully acquired an OAuth access token, store that token in your database to recall for later use. There's no need to send the user back through OAuth on every run of your application. Use client.auth_token = gdata.gauth.OAuthHmacToken(consumer_key, consumer_secret, oauth_token, oauth_secret, gdata.gauth.ACCESS_TOKEN) to set an existing token on the client.

After authenticating against the google-oauth backend, I try to set my gdata calendar_client.auth_token like so:

# not sure how to get the right association for the logged in user but there is only one
assoc = Association.objects.all()[0]
calendar_client.auth_token = gdata.gauth.OAuthHmacToken(
settings.GOOGLE_CONSUMER_KEY,
settings.GOOGLE_CONSUMER_SECRET,
assoc.handle,
assoc.secret,
gdata.gauth.ACCESS_TOKEN)

But when I try to access the API...

new_event = client.InsertEvent(event)

I get:

Unauthorized - Server responded with: 401,

Token invalid - Invalid AuthSub token.

Token invalid - Invalid AuthSub token.

Error 401

After authenticating against the google-oauth backend, I try to set my gdata calendar_client.auth_token like so:

assoc = Association.objects.all()[0] # not sure how to get the right association for the logged in user but there is only one
calendar_client.auth_token = gdata.gauth.OAuthHmacToken(settings.GOOGLE_CONSUMER_KEY, settings.GOOGLE_CONSUMER_SECRET, assoc.handle, assoc.secret, gdata.gauth.ACCESS_TOKEN)
new_event = client.InsertEvent(event)