omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

custom LOGIN_REDIRECT_URL per backend #301

Closed cambridgemike closed 10 years ago

cambridgemike commented 10 years ago

It would be great if the backend could define its own LOGIN_REDIRECT_URL.

Thanks!

omab commented 10 years ago

It's already like that, you can define SOCIAL_AUTH_FACEBOOK_LOGIN_REDIRECT_URL

cambridgemike commented 10 years ago

Oh, that's awesome. It wasn't in the documentation. Thanks a bunch!

cambridgemike commented 10 years ago

@omab Is it possible to set this redirect_url from within the pipeline?

omab commented 10 years ago

@cambridgemike, you can set the next value in the session, like this:

strategy.session.set('next', '/your/url')

But this is a workaround.

cambridgemike commented 10 years ago

Thanks, that's good enough for me!

cambridgemike commented 10 years ago

@omab will this work? The redirect_value is grabbed from the session before the pipeline finishes running

redirect_value = backend.strategy.session_get(redirect_name, '') or \
                 data.get(redirect_name, '')

is_authenticated = user_is_authenticated(user)
user = is_authenticated and user or None

partial = partial_pipeline_data(backend, user, *args, **kwargs)
if partial:
    xargs, xkwargs = partial
    user = backend.continue_pipeline(*xargs, **xkwargs)
else:
omab commented 10 years ago

Right, my suggestion to change it in the pipeline won't work at all. What are you trying to accomplish? Maybe there's another way.

cambridgemike commented 10 years ago

I want to send a user to /facebook/login?redict_after=/my/url OR /facebook/complete?redirect_after=/my/url. And have them redirected to /my/url after authenticated

cambridgemike commented 10 years ago

Do I just need to put next=/my/url I assumed next was used for internal state tracking

omab commented 10 years ago

@cambridgemike, yes, that's all you need, just add next=/my/url to the login/signup URL. Docs about that is located here http://psa.matiasaguirre.net/docs/use_cases.html?highlight=next#return-the-user-to-the-original-page.

cambridgemike commented 10 years ago

Is it possible to turn off SANITIZE_REDIRECTS for the django strategy without writing my own strategy?

omab commented 10 years ago

Set SOCIAL_AUTH_SANITIZE_REDIRECTS = False

cambridgemike commented 10 years ago

awesome aswesome, I see that's in the docs as well... sorry about that.

Thanks for everything!