Get access token from Python Social Auth
Asked Answered
C

2

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

Crackpot answered 14/6, 2014 at 14:51 Comment(0)
G
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']
Giesser answered 15/6, 2014 at 16:8 Comment(1)
Answer from the creator of PSA himself :)Quijano
U
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']}
)
Undenominational answered 27/11, 2015 at 16:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.