issue/744 - Uses authorization server url provided by .well-known/oauth-protected-resource metadata#748
issue/744 - Uses authorization server url provided by .well-known/oauth-protected-resource metadata#748katesclau wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
…th-protected-resource metadata
| const pathAwareUrl = new URL(wellKnownPath, issuer); | ||
| let response = await tryMetadataDiscovery(pathAwareUrl, protocolVersion); | ||
| // Try provided issuer URL first | ||
| let response = await tryMetadataDiscovery(issuer, protocolVersion); |
There was a problem hiding this comment.
we could also validate if the issuer URL already contains .well-known/oauth-authorization-server string 🤔
ochafik
left a comment
There was a problem hiding this comment.
Hi @katesclau , thanks for sending this out!
It's not clear to me that we should go down this route tbh.
RFC 9728 (which governs the oauth-protected-resource) defines authorization_servers as:
containing a list of OAuth authorization server issuer identifiers, as defined in RFC8414
RFC8414 states that an issuer identifier is:
a URL that uses the "https" scheme and has no query or fragment components`.
Sounds like maybe an issue to submit to Keycloak's consideration, not sure what the best way forward on their end is but I'd rather the SDK followed the RFCs.
We already have an issue opened on Keycloak with this discussion, but regardless, the authorization servers list is ignored if it contains the actual endpoint for Feel free to close the PR if you don't think this is a viable solution. |
|
going to close this as the openID compatibility work should cover this: |
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-rtlminstead 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 indiscoverOAuthMetadatasrc/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.