Added: 4 months ago
This Solution was
useful for me
Solution
in settings.py
SOCIAL_AUTH_CREATE_USERS = False
then you should override or change "complete" function in social_auth/views.py and turn it into your required one.
you can use:
kwargs.get('details') kwargs.get('uid')to get what you want and save them in SESSION (or ...) for next page.
another way: get 'details' and 'uid' in 'complete' and erase the whole procedure from social_auth/backends/__init__.py Authentication method.
then social_auth/views.py would look like this:
from django.shortcuts import render_to_response
from social_auth.backends.pipeline.social import social_auth_user
from social_auth.backends.pipeline.associate import associate_by_email
from social_auth.backends.pipeline.user import get_username
from social_auth.backends.pipeline.user import create_user
from social_auth.backends.pipeline.social import associate_user
from social_auth.backends.pipeline.social import load_extra_data
from social_auth.backends.pipeline.user import update_user_details
from social_auth import backends
@csrf_exempt
@dsa_view()
def complete(request, backend, user=None, *args, **kwargs):
"""Authentication complete process"""
if request.user and not request.user.is_authenticated():
user = None
elif request.user and request.user.is_authenticated():
user = request.user
kwargs.update({'user': user, 'request': request})
kwargs = backend.auth_complete(*args, **kwargs)
auth_backend = backend.AUTH_BACKEND()
response = kwargs.get('response')
details = auth_backend.get_user_details(response)
uid = auth_backend.get_user_id(details, response)
backend = auth_backend
kwargs.update({
'backend': backend,
'request': request,
'uid': uid,
'social_user': None,
'response': response,
'details': details,
'is_new': False,
})
kwargs.update( {'backend_name': backend.name} )
kwargs.update( social_auth_user(*args, **kwargs) or {})
kwargs.update( associate_by_email(*args, **kwargs) or {})
kwargs.update( get_username(*args, **kwargs) or {})
if user and user.is_authenticated():
kwargs.update( associate_user(*args, **kwargs) or {})
#kwargs.update( load_extra_data(*args, **kwargs) or {})
#kwargs.update( update_user_details(*args, **kwargs) or {})
request.session['kwargs'] = {'details': details, 'username': kwargs.get('username'), 'backend_name': backend.name, 'uid': uid}
user = kwargs.get('user') if not user else user
social_user = kwargs.get('social_user')
if social_user:
user = social_user.user
user.social_user = social_user
user.is_new = kwargs.get('is_new')
redirect_value = request.session.pop(REDIRECT_FIELD_NAME, '')
if user and getattr(user, 'is_active', True):
user.backend = 'django.contrib.auth.backends.ModelBackend' #kwargs.get('backend')
login(request, user)
# user.social_user is the used UserSocialAuth instance defined
# in authenticate process
social_user = user.social_user
if SESSION_EXPIRATION :
# Set session expiration date if present and not disabled by
# setting. Use last social-auth instance for current provider,
# users can associate several accounts with a same provider.
if social_user.expiration_delta():
request.session.set_expiry(social_user.expiration_delta())
# store last login backend name in session
request.session[SOCIAL_AUTH_LAST_LOGIN] = social_user.provider
# Remove possible redirect URL from session, if this is a new account,
# send him to the new-users-page if defined.
url = NEW_USER_REDIRECT if NEW_USER_REDIRECT and getattr(user, 'is_new', False) else redirect_value or DEFAULT_REDIRECT
return HttpResponseRedirect('/')
else:
return HttpResponseRedirect('/social_register/')