Skip to content

Commit

Permalink
using context_processor for resolving correct login/logout url
Browse files Browse the repository at this point in the history
  • Loading branch information
landrej committed Nov 20, 2024
1 parent 9f5acb7 commit 92c619e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions datafundament_fb/datafundament_fb/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'shared.context_processors.authentication_urls',
],
},
},
Expand Down Expand Up @@ -180,6 +181,7 @@
# Authentication settings
AUTHENTICATION_BACKENDS = ['mozilla_django_oidc.auth.OIDCAuthenticationBackend',]
LOGIN_URL = "oidc_authentication_init"
LOGOUT_URL = "oidc_logout"
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"

Expand Down
3 changes: 2 additions & 1 deletion datafundament_fb/datafundament_fb/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

# Settings specific to this enviromnent
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']
LOGIN_URL = '/auth/login'
LOGIN_URL = 'login'
LOGOUT_URL = 'logout'
3 changes: 0 additions & 3 deletions datafundament_fb/datafundament_fb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
else:
urlpatterns = [
path('oidc/', include("mozilla_django_oidc.urls")),
# This will, purposefully, never hit, but will provide a reverse lookup for the logout/login url
path('oidc/authenticate/', OIDCAuthenticationRequestView.as_view(), name='login'),
path('oidc/logout/', OIDCLogoutView.as_view(), name='logout'),
]

urlpatterns.extend([
Expand Down
7 changes: 7 additions & 0 deletions datafundament_fb/shared/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf import settings

def authentication_urls(request):
return {
'LOGIN_URL': settings.LOGIN_URL,
'LOGOUT_URL': settings.LOGOUT_URL,
}
4 changes: 2 additions & 2 deletions datafundament_fb/templates/site-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ <h1>
<nav>
<ul>
{% if user.is_anonymous %}
<li><a href="{% url 'login' %}?next={{ request.path }}">Inloggen</a></li>
<li><a href="{% url LOGIN_URL %}?next={{ request.path }}">Inloggen</a></li>
{% endif %}
{% if user.is_authenticated %}
<li><a href="{% url 'help_docs_urls:documentation-list' %}">Help</a></li>
<li><a href="{% url 'locations_urls:location-admin' %}">Beheer</a></li>
<li>
<form id="logout-form" method="post" action="{% url 'logout' %}">
<form id="logout-form" method="post" action="{% url LOGOUT_URL %}">
{% csrf_token %}
<button type="submit">Uitloggen</button>
</form>
Expand Down

0 comments on commit 92c619e

Please sign in to comment.