Add 2025-03-26 OAuth backward compatibility for client conformance#1374
Open
jeffhandley wants to merge 4 commits intomodelcontextprotocol:mainfrom
Open
Add 2025-03-26 OAuth backward compatibility for client conformance#1374jeffhandley wants to merge 4 commits intomodelcontextprotocol:mainfrom
jeffhandley wants to merge 4 commits intomodelcontextprotocol:mainfrom
Conversation
Implement legacy OAuth fallback so the client can authenticate against MCP servers that predate Protected Resource Metadata (RFC 9728): - When PRM discovery fails, synthesize minimal metadata using the MCP server's origin as the authorization server - When auth server metadata discovery also fails, fall back to the default endpoint paths (/authorize, /token, /register) specified by the MCP 2025-03-26 spec - Conditionally omit the 'resource' parameter from authorization and token requests when operating in legacy mode - Skip resource-match verification only for synthesized (not fetched) PRM Enable the two previously-commented-out client conformance test scenarios: auth/2025-03-26-oauth-metadata-backcompat auth/2025-03-26-oauth-endpoint-fallback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
halter73
reviewed
Feb 24, 2026
src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs
Outdated
Show resolved
Hide resolved
halter73
reviewed
Feb 24, 2026
Refactor GetAuthServerMetadataAsync to accept an allowDefaultFallback parameter and return BuildDefaultAuthServerMetadata directly instead of throwing and catching McpException at the call site. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add two tests to AuthTests.cs covering legacy server scenarios: - CanAuthenticate_WithLegacyServerWithoutProtectedResourceMetadata: Server lacks RFC 9728 PRM but serves auth server metadata at well-known URLs on the MCP server origin. - CanAuthenticate_WithLegacyServerUsingDefaultEndpointFallback: Server lacks both PRM and auth server metadata, forcing fallback to default /authorize, /token, /register endpoint paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9 tasks
halter73
reviewed
Feb 24, 2026
Comment on lines
+1084
to
+1087
| "issuer": "{{OAuthServerUrl}}", | ||
| "authorization_endpoint": "{{OAuthServerUrl}}/authorize", | ||
| "token_endpoint": "{{OAuthServerUrl}}/token", | ||
| "registration_endpoint": "{{OAuthServerUrl}}/register", |
Contributor
There was a problem hiding this comment.
I think we should be using McpServerUrl rather than OAuthServerUrl for the above to really replicate the legacy scenario. It looks like we're proxying these endpoints using CanAuthenticate_WithLegacyServerUsingDefaultEndpointFallback. I think we should do the same here, and that should be possible.
In reality, this would fail due to a resource mismatch if the OAuth server validated it (we don't because TestOAuthServer.RequireResource = false is set in this test). I think it's better to test the fallback scenario where we skip using the resource. Maybe we should only update the RequireResource` logic in test server to only pass if the resource is missing rather than invalid.
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.
Implement legacy OAuth fallback so the client can authenticate against MCP servers that predate Protected Resource Metadata (RFC 9728):
Enable the two previously-commented-out client conformance test scenarios:
auth/2025-03-26-oauth-metadata-backcompat
auth/2025-03-26-oauth-endpoint-fallback