From 065f278c06a929c67cce7fde56de101a7c6fe08d Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Mon, 16 Nov 2026 17:51:37 -0300 Subject: [PATCH] Update auth-gateway TemplateResponse calls for Starlette 1.x --- containers/auth-gateway/auth_gateway/main.py | 14 ++++++++------ .../auth_gateway/web/challenge_routes.py | 11 +++++++---- .../auth-gateway/auth_gateway/web/login_routes.py | 3 +-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/containers/auth-gateway/auth_gateway/main.py b/containers/auth-gateway/auth_gateway/main.py index f5efe01..e615836 100644 --- a/containers/auth-gateway/auth_gateway/main.py +++ b/containers/auth-gateway/auth_gateway/main.py @@ -3,6 +3,12 @@ import time from contextlib import asynccontextmanager from pathlib import Path +from fastapi import FastAPI, Request +from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates +from slowapi.errors import RateLimitExceeded + from auth_gateway.config_loader import RuntimeConfigStore from auth_gateway.limiter import get_real_client_ip, limiter from auth_gateway.services.oidc_service import OIDCService @@ -12,11 +18,6 @@ from auth_gateway.storage.sqlite import SQLiteStorage from auth_gateway.web.auth_routes import router as auth_router from auth_gateway.web.challenge_routes import router as challenge_router from auth_gateway.web.login_routes import router as login_router -from fastapi import FastAPI, Request -from fastapi.responses import HTMLResponse -from fastapi.staticfiles import StaticFiles -from fastapi.templating import Jinja2Templates -from slowapi.errors import RateLimitExceeded BASE_DIR = Path(__file__).resolve().parent _access_logger = logging.getLogger("uvicorn.error") @@ -59,8 +60,9 @@ async def _rate_limit_handler(request: Request, exc: RateLimitExceeded) -> HTMLR templates = request.app.state.templates external_path = request.app.state.settings.external_path return templates.TemplateResponse( + request, "ratelimit.html", - {"request": request, "external_path": external_path, "back_url": str(request.url.path)}, + {"external_path": external_path, "back_url": str(request.url.path)}, status_code=429, ) diff --git a/containers/auth-gateway/auth_gateway/web/challenge_routes.py b/containers/auth-gateway/auth_gateway/web/challenge_routes.py index b39b194..d2c49d8 100644 --- a/containers/auth-gateway/auth_gateway/web/challenge_routes.py +++ b/containers/auth-gateway/auth_gateway/web/challenge_routes.py @@ -1,13 +1,14 @@ from urllib.parse import urlsplit +from fastapi import APIRouter, Form, Request +from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse + from auth_gateway.services.challenge_service import ( CHALLENGE_COOKIE_NAME, generate_altcha_challenge, generate_challenge_cookie, verify_altcha_solution, ) -from fastapi import APIRouter, Form, Request -from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse router = APIRouter() @@ -28,8 +29,9 @@ def _safe_next(url: str | None, external_path: str) -> str: async def challenge_page(request: Request, next: str = "/"): external_path = request.app.state.settings.external_path return request.app.state.templates.TemplateResponse( + request, "challenge.html", - {"request": request, "external_path": external_path, "next": next}, + {"external_path": external_path, "next": next}, ) @@ -47,8 +49,9 @@ async def challenge_verify(request: Request, next: str = Form("/"), altcha: str if not verify_altcha_solution(altcha, hmac_key): return request.app.state.templates.TemplateResponse( + request, "challenge.html", - {"request": request, "external_path": external_path, "next": next, "error": True}, + {"external_path": external_path, "next": next, "error": True}, status_code=400, ) diff --git a/containers/auth-gateway/auth_gateway/web/login_routes.py b/containers/auth-gateway/auth_gateway/web/login_routes.py index dc5acf5..a5906e4 100644 --- a/containers/auth-gateway/auth_gateway/web/login_routes.py +++ b/containers/auth-gateway/auth_gateway/web/login_routes.py @@ -34,11 +34,10 @@ router = APIRouter() def _render(request: Request, template_name: str, status_code: int = 200, **context): templates = request.app.state.templates base_context = { - "request": request, "external_path": request.app.state.settings.external_path, } base_context.update(context) - response = templates.TemplateResponse(template_name, base_context, status_code=status_code) + response = templates.TemplateResponse(request, template_name, base_context, status_code=status_code) csrf_token = context.get("csrf_token") if csrf_token: set_csrf_cookie(request, response, csrf_token)