Added: 4 months ago
Problem
I'm trying to let my users authenticate with the social provider and then enter data in a form before user creation
Problem Description

Has the functionality to use a partial pipeline process been implemented? I'm trying to do the same thing as bennetb01 - let my users authenticate with the social provider and then enter data in a form before user creation. If someone could recommend a good way of doing this that would be awesome.
https://github.com/omab/django-social-auth/issues/90#issuecomment-3318459

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/')



You know a better solution for this problem? Login or Sign Up and Add a New Solution

You don't have permission to comment on Kambiz Saffarizadeh's solution. You may want to Login or Sign Up.

4 months ago
Kambiz Saffarizadeh:

yw ;) I'll try my best to develop a general solution

4 months ago
Daniel Shapiro:

Thank you very much for sharing this. I was hoping for a solution that involves customizing the django-social-auth pipeline, but I guess this will work as well!


About Author

Level: 8
Main Attribute: Developer
Total Solutions From: 14
Total Viewed: 3964
Total Votes Got: 1
Accept rate: 61%
Viewing Score: 3.5
Criticizing Score: 2.0
Developing Score: 467.0
Total Score: 472.5


About This Solution
Solution ID: #30
Category: Computer

Accept rate: 61% through 1 vote

Source: solutioner.net

Licenses:

Viewed: 260 Times
Added: 4 months ago