Skip to content

Commit facb194

Browse files
committed
refac
1 parent c3c8c60 commit facb194

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

backend/open_webui/utils/oauth.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import aiohttp
2020
from authlib.integrations.starlette_client import OAuth
21+
from authlib.jose.errors import BadSignatureError
2122
from authlib.oidc.core import UserInfo
2223
from fastapi import (
2324
HTTPException,
@@ -1392,6 +1393,27 @@ async def handle_callback(self, request, provider, response, db=None):
13921393

13931394
try:
13941395
token = await client.authorize_access_token(request, **auth_params)
1396+
except BadSignatureError:
1397+
# The IdP likely rotated its signing keys and the cached JWKS
1398+
# is stale. Evict the cached key set so the next attempt
1399+
# fetches fresh keys from the jwks_uri.
1400+
log.warning(
1401+
'OIDC bad_signature for provider %s — evicting cached JWKS and retrying',
1402+
provider,
1403+
)
1404+
if hasattr(client, 'server_metadata') and isinstance(client.server_metadata, dict):
1405+
client.server_metadata.pop('jwks', None)
1406+
try:
1407+
token = await client.authorize_access_token(request, **auth_params)
1408+
except Exception as retry_exc:
1409+
detailed_error = _build_oauth_callback_error_message(retry_exc)
1410+
log.warning(
1411+
'OAuth callback error during authorize_access_token retry for provider %s: %s',
1412+
provider,
1413+
detailed_error,
1414+
exc_info=True,
1415+
)
1416+
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
13951417
except Exception as e:
13961418
detailed_error = _build_oauth_callback_error_message(e)
13971419
log.warning(

0 commit comments

Comments
 (0)