Skip to content

Commit 08d8e37

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 a2aa82a commit 08d8e37

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
@@ -3344,7 +3344,8 @@ async def prepare_rust_mcp_tool_execution(
33443344
if access_token:
33453345
headers = {"Authorization": f"Bearer {access_token}"}
33463346
else:
3347-
raise ToolInvocationError(f"Please authorize {gateway_name} first. Visit /oauth/authorize/{gateway_id_str} to complete OAuth flow.")
3347+
authorize_url = f"{str(settings.app_domain).rstrip('/')}{settings.app_root_path}/oauth/authorize/{gateway_id_str}"
3348+
raise ToolInvocationError(f"Please authorize {gateway_name} first. Visit {authorize_url} to complete OAuth flow.")
33483349
except Exception as e:
33493350
logger.error(f"Failed to obtain stored OAuth token for gateway {gateway_name}: {e}")
33503351
raise ToolInvocationError(f"OAuth token retrieval failed for gateway: {str(e)}")
@@ -4377,7 +4378,8 @@ async def invoke_tool(
43774378
headers = {"Authorization": f"Bearer {access_token}"}
43784379
else:
43794380
# User hasn't authorized this gateway yet
4380-
raise ToolInvocationError(f"Please authorize {gateway_name} first. Visit /oauth/authorize/{gateway_id_str} to complete OAuth flow.")
4381+
authorize_url = f"{str(settings.app_domain).rstrip('/')}{settings.app_root_path}/oauth/authorize/{gateway_id_str}"
4382+
raise ToolInvocationError(f"Please authorize {gateway_name} first. Visit {authorize_url} to complete OAuth flow.")
43814383
except Exception as e:
43824384
logger.error(f"Failed to obtain stored OAuth token for gateway {gateway_name}: {e}")
43834385
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
@@ -68,8 +68,8 @@
6868
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"
6969
>Test</button>
7070

71-
{% if gateway.authType == 'oauth' and can_modify %}
72-
<!-- OAuth Authorize -->
71+
{% if gateway.authType == 'oauth' %}
72+
<!-- OAuth Authorize (accessible to all authenticated users with gateway access) -->
7373
<a
7474
href="{{ root_path }}/oauth/authorize/{{ gateway.id }}"
7575
@click="menuOpen = false"

0 commit comments

Comments
 (0)