Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
fix(auth): catch joserfc errors only, drop the authlib.jose import
Pouzore27019b78516
diff --git a/backend/app/api/routes/auth.py b/backend/app/api/routes/auth.pyindex 727d5d5..669a7fc 100644--- a/backend/app/api/routes/auth.py+++ b/backend/app/api/routes/auth.py@@ -4,7 +4,6 @@ from collections.abc import Mappingfrom typing import castfrom authlib.integrations.base_client.errors import OAuthError-from authlib.jose.errors import JoseError as _AuthlibJoseError # authlib 1.7.x still raises this; drop after 2.0from fastapi import APIRouter, Depends, HTTPException, Request, Response, statusfrom joserfc.errors import JoseErrorfrom pydantic import BaseModel@@ -88,7 +87,7 @@ async def oidc_callback(request: Request) -> Response:client = get_oidc_client()try:token = await client.authorize_access_token(request)- except (OAuthError, JoseError, _AuthlibJoseError) as exc:+ except (OAuthError, JoseError) as exc:logger.warning("OIDC callback rejected: %s", exc.error)request.session.clear()raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="OIDC authentication failed") from Nonediff --git a/backend/requirements.txt b/backend/requirements.txtindex 25187c5..fcba667 100644--- a/backend/requirements.txt+++ b/backend/requirements.txt@@ -9,7 +9,7 @@ pydantic-settings==2.5.2PyJWT==2.13.0bcrypt==4.2.1authlib==1.7.2-joserfc>=1.6.0+joserfc==1.7.4itsdangerous==2.2.0python-multipart==0.0.31apscheduler==3.10.4diff --git a/backend/tests/test_auth.py b/backend/tests/test_auth.pyindex bd0e8ad..3e45a08 100644--- a/backend/tests/test_auth.py+++ b/backend/tests/test_auth.py@@ -4,9 +4,9 @@ from urllib.parse import parse_qs, urlparseimport pytestfrom authlib.integrations.base_client.errors import OAuthError-from authlib.jose.errors import ExpiredTokenError, JoseErrorfrom fastapi import WebSocketDisconnectfrom httpx import AsyncClient+from joserfc.errors import BadSignatureError, ExpiredTokenError, JoseErrorfrom starlette.responses import RedirectResponsefrom starlette.testclient import TestClient@@ -326,7 +326,7 @@ async def test_oidc_callback_hides_protocol_error_details(client: AsyncClient, oasync def test_oidc_callback_hides_claim_validation_error_details(client: AsyncClient, oidc_settings):- fake_client = FakeOIDCClient(error=ExpiredTokenError())+ fake_client = FakeOIDCClient(error=ExpiredTokenError("exp"))with patch("app.api.routes.auth.get_oidc_client", return_value=fake_client):res = await client.get("/api/v1/auth/oidc/callback")assert res.status_code == 401@@ -334,6 +334,16 @@ async def test_oidc_callback_hides_claim_validation_error_details(client: AsyncCassert "expired" not in res.text.lower()+async def test_oidc_callback_rejects_bad_id_token_signature(client: AsyncClient, oidc_settings):+ # authlib 1.7 validates ID tokens with joserfc, whose errors are unrelated to+ # the deprecated authlib.jose ones — they must still end in a clean 401.+ fake_client = FakeOIDCClient(error=BadSignatureError())+ with patch("app.api.routes.auth.get_oidc_client", return_value=fake_client):+ res = await client.get("/api/v1/auth/oidc/callback")+ assert res.status_code == 401+ assert res.json() == {"detail": "OIDC authentication failed"}++async def test_oidc_session_token_cannot_be_used_as_bearer(client: AsyncClient, oidc_settings):from app.core.security import create_oidc_session_token