0

With django-social-auth, is there a good way to find out the backend provider of a logged in user? Is finding the corresponding UserSocialAuth object supposedly the best way?

Thanks!

Kar
  • 6,063
  • 7
  • 53
  • 82

2 Answers2

3

The last login provider is stored in the session using the key social_auth_last_login_backend by default, otherwise yes, checking the UserSocialAuth instances is the preferred way by doing user.social_auth.filter().

Both methods can be combined by doing:

user.social_auth.filter(provider=request.session['social_auth_last_login_backend'])
omab
  • 3,721
  • 19
  • 23
2

In your views, try:

request.user.social_auth.values_list('provider')

to get a list of the user's connected backends.

K-man
  • 353
  • 1
  • 13