If an already logged-in user will try to start a social auth workflow you will notice this error.
One of the approaches how to overcome this and perform login event if auth already associated is overwriting do_complete
function.
The disadvantage of this method that we will import some staff from python-social-auth
internals, so our code may be broken after the new version release.
This one tested on python-social-auth==0.3.6
and social-app-django==2.0.0
Define view:
from django.views.decorators.cache import never_cache from django.views.decorators.csrf import csrf_exempt from social_core.actions import do_complete from social_django.utils import psa from social_django.views import NAMESPACE, _do_login from django.contrib.auth import REDIRECT_FIELD_NAME ... @never_cache @csrf_exempt @psa('{0}:complete'.format(NAMESPACE)) def complete(request, backend, *args, **kwargs): """Authentication complete view""" return do_complete(request.backend, _do_login, user=None, redirect_name=REDIRECT_FIELD_NAME, request=request, *args, **kwargs)
Add to main urls.py
:
from social_django.urls import extra ... [ ... url(r'^complete/(?P<backend>[^/]+){0}$'.format(extra), complete, name='complete'), ]
Bonus
How was this done? Just find site-packages\social_django\urls.py
and see how '^complete/...
url defined. Follow complete view and copy it to your code, then just replace request.user
it to None