3

After I choose some view with the decorator login_required() the user is redirected to: http://example.com/login/?next=/anuncio/adicionar/, right?

But, after I use "Login with facebook", the user are redirected to http://example.com/login/#= instead of http://example.com/anuncio/adicionar/

It happens only if I use the python-social-auth, and not happens if I use the auth native login.

My registration/login.html - Python Social Auth link

<a class="btn btn-social btn-fw btn-lg btn-facebook" href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}"><i class="fa fa-facebook"></i> Fazer login com Facebook</a>

and my Auth native login

<form action="{% url "auth:login" %}" role="form" method="POST">{% csrf_token %}
Max Ferreira
  • 468
  • 1
  • 4
  • 19

2 Answers2

1

Add login redirect url to your settins.py file

LOGIN_REDIRECT_URL = '/anuncio/adicionar/'

so when user is authenticated it will tedirect the above url

Wagh
  • 4,202
  • 5
  • 39
  • 62
  • 2
    It cannot be a non-dinamic URL. I need to redirect the user to a dynamic url. Sometimes will be "/anuncio/adicionar", sometimes "/empresa/adicionar/" – Max Ferreira Dec 29 '14 at 12:52
  • yes you can do that. create one view for this url and in that view use httpresponseredirect. so you can redirect anywhere you want. You can put dynamic url in httpresponseredirect. – Wagh Dec 29 '14 at 12:55
-2

Try adding these in your config.py (if imported to settings.py, if not - add in settings.py):

SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/anuncio/adicionar/'
SOCIAL_AUTH_LOGIN_URL = '/login'

These definitions determine the redirection url after authentication using facebook.

Reut Sharabani
  • 30,449
  • 6
  • 70
  • 88
  • 1
    I got it. But if I need to send to a dynamic url? Sometimes will be will be "/anuncio/adicionar", sometimes "/empresa/adicionar/", ... – Max Ferreira Dec 29 '14 at 12:53
  • You can pass the url for another redirection/replace on server side, using the session. Facebook is said to pass the session identifier. – Reut Sharabani Dec 29 '14 at 12:55
  • 2
    Maybe my question is why the Python Social Auth are not following the "next=" param. – Max Ferreira Dec 29 '14 at 13:12
  • When did facebook say they follow the `next` parameter? You may be able to use the oauth `callback_uri` parameter, but I never heard of `next`. That will probably make the python-social-auth redundant if you start handling everything on your own. – Reut Sharabani Dec 29 '14 at 13:22