I have started using https://github.com/omab/django-social-auth and been successfully able to login via twitter, google and facebook.
Needed
I need to query about the logged in user in order to do more things, which Model I shall be using for that?
I don't see any examples for that
Thank you
Update
@Omab, I did not understand how this would work, can you please help. When I login with twitter, the callback goes to following code
@login_required
def done(request):
"""Login complete view, displays user data"""
ctx = {
'version': version,
'last_login': request.session.get('social_auth_last_login_backend')
}
logging.warn('context - ' + str(ctx))
logging.warn('request - ' + str(request))
return render_to_response('home.html', ctx, RequestContext(request))
Can you tell me how can I access to user instance here?
Thank you
The app stores the social account details using the UserSocialAuth
model, to retrieve any instance just do:
user.social_auth.filter(provider="...")
Where:
user
is a User instance (request.user
for current logged in user)provider
is a string with the provider name (facebook, twitter, etc)The UserSocialAuth
instance stores the needed tokens to call the needed API:
print user_social_auth.tokens
{...}
As suggested by K-man, you can try this (Identifying the backend provider of a logged in user):
request.user.social_auth.values_list('provider')
Other values that you can find in the values_list include: id, uid (for ex. facebook user id), user, extra_data (which contains the access_token)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With