Add --remote-auth-scope-param-name for non-standard OAuth scope parameters#4712
Open
gmogmzGithub wants to merge 1 commit intostacklok:mainfrom
Open
Add --remote-auth-scope-param-name for non-standard OAuth scope parameters#4712gmogmzGithub wants to merge 1 commit intostacklok:mainfrom
gmogmzGithub wants to merge 1 commit intostacklok:mainfrom
Conversation
…parameters Some OAuth providers use non-standard query parameter names for scopes in the authorization URL. For example, Slack's OAuth v2 requires user-token scopes in "user_scope" instead of the standard "scope" parameter. This causes ToolHive's OAuth flow to fail with invalid_scope errors when connecting to providers like Slack's MCP server. Add a new --remote-auth-scope-param-name flag that allows users to override the query parameter name used for scopes. When set, scopes are sent under the specified parameter name and the standard "scope" parameter is cleared. The oauth2Config.Scopes field is preserved so token refresh requests continue to work correctly. Signed-off-by: Gustavo Gomez <gmogmz@indeed.com>
1feeca8 to
141b5cf
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4712 +/- ##
==========================================
+ Coverage 68.60% 68.62% +0.02%
==========================================
Files 517 517
Lines 54631 54639 +8
==========================================
+ Hits 37480 37498 +18
+ Misses 14265 14246 -19
- Partials 2886 2895 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--remote-auth-scope-param-nameCLI flag to override the query parameter name used for scopes in the OAuth authorization URLuser_scope), scopes are sent under the custom parameter name and the standardscope=is clearedoauth2Config.Scopesis preserved so token refresh continues to work correctlyMotivation
Slack's OAuth v2 requires user-token scopes in
user_scope=instead of the standardscope=parameter. When ToolHive connects tohttps://mcp.slack.com/mcp, its OAuth discovery correctly finds thev2_user/authorizeendpoint and the 15 supported scopes, but Go'soauth2library always places scopes inscope=. Slack rejects this withinvalid_scope.This flag closes the gap so ToolHive can authenticate with providers that use non-standard scope parameter names.
Example usage for Slack MCP
Changes
pkg/auth/oauth/flow.goScopeParamNamefield onConfig;buildAuthURLoverride logicpkg/auth/oauth/manual.goscopeParamNameparameterpkg/auth/discovery/discovery.goScopeParamNameonOAuthFlowConfigpkg/auth/remote/config.goScopeParamNamefield with JSON/YAML tagspkg/auth/remote/handler.goScopeParamNameto flow configcmd/thv/app/auth_flags.go--remote-auth-scope-param-nameflagcmd/thv/app/run_flags.gocmd/thv/app/proxy.go