10
votes

I have Python Social Auth implemented on my site, and I'm trying to access (after the login process) into the access token that the user got. I can see on the Django admin that there's a field called extra_data containing the access token, but I don't know how to access it from my code.

Any idea?

I want to do something similar as it could be done in Django Social Auth: http://django-social-auth.readthedocs.org/en/latest/tokens.html

2

2 Answers

33
votes

Given a user instance, you can get the token by doing this:

  social = user.social_auth.get(provider='provider name')
  social.extra_data['access_token']

Assuming Facebook provider:

  social = user.social_auth.get(provider='facebook')
  social.extra_data['access_token']
2
votes

http://python-social-auth.readthedocs.org/en/latest/use_cases.html#retrieve-google-friends

user = User.objects.get(...)
social = user.social_auth.get(provider='google-oauth2')
response = requests.get(
    'https://www.googleapis.com/plus/v1/people/me/people/visible',
    params={'access_token': social.extra_data['access_token']}
)