Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AuthAlreadyAssociated Exception in Django Social Auth

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. Ideally it should throw an error called you are already logged in as user normaluser.

  2. 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.

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/

like image 357
ramdaz Avatar asked Oct 22 '12 19:10

ramdaz


1 Answers

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. 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.

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

like image 82
omab Avatar answered Sep 20 '22 02:09

omab