AuthAlreadyAssociated Exception in Django Social Auth

后端 未结 5 1268
渐次进展
渐次进展 2020-12-30 04:37

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 aga

5条回答
  •  孤独总比滥情好
    2020-12-30 05:27

    My approach to this problem was a little different, instead of tackling this in the pipeline, I made sure that a user was never passed into the pipeline in the first place. This way, even if the social_auth.user does not match the logged in user, the social_auth.user will be logged in on top of the currently logged in user.

    I think it's as easy as overriding the complete action.

    urls.py

    url(r'^complete/(?P[^/]+)/$', 'account.views.complete', name='complete'),
    

    account/views.py

    from social.actions import do_complete
    from social.apps.django_app.utils import strategy
    from social.apps.django_app.views import _do_login
    
    @csrf_exempt
    @strategy('social:complete')
    def complete(request, backend, *args, **kwargs):
        """Override this method so we can force user to be logged out."""
        return do_complete(request.social_strategy, _do_login, user=None,
                           redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs)
    

提交回复
热议问题