python-social-auth partial pipeline can not resume

486 views
Skip to first unread message

Yonggan Wu

unread,
Jan 10, 2014, 5:45:02 PM1/10/14
to django...@googlegroups.com
http://stackoverflow.com/questions/21032255/python-social-auth-partial-pipeline-can-not-resume

I am trying to collect the password for the new user with partial pipeline of python-social-auth. For some unknown reason, I am not able to resume the pipeline, the page render back to the password collection page after I submit the form.

What's wired is that even I typed the http.../complete/backend-name, the page will redirect back to the password collection page. It looks like the rendering goes into an endless loop, the password collection page first point to the complete page, the complete page direct back to the password collection page. I checked the value for REDIRECT_FIELD_NAME, it is "next".

I am not sure what's wrong with my code, any tips/suggestions are greatly appreciated.

settings.py

SOCIAL_AUTH_PIPELINE = (
    ...
    'accounts.pipeline.get_password',
    ...
)

pipeline.py

from django.shortcuts import redirect
from social.pipeline.partial import partial

@partial
def get_password(strategy, details, user=None, is_new=False, *args, **kwargs):
    if is_new:
        return redirect('accounts_signup_social')
    else:
        return

views.py

def get_password(request):
    if request.method == 'POST':
        request.session['password'] = request.POST.get('password')
        backend = request.session['partial_pipeline']['backend']
        return redirect('social:complete', backend=backend)
    return render_to_response('accounts/social_signup.html',{"form":SocialSignUpForm}, RequestContext(request))

Yonggan Wu

unread,
Jan 10, 2014, 6:23:57 PM1/10/14
to django...@googlegroups.com
Hi Waris,

Thank you for your replay. I just tried, it does not work.

I downloaded the original source example code from https://github.com/omab/python-social-auth/tree/master/examples/django_example

and modified the pipeline to the following to force the collection of email address. Same problem appeared.

def require_email(strategy, details, user=None, is_new=False, *args, **kwargs):
    #if user and user.email:
    #    return
    #elif is_new and not details.get('email'):
    #    if strategy.session_get('saved_email'):
    #        details['email'] = strategy.session_pop('saved_email')
    #    else:
    #        return redirect('require_email')
    return redirect('require_email')

and the setting to:
SOCIAL_AUTH_PIPELINE = (
   ...
    'social.pipeline.partial.save_status_to_session',
    'example.app.pipeline.require_email',
    ...
)

Yonggan Wu

unread,
Jan 10, 2014, 7:31:50 PM1/10/14
to django...@googlegroups.com

Ok. I found the problem and the solution.

As the documentation said, "The pipeline will resume in the same function that cut the process." athttp://python-social-auth.readthedocs.org/en/latest/pipeline.html. Which means it will always render back to the same function.

The solution is to add the session check for the password in the pipeline. Return back to the next pipeline if the password is archived:

pipeline:

from django.shortcuts import redirect
from social.pipeline.partial import partial

@partial
def get_password(strategy, details, user=None, is_new=False, *args, **kwargs):
    if is_new:

        if 'password' in kwargs['request'].session:
            return {'password': kwargs['request'].session['psssword']}
        else:
Reply all
Reply to author
Forward
0 new messages