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?

Kai
  • 2,205
  • 3
  • 32
  • 43

2 Answers2

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
  ...
0

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

HTH

Tony
  • 625
  • 1
  • 6
  • 17