-
Notifications
You must be signed in to change notification settings - Fork 151
Fix OAuth scope parameter handling while preserving custom scopes #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This fixes the OAuth "Missing required parameter: scope" issue while maintaining backward compatibility with existing --static-oauth-client-metadata usage. Core Changes: - Add scope parameter to authorization URLs to satisfy OAuth provider requirements - Extract and store scopes from registration responses in multiple formats - Preserve custom scopes provided via staticOAuthClientMetadata.scope - Add comprehensive scope priority handling Scope Priority (fixed the original regression): 1. Custom scope from staticOAuthClientMetadata.scope (user's custom scope) 2. Extracted scopes from registration response 3. Default scopes ('openid email profile') as fallback Implementation Details: - getEffectiveScope() determines which scope to use based on priority - extractScopesFromRegistration() handles scope, default_scope, scopes[], default_scopes[] - Only extract/store scopes when no custom scope is provided - Clean up stored scopes during credential invalidation - Added 19 comprehensive tests covering all scenarios Backward Compatibility: - Existing --static-oauth-client-metadata usage works exactly as before - Users with custom scopes won't be affected by scope extraction - All existing APIs remain unchanged Fixes the regression in v0.1.20 that broke custom scopes while maintaining the OAuth scope parameter fix for providers like Google. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
commit: |
@geelen, any chance you could take a look? I'm keen to use Google oauth via mcp-remote ASAP. |
const effectiveScope = this.getEffectiveScope() | ||
authorizationUrl.searchParams.set('scope', effectiveScope) | ||
debugLog('Added scope parameter to authorization URL', { scopes: effectiveScope }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! I'm running into this issue myself and really appreciate this PR. Unfortunately when using your branch, I'm still not seeing the correct scopes attached. This piece of code successfully attaches the scope for me, but I'm not sure how to integrate it into your getEffectiveScope
method.
const effectiveScope = this.getEffectiveScope() | |
authorizationUrl.searchParams.set('scope', effectiveScope) | |
debugLog('Added scope parameter to authorization URL', { scopes: effectiveScope }) | |
const effectiveScope = this.getEffectiveScope() | |
authorizationUrl.searchParams.set('scope', effectiveScope) | |
debugLog('Added scope parameter to authorization URL', { scopes: effectiveScope }) | |
// The correct custom scopes are found in the authorization URL resource + using the discoverOAuthProtectedResourceMetadata | |
const resourceURL = authorizationUrl.searchParams.get('resource') | |
if (resourceURL) { | |
const metadata = await discoverOAuthProtectedResourceMetadata(resourceURL) | |
if (metadata.scopes_supported !== undefined) { | |
authorizationUrl.searchParams.set('scope', metadata.scopes_supported.join(' ')) | |
} | |
} |
Any guidance on how to integrate this into the PR would be very much appreciated! Hoping to get this fixed to address this reported issue.
Thanks for the feedback and the code suggestion! I really appreciate you testing this branch and providing a concrete solution. Your approach using However, I think this enhancement would be better suited for a separate PR since:
Would you be interested in creating a follow-up PR with your Thanks again for the detailed analysis and code - it's exactly what's needed to properly implement RFC 9728 support! |
Problem
PR #145 fixed the "Missing required parameter: scope" error with OAuth providers like Google, but it introduced a regression that broke existing users who relied on
--static-oauth-client-metadata '{"scope": "custom scopes"}'
for custom scope configuration.Root Cause: The original implementation always forced scopes to be hardcoded defaults (
'openid email profile'
), overriding any custom scope provided instaticOAuthClientMetadata
.Solution
This PR fixes the regression while preserving the original OAuth scope parameter fix. It implements a proper scope priority system:
Scope Priority (Backward Compatible)
staticOAuthClientMetadata.scope
(user's custom scope) - HIGHEST PRIORITY'openid email profile'
) as fallback onlyCore Changes
staticOAuthClientMetadata.scope
always takes precedenceImplementation Details
getEffectiveScope()
: Determines which scope to use based on priorityextractScopesFromRegistration()
: Handles different scope formats from OAuth providersstaticOAuthClientMetadata.scope
scopes.json
and loaded on startupTesting
Added 19 comprehensive test cases covering:
staticOAuthClientMetadata.scope
always takes priorityCompatibility
✅ Backward Compatible
--static-oauth-client-metadata '{"scope": "custom scopes"}'
works exactly as before✅ Fixes Original Issue
Testing Done
utils.test.ts
(upstream compatibility) ✅Example Usage
Before (broken in v0.1.20):
After (fixed in this PR):
This fix ensures both existing users with custom scopes and new users with providers like Google have a seamless OAuth experience.