AuthAlreadyAssociated异常在Django社会认证 [英] AuthAlreadyAssociated Exception in Django Social Auth

查看:191
本文介绍了AuthAlreadyAssociated异常在Django社会认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用说Facebook(或者说fbuser)或Google(googleuser))创建用户之后。如果我通过正常的django管理员(普通用户)创建另一个用户,并在第三个用户(normaluser)登录时尝试使用Facebook或Google再次登录,则会引发一个错误异常AuthAlreadyAssociated。

After I create a user using say Facebook(let's say fbuser) or Google(googleuser). If I create another user through the normal django admin(normaluser), and try logging again using Facebook or Google while third user(normaluser) is logged in, it throws an error exception AuthAlreadyAssociated.


  1. 理想情况下,应该会出现一个错误,您已经以
    user normaluser身份登录。

  1. Ideally it should throw an error called you are already logged in as user normaluser.

或者它应该注销正常的用户,并尝试与已经与FB或Google相关联的
帐户关联,例如
可能是。

Or it should log out normal user, and try associating with the account which is already associated with FB or Google, as the case may be.

如何实现上述两个功能之一?所有的建议欢迎。

How do I implement one of these two above features? All advice welcome.

此外,当我尝试自定义SOCIAL_AUTH_PIPELINE,不可能使用FB或Google登录,并强制登录URL / accounts / login / p>

Also when I try customizing SOCIAL_AUTH_PIPELINE, it is not possible to login with FB or Google, and it forces the login URL /accounts/login/

推荐答案

DSA目前不会注销帐户(或冲突会话)。 AuthAlreadyAssociated 突出显示当前用户未与尝试使用的当前社交帐户相关联的场景。有一些解决方案可能会套用您的项目:

DSA doesn't logout accounts (or flush sessions) at the moment. AuthAlreadyAssociated highlights the scenario where the current user is not associated to the current social account trying to be used. There are a couple solutions that might suite your project:


  1. 定义一个 social_auth的子类。 middleware.SocialAuthExceptionMiddleware 并覆盖默认行为( process_exception()),以您喜欢的方式重定向或设置您喜欢的警告。

  1. Define a sub-class of social_auth.middleware.SocialAuthExceptionMiddleware and override the default behavior (process_exception()) to redirect or setup the warning you like in the way you prefer.

添加注销当前用户的管道方法(替换 social_auth.backend.pipeline.social.social_auth_user )提起例外。

Add a pipeline method (replacing social_auth.backend.pipeline.social.social_auth_user) that logouts the current user instead of raising an exception.

这篇关于AuthAlreadyAssociated异常在Django社会认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆