Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-social-auth : connected successfully, how to query for users now?

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

like image 672
daydreamer Avatar asked Jun 27 '12 18:06

daydreamer


2 Answers

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
{...}
like image 130
omab Avatar answered Oct 22 '22 02:10

omab


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)

like image 1
Merline Xavier Avatar answered Oct 22 '22 02:10

Merline Xavier