chore: refactor OAuth client authorization api - #1009
Conversation
There was a problem hiding this comment.
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
AuthorizationRequestand consolidatesOAuthState::start_authorization/AuthorizationSession::newaround 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. |
ce0ae93 to
441644d
Compare
`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.
d378932 to
9a3c0af
Compare
There was a problem hiding this comment.
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_scopesdoc comment says "When not set" but the implementation uses an emptyVecas 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.
alexhancock
left a comment
There was a problem hiding this comment.
It looks like a much better interface to me, thanks for the cleanup
OAuthState::start_authorizationnow accepts a declarativeAuthorizationRequestdescribing 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::newis consolidated the same way, and the failure-recovery pattern from #994 (returning the manager alongside the error soOAuthStaterecovers toUnauthorizedon transient failures) is now applied across all registration paths. Includes newRecordingOAuthHttpClient-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
Checklist
Additional context