This commit is contained in:
Timothy Jaeryang Baek
2026-11-17 22:24:21 +09:00
Unverified
parent 0ba0a4d7e2
commit 207c7735f4
2 changed files with 38 additions and 3 deletions
+20
View File
@@ -43,6 +43,7 @@ from open_webui.utils.auth import get_admin_user, get_verified_user
from open_webui.utils.mcp.apps import app_csp, ui_resource_uri, verify_app_binding
from open_webui.utils.mcp.client import tool_visible_to
from open_webui.utils.misc import is_string_allowed
from open_webui.utils.oauth import get_system_oauth_token
from open_webui.utils.plugin import (
get_tool_contents_cache,
get_tool_module_from_cache,
@@ -116,6 +117,23 @@ async def get_tools(
)
)
# Tool servers that forward the user's SSO token fail once that SSO session is gone.
# Only flag them for browsers signed in through SSO, where signing in again fixes it.
oauth_session_expired = (
ENABLE_TOOL_SERVERS
and 'oauth_session_id' in request.cookies
and any(
connection.get('auth_type') == 'system_oauth' and (connection.get('config') or {}).get('enable')
for connection in await Config.get('tool_server.connections', [])
)
and await get_system_oauth_token(request, user) is None
)
def get_system_oauth_status(auth_type: str) -> dict:
if auth_type == 'system_oauth' and oauth_session_expired:
return {'authenticated': False, 'auth_type': 'system_oauth'}
return {}
# OpenAPI Tool Servers
server_connections = {}
for server in await get_tool_servers(request):
@@ -151,6 +169,7 @@ async def get_tools(
],
'updated_at': int(time.time()),
'created_at': int(time.time()),
**get_system_oauth_status(connection.get('auth_type')),
}
)
)
@@ -192,6 +211,7 @@ async def get_tools(
if auth_type in ('oauth_2.1', 'oauth_2.1_static')
else {}
),
**get_system_oauth_status(auth_type),
}
)
)
+18 -3
View File
@@ -1167,6 +1167,11 @@
console.log('saveSessionSelectedModels', selectedModels, sessionStorage.selectedModels);
};
// The backend only marks a tool as system_oauth when the user's SSO session is gone, so
// signing in again is the fix. These tools never block sending or redirect on their own.
const isSystemOAuthTool = (toolId: string) =>
($tools ?? []).find((tool) => tool.id === toolId)?.auth_type === 'system_oauth';
const continueOAuthRedirect = async () => {
if (tabbed) {
pendingOAuthTools = [];
@@ -1181,7 +1186,11 @@
return;
}
const nextTool = pendingOAuthTools[0];
const nextTool = pendingOAuthTools.find((tool) => !isSystemOAuthTool(tool.id));
if (!nextTool) {
sessionStorage.removeItem('oauthRedirectInProgressToolId');
return;
}
if (sessionStorage.getItem('oauthRedirectInProgressToolId') === nextTool.id) {
sessionStorage.removeItem('oauthRedirectInProgressToolId');
return;
@@ -3195,7 +3204,7 @@
const pendingToolId = sessionStorage.getItem('pendingOAuthToolId');
if (pendingToolId) {
sessionStorage.removeItem('pendingOAuthToolId');
if (!selectedToolIds.includes(pendingToolId)) {
if (!selectedToolIds.includes(pendingToolId) && !isSystemOAuthTool(pendingToolId)) {
selectedToolIds = [...selectedToolIds, pendingToolId];
}
}
@@ -4612,7 +4621,7 @@
return { status: 'rejected' };
}
if (pendingOAuthTools.length > 0) {
if (pendingOAuthTools.some((tool) => !isSystemOAuthTool(tool.id))) {
toast.warning($i18n.t('Please connect all required integrations before sending a message'));
return { status: 'rejected' };
}
@@ -5705,6 +5714,12 @@
await tick();
saveSessionSelectedModels();
await saveDraft(draft, null, false);
if (isSystemOAuthTool(tool.id)) {
sessionStorage.setItem('pendingOAuthToolId', tool.id);
localStorage.removeItem('token');
window.location.href = '/auth?state=logout&form=signin';
return;
}
initiateOAuthRedirect(tool);
};