Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect url from "?next=" won't be loaded after successful authentication, even when OIDC_REDIRECT_FIELD_NAME="next" is set. #485

Open
paulstrobel opened this issue Feb 8, 2023 · 5 comments

Comments

@paulstrobel
Copy link

paulstrobel commented Feb 8, 2023

In my application both the standard django authentication ( django.contrib.auth.backends.ModelBackend ) and the mozilla django oidc backend ( mozilla_django_oidc.auth.OIDCAuthenticationBackend ) can be used to authenticate users. The LOGIN_REDIRECT_URL is not explicitly set.

  • When using the default login from django, the ?next=/somepage/ parameter from the url is catched and after login the correct redirect url is loaded.
  • When using the OIDC login from mozilla-django-oidc, the next parameter is not caught. Even when explicitly setting the parameter OIDC_REDIRECT_FIELD_NAME="next" which it should be by default, the next argument is somehow lost during the authentication process. After successful authentication, the application always forwards to the default url: /accounts/profile .

Is this an issue of mozilla-django-oidc or is it required that the OIDC server somehow passes the next parameter along and maybe is not doing that?

@nicolazilio
Copy link

I have the same exact problem, the next url is not followed through after authenticating via OIDC.

@soft-top-notch
Copy link

Same here. How to solve this?

@nicolazilio
Copy link

nicolazilio commented Jun 4, 2023

I solved this issue, in my usecase. For me, the problem was that I set up logging in as an 'a' element, as described here, when it should have been set up as a get form that includes a next parameter

<form method="get" action="{% url 'oidc_authentication_init' %}">
     <input type="hidden" name="next" value="{{ next }}" />
     <input type="submit" value="Submit">
</form>

or see my template.

@gedyeyasu
Copy link

gedyeyasu commented Jul 20, 2023

You can solve this issue by creating a custom login redirect view that gets the next query param and appends it to oidc_authentication_init url before doing the redirect. That way after successful authentication you will get redirected to the next url.

in urls.py
path('auth/login/', custom_login)

in views.py

custom_login(request):
    # get next query param and append it to oidc login
    next = request.GET.get("next")
    url = reverse('oidc_authentication_init')
    if next:
        url = f"{url}?next={next}"

    return redirect(url)

This way instead of calling the url 'oidc_authentication_init' in the template or anywhere else you just call the custom login url.

@jpedroreigota
Copy link

In my application both the standard django authentication ( django.contrib.auth.backends.ModelBackend ) and the mozilla django oidc backend ( mozilla_django_oidc.auth.OIDCAuthenticationBackend ) can be used to authenticate users. The LOGIN_REDIRECT_URL is not explicitly set.

  • When using the default login from django, the ?next=/somepage/ parameter from the url is catched and after login the correct redirect url is loaded.
  • When using the OIDC login from mozilla-django-oidc, the next parameter is not caught. Even when explicitly setting the parameter OIDC_REDIRECT_FIELD_NAME="next" which it should be by default, the next argument is somehow lost during the authentication process. After successful authentication, the application always forwards to the default url: /accounts/profile .

Is this an issue of mozilla-django-oidc or is it required that the OIDC server somehow passes the next parameter along and maybe is not doing that?

Hey man, did you make it? I'm with the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants