issue/744 - Uses authorization server url provided by .well-known/oauth-protected-resource metadata #748
+107
−36
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.
Fix OAuth metadata discovery to respect provided authorization server URLs (issue 744)
Summary
Fix OAuth metadata discovery to respect provided authorization server URLs before applying RFC 8414 path construction. This change modifies the discovery order to try the exact provided URL first, then fall back to RFC 8414 path-aware discovery patterns.
Motivation and Context
The current OAuth metadata discovery implementation automatically applies RFC 8414 path-aware discovery patterns to authorization server URLs without first attempting to use the exact URL provided in the metadata. This causes failures when working with authorization servers like Keycloak that provide functional OAuth metadata endpoints but don't implement the full RFC 8414 specification.
Problem: When a server provides
authorization_servers: ['http://localhost:9090/realms/mcp-rtlm']
, the SDK would immediately try path-aware URLs likehttp://localhost:9090/.well-known/oauth-authorization-server/realms/mcp-rtlm
instead of first attempting the provided URL directly.Impact: This breaks compatibility with common authorization servers that provide working endpoints but don't follow RFC 8414 path construction patterns.
How Has This Been Tested?
Test scenarios covered:
Breaking Changes
❌ No breaking changes. This is purely an internal optimization that improves compatibility. The public API remains unchanged and existing code will continue to work as expected.
Types of changes
Checklist
Additional context
Implementation Details
New Discovery Order (in
discoverOAuthMetadata
):Files Modified:
src/client/auth.ts
: Updated discovery logic indiscoverOAuthMetadata
src/client/auth.test.ts
: Updated tests to match new behaviorDesign Decisions
Related Issues
This addresses compatibility issues with authorization servers that provide working OAuth metadata endpoints at non-RFC-8414-compliant paths, particularly affecting integrations with Keycloak and similar enterprise identity providers.