Skip to content
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

Correctly pass redirect_uri to tokens call #222

Merged
merged 1 commit into from
Mar 28, 2025

Conversation

praboud-ant
Copy link
Contributor

@praboud-ant praboud-ant commented Mar 25, 2025

Motivation and Context

The OAuth client currently passes redirect_uri to /authorize, but doesn't pass it to /token. Per https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3, if the client passes it to /authorize, it MUST pass the same value to /token. I ran into this when trying to test Inspector (which uses the typescript SDK client) with an OAuth server which is compliant with that part of the RFC - the server correctly rejected the requests as missing the redirect_uri value.

How Has This Been Tested?

Automated tests, and locally wiring this up to inspector & verifying that the auth flow works.

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@praboud-ant praboud-ant force-pushed the praboud/redirect-uri-fix branch 2 times, most recently from 3a6d5dc to 2a2392b Compare March 25, 2025 21:29
Copy link
Member

@jspahrsummers jspahrsummers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are following the OAuth 2.1 draft spec (not OAuth 2.0) for MCP, which has this to say:

In OAuth 2.1, authorization code injection is prevented by the code_challenge and code_verifier parameters, making the inclusion of the redirect_uri parameter serve no purpose in the token request. As such, it has been removed.

I don't think we care about OAuth 2.0 compatibility here, although if folks feel strongly that this is important (e.g., because we want to be compatible with existing, OAuth 2.0-only auth libraries), we can consider it.

@csmoakpax8
Copy link

I need this as well. Just submitted an issue before seeing this. #225

Copy link
Member

@jspahrsummers jspahrsummers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, on the basis of being compatible with Auth0 (as very widely used infrastructure), let's get this in.

Thanks for the data point @csmoakpax8!

@jspahrsummers jspahrsummers linked an issue Mar 27, 2025 that may be closed by this pull request
@csmoakpax8
Copy link

@jspahrsummers Amazing thank you!

@@ -259,11 +260,13 @@ export async function exchangeAuthorization(
clientInformation,
authorizationCode,
codeVerifier,
redirectUri,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be optional? I think it's possible for the authorization request to not have ?redirect_uri=xxx defined (i.e. if the client only has a single configured redirect the server should just send them there).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and thus by oauth 2.0, it wouldn't be required

redirect_uri
REQUIRED, if the "redirect_uri" parameter was included in the
authorization request as described in Section 4.1.1, and their
values MUST be identical.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I think it's okay as is

@jerome3o-anthropic jerome3o-anthropic dismissed their stale review March 28, 2025 15:50

I think it's fine as is

@jerome3o-anthropic jerome3o-anthropic merged commit 592c91f into main Mar 28, 2025
6 checks passed
@jerome3o-anthropic jerome3o-anthropic deleted the praboud/redirect-uri-fix branch March 28, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Redirect URL to Client Auth when Exchanging Token
4 participants