Skip to content

Commit b3efbb9

Browse files
author
Olivier Gintrand
committed
fix: use absolute OAuth authorize URL and allow non-admin users to authorize
Two related fixes for OAuth UX in multi-user deployments: 1. tool_service.py: Build absolute authorize URL using settings.app_domain + settings.app_root_path instead of a relative path. AI agents (VS Code Copilot, etc.) receive clickable URLs in ToolInvocationError messages. Applied in both invoke_tool and stream_invoke_tool code paths. 2. gateways_partial.html: Decouple the OAuth Authorize button from the can_modify permission check. OAuth authorization is a per-user action (each user gets their own token), so any authenticated user with gateway access should be able to authorize. Fetch/Refresh Tools remains gated behind can_modify. Fixes #3998 Signed-off-by: Olivier Gintrand <olivier.gintrand@forterro.com>
1 parent 3c9a702 commit b3efbb9

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

mcpgateway/services/tool_service.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,7 +3159,8 @@ async def prepare_rust_mcp_tool_execution(
31593159
if access_token:
31603160
headers = {"Authorization": f"Bearer {access_token}"}
31613161
else:
3162-
raise ToolInvocationError(f"Please authorize {gateway_name} first. Visit /oauth/authorize/{gateway_id_str} to complete OAuth flow.")
3162+
authorize_url = f"{str(settings.app_domain).rstrip('/')}{settings.app_root_path}/oauth/authorize/{gateway_id_str}"
3163+
raise ToolInvocationError(f"Please authorize {gateway_name} first. Visit {authorize_url} to complete OAuth flow.")
31633164
except Exception as e:
31643165
logger.error(f"Failed to obtain stored OAuth token for gateway {gateway_name}: {e}")
31653166
raise ToolInvocationError(f"OAuth token retrieval failed for gateway: {str(e)}")
@@ -4162,7 +4163,8 @@ async def invoke_tool(
41624163
headers = {"Authorization": f"Bearer {access_token}"}
41634164
else:
41644165
# User hasn't authorized this gateway yet
4165-
raise ToolInvocationError(f"Please authorize {gateway_name} first. Visit /oauth/authorize/{gateway_id_str} to complete OAuth flow.")
4166+
authorize_url = f"{str(settings.app_domain).rstrip('/')}{settings.app_root_path}/oauth/authorize/{gateway_id_str}"
4167+
raise ToolInvocationError(f"Please authorize {gateway_name} first. Visit {authorize_url} to complete OAuth flow.")
41664168
except Exception as e:
41674169
logger.error(f"Failed to obtain stored OAuth token for gateway {gateway_name}: {e}")
41684170
raise ToolInvocationError(f"OAuth token retrieval failed for gateway: {str(e)}")

mcpgateway/templates/gateways_partial.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
class="w-full flex items-center px-4 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700"
5757
>Test</button>
5858

59-
{% if gateway.authType == 'oauth' and can_modify %}
60-
<!-- OAuth Authorize -->
59+
{% if gateway.authType == 'oauth' %}
60+
<!-- OAuth Authorize (accessible to all authenticated users with gateway access) -->
6161
<a
6262
href="{{ root_path }}/oauth/authorize/{{ gateway.id }}"
6363
@click="menuOpen = false"

0 commit comments

Comments
 (0)