From fd9f9a13ba06682a393791933dffec8d2dc6c183 Mon Sep 17 00:00:00 2001 From: Mabe Date: Sun, 21 Jun 2026 17:25:46 +0200 Subject: [PATCH] fix: improve error handling and logging in OIDC token exchange and redirect callback --- backend/app/main.py | 6 +++++- frontend/src/App.tsx | 13 +++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index d504d49..75af775 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -115,7 +115,11 @@ async def auth_callback(payload: AuthCallbackRequest): if response.status_code != 200: raise HTTPException(status_code=400, detail=f"OIDC token exchange failed: {response.text}") - return response.json() + result = response.json() + logger.debug("OIDC token exchange result keys: %s", list(result.keys())) + if "access_token" not in result: + logger.warning("OIDC token response missing access_token; may return only id_token or an opaque token") + return result @app.post("/chat", response_class=StreamingResponse) async def chat(request: ChatRequest, token=Depends(validate_token)): diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 0fc0488..edf7b3d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -166,12 +166,16 @@ async function handleRedirectCallback(): Promise { const result = await response.json() const token = result.access_token || result.id_token - if (response.ok && token) { - setLocalToken(token) - return token + console.debug('OIDC callback result:', result) + if (!response.ok) { + throw new Error(result.error_description || 'OIDC callback failed') + } + if (!token) { + throw new Error('OIDC callback did not return an access token') } - throw new Error(result.error_description || 'OIDC callback failed') + setLocalToken(token) + return token } function App() { @@ -207,6 +211,7 @@ function App() { ) async function login() { + clearLocalToken() try { const config = await fetchOIDCConfig() const state = generateUUID()