11

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

user3169790
  • 175
  • 1
  • 7

2 Answers2

36

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']
Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
omab
  • 3,721
  • 19
  • 23
2

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']}
)