feat: redirect to OIDC login from Django admin

This commit is contained in:
Luca 2024-09-16 02:45:16 +02:00
parent ab96727082
commit 46c6591170
2 changed files with 14 additions and 1 deletions

View File

@ -5,4 +5,5 @@ from . import views
urlpatterns = [
path("", views.index, name="index"),
path("unauthorized", views.unauthorized, name="unauthorized"),
path("admin/login/", views.admin_login),
]

View File

@ -1,5 +1,7 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from django.http import QueryDict
from django.shortcuts import redirect, render
from django.urls import reverse
@login_required
@ -9,3 +11,13 @@ def index(request):
def unauthorized(request):
return render(request, "core/unauthorized.html", {})
def admin_login(request):
query = ""
if next := request.GET.get("next"):
q = QueryDict(mutable=True)
q["next"] = next
query = f"?{q.urlencode()}"
return redirect(f"{reverse('oidc_authentication_init')}{query}")