From 25fccd617fa78e73bb60514fe51bc166c92fb652 Mon Sep 17 00:00:00 2001 From: Ian Roddis <31021769+iroddis@users.noreply.github.com> Date: Mon, 27 Jul 2026 15:43:24 -0300 Subject: [PATCH] Redirecting deep links after login --- app/main.py | 11 +++++- app/templates/login.html | 3 ++ app/web/pages.py | 35 ++++++++++++++--- tests/test_login_redirect.py | 73 ++++++++++++++++++++++++++++++++++++ tests/test_scope_guide.py | 3 +- 5 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 tests/test_login_redirect.py diff --git a/app/main.py b/app/main.py index 87ee1dc..e7f0ed3 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,6 @@ from contextlib import asynccontextmanager from pathlib import Path +from urllib.parse import quote from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware @@ -45,7 +46,15 @@ def create_app() -> FastAPI: @app.exception_handler(NotAuthenticated) async def _redirect_to_login(request: Request, exc: NotAuthenticated): - return RedirectResponse(url="/login", status_code=302) + # Preserve the originally requested URL so we can return there after + # login. Only meaningful for GET navigations (the ones users deep-link). + login_url = "/login" + if request.method == "GET" and request.url.path not in ("/", "/login"): + target = request.url.path + if request.url.query: + target += "?" + request.url.query + login_url = f"/login?next={quote(target, safe='')}" + return RedirectResponse(url=login_url, status_code=302) @app.get("/healthz", tags=["health"]) async def healthz(): diff --git a/app/templates/login.html b/app/templates/login.html index ee71fce..1fa24e3 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -9,6 +9,7 @@ {% if ldap_enabled %}
+ {% if ldap_error %}
{{ ldap_error }}
{% endif %}