Using the OAuth Access Token from django-social-auth with Google data api (calendar)
Asked Answered
K

2

6

I'm trying to use the OAuth Token I get from django-social-auth to access the users calendars.

So in the django-social-auth configuration I set:

GOOGLE_CONSUMER_KEY = 'anonymous'
GOOGLE_CONSUMER_SECRET = 'anonymous'
GOOGLE_OAUTH_EXTRA_SCOPE = ['https://www.google.com/calendar/feeds/']

When the user comes back from google, I get an entry in the database which lookes like this:

{u'access_token': u'oauth_token_secret=vvvv&oauth_token=xxxx'}

But now, when I try do something like this:

import gdata.calendar.client

client = gdata.calendar.client.CalendarClient()
client.auth_token = gdata.gauth.OAuthHmacToken('anonymous', 'anonymous', 'xxxx', 'vvvv', gdata.gauth.ACCESS_TOKEN)

client.GetOwnCalendarsFeed()

I always get:

gdata.client.Unauthorized: Unauthorized - Server responded with: 401
<HEAD>
<TITLE>Token invalid - Invalid AuthSub token.</TITLE>
</HEAD>

What am I missing here?

Kranz answered 21/9, 2011 at 8:19 Comment(2)
Are you using OAuth or OAuth2?Decern
I have the exact same problem. Driving me nuts. I'm using OAuth and have tried with anonymous as well as registered keys.Lacasse
C
3

This works for me:

from social_auth.models import UserSocialAuth

def do_something_with_tokens(request):
  tokens = UserSocialAuth.get_social_auth_for_user(request.user).get().tokens
  ...
Consul answered 6/10, 2012 at 18:35 Comment(0)
L
0

Hallelujah! Django-social-auth returns the access token with an escaped forward slash (%2F). Replacing that with "/" worked for me.

HTH

Lacasse answered 20/1, 2012 at 3:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.