diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index da52926cf..29b503318 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -813,16 +813,9 @@ def load_oauth_providers(): } # Always register Letta OAuth provider (this is a Letta-focused deployment) + # Note: Letta returns non-standard token_type: "access_token" instead of "Bearer" + # This is handled manually in oauth.py _letta_token_exchange() def letta_oauth_register(oauth: OAuth): - # Letta returns token_type: "access_token" instead of "Bearer", fix it - def letta_compliance_fix(session): - def _fix_token_response(response): - data = response.json() - if data.get("token_type") == "access_token": - data["token_type"] = "Bearer" - return data - session.register_compliance_hook("access_token_response", _fix_token_response) - client = oauth.register( name="letta", client_id=LETTA_CLIENT_ID.value or "ci-let-1e9dae1e14b8412e0dec10aebce26da3", @@ -841,7 +834,6 @@ def load_oauth_providers(): ), }, redirect_uri=LETTA_REDIRECT_URI.value or "https://chatlettacom-production.up.railway.app/oauth/letta/callback", - compliance_fix=letta_compliance_fix, ) return client diff --git a/backend/open_webui/utils/oauth.py b/backend/open_webui/utils/oauth.py index 2ccc906c6..65ebd762f 100644 --- a/backend/open_webui/utils/oauth.py +++ b/backend/open_webui/utils/oauth.py @@ -1331,8 +1331,13 @@ class OAuthManager: except Exception as e: # Letta returns non-standard token_type: "access_token" instead of "Bearer" # Handle this by manually exchanging the token - if provider == "letta" and "unsupported_token_type" in str(e): - log.info("Letta OAuth: handling non-standard token_type, manually exchanging token") + error_str = str(e).lower() + if provider == "letta" and ( + "unsupported_token_type" in error_str + or "status_code" in error_str # compliance_fix error + or "400" in error_str + ): + log.info(f"Letta OAuth: handling token exchange error ({e}), manually exchanging token") try: token = await self._letta_token_exchange(request, client) except Exception as letta_e: