Identifying the backend provider of a logged in user

时间秒杀一切 提交于 2019-12-25 01:17:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!