Skip to content

chore: refactor OAuth client authorization api - #1009

Merged
jamadeo merged 3 commits into
mainfrom
jamadeo/enhance-auth-api
Jul 23, 2026
Merged

chore: refactor OAuth client authorization api#1009
jamadeo merged 3 commits into
mainfrom
jamadeo/enhance-auth-api

Conversation

@jamadeo

@jamadeo jamadeo commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

OAuthState::start_authorization now accepts a declarative AuthorizationRequest describing the client's available identity material and selects the highest-priority mechanism the server supports: pre-registered client information → Client ID Metadata Documents (SEP-991) → Dynamic Client Registration.

This replaces the three specific entry points (start_authorization, start_authorization_with_metadata_url, start_authorization_with_preregistered_client), where callers previously had to know which mechanism to pick. AuthorizationSession::new is consolidated the same way, and the failure-recovery pattern from #994 (returning the manager alongside the error so OAuthState recovers to Unauthorized on transient failures) is now applied across all registration paths. Includes new RecordingOAuthHttpClient-based tests covering the priority matrix and recovery semantics, plus updated docs, examples, and conformance client.

closes #1006

Motivation and Context

Improving the authorization API for v3.

How Has This Been Tested?

Breaking Changes

Yes, the auth client code will need some changes.

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

@github-actions github-actions Bot added T-documentation Documentation improvements T-core Core library changes T-examples Example code changes T-transport Transport layer changes labels Jul 18, 2026
@jamadeo
jamadeo requested a review from Copilot July 23, 2026 10:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the OAuth client authorization surface to a single declarative entry point by introducing AuthorizationRequest, allowing the SDK to select the highest-priority client registration mechanism supported by the server (pre-registered client → CIMD/SEP-991 → dynamic registration). It updates examples, conformance client code, and documentation to match the consolidated API, and extends tests to cover mechanism priority and state recovery semantics.

Changes:

  • Introduces AuthorizationRequest and consolidates OAuthState::start_authorization / AuthorizationSession::new around it.
  • Removes the older specialized authorization entry points and updates downstream callers (examples + conformance client).
  • Expands documentation and tests to cover the mechanism priority matrix and error recovery behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
examples/clients/src/auth/oauth_client.rs Updates the example client to use AuthorizationRequest with the unified start_authorization API.
docs/OAUTH_SUPPORT.md Updates OAuth support documentation and examples to describe the new priority-based registration selection and new API usage.
crates/rmcp/src/transport/auth.rs Adds AuthorizationRequest, consolidates session/authorization creation, updates error recovery behavior, and adds/updates tests.
crates/rmcp/src/transport.rs Re-exports AuthorizationRequest from the transport module API surface.
conformance/src/bin/client.rs Migrates the conformance client flows to the unified AuthorizationRequest-based API.

Comment thread crates/rmcp/src/transport/auth.rs Outdated
Comment thread crates/rmcp/src/transport/auth.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread crates/rmcp/src/transport/auth.rs
`OAuthState::start_authorization` now accepts a declarative `AuthorizationRequest`
describing the client's available identity material and selects the highest-priority
mechanism the server supports: pre-registered client information → Client ID
Metadata Documents (SEP-991) → Dynamic Client Registration.

This replaces the three mechanism-specific entry points (`start_authorization`,
`start_authorization_with_metadata_url`, `start_authorization_with_preregistered_client`),
where callers previously had to know which mechanism to pick. `AuthorizationSession::new`
is consolidated the same way, and the failure-recovery pattern from #994 (returning the
manager alongside the error so `OAuthState` recovers to `Unauthorized` on transient failures)
is now applied across all registration paths. Includes new `RecordingOAuthHttpClient`-based
tests covering the priority matrix and recovery semantics, plus updated docs, examples, and
conformance client.
@jamadeo
jamadeo force-pushed the jamadeo/enhance-auth-api branch from d378932 to 9a3c0af Compare July 23, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

crates/rmcp/src/transport/auth.rs:720

  • The with_scopes doc comment says "When not set" but the implementation uses an empty Vec as the sentinel for auto-selection (and callers can also explicitly pass an empty iterator). This wording is misleading; consider documenting the behavior in terms of an empty scopes list.
    /// Set the scopes to request. When not set, the SDK auto-selects scopes
    /// using its normal scope-selection policy.

Comment thread crates/rmcp/src/transport/auth.rs
@jamadeo
jamadeo marked this pull request as ready for review July 23, 2026 17:57
@jamadeo
jamadeo requested a review from a team as a code owner July 23, 2026 17:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@alexhancock alexhancock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like a much better interface to me, thanks for the cleanup

@jamadeo
jamadeo merged commit e903341 into main Jul 23, 2026
22 checks passed
@jamadeo
jamadeo deleted the jamadeo/enhance-auth-api branch July 23, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-documentation Documentation improvements T-examples Example code changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate OAuth client authorization entry points behind a unified API

3 participants