问题
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!
回答1:
In your views, try:
request.user.social_auth.values_list('provider')
to get a list of the user's connected backends.
回答2:
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'])
来源:https://stackoverflow.com/questions/11166240/identifying-the-backend-provider-of-a-logged-in-user