Skip to content

Add nonce support #769

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Glitched
Copy link

Adds nonce parameter support to OAuth/OIDC authorization flows to prevent replay attacks on ID tokens.

Motivation and Context

Supporting nonces are necessary for id_token flows to prevent replay attacks.

How Has This Been Tested?

Just jest / automated tests. The changes are relatively minor, though.

Breaking Changes

The return type of startAuthorization() now includes an optional nonce field.

Hypothetically, someone could have provided explicit types on the return value like this:
const result: { authorizationUrl: URL; codeVerifier: string } = await startAuthorization(...);
Which would now be a type error, but I don't see why anyone would have an explicit type annotation there.

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

Glitched added 2 commits July 14, 2025 13:24
- Add optional nonce parameter to client startAuthorization()
- Auto-generate nonce when scope includes 'openid'
- Pass nonce through server authorization handler
- Update AuthorizationParams type to include nonce
- Add comprehensive tests for nonce handling

This enables proper OpenID Connect security by preventing replay attacks
on ID tokens.
- Add afterEach to restore all mocks
- Remove unnecessary mockClear() calls
- Ensures tests are properly isolated
@ihrpr ihrpr added this to the auth milestone Jul 15, 2025
@pcarleton pcarleton self-assigned this Jul 15, 2025
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.

3 participants