Redirect url from "?next=" won't be loaded after successful authentication, even when OIDC_REDIRECT_FIELD_NAME="next" is set.
paulstrobel opened this issue · 5 comments
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?
I have the same exact problem, the next
url is not followed through after authenticating via OIDC.
Same here. How to solve this?
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.
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.
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. TheLOGIN_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