Package org.apache.juneau.rest.client.mcp.auth
package org.apache.juneau.rest.client.mcp.auth
Client-side OAuth 2.1 token acquisition for the Model Context Protocol
2026-07-28 revision.
This module supplies the token-provider implementations that plug into the McpAuthInterceptor seam of
juneau-rest-client-mcp (its Supplier<String>). It deliberately does not depend on
juneau-rest-server — the client-side flow/discovery helpers are relocated (see the flow and
oidc sub-packages) rather than reused from juneau-rest-server-auth-oauth, which compile-depends on
the server. A later auth-module de-layering is expected to rationalize this relocation.
What's here
McpTokenProvider— aSupplier<String>token manager for pre-provisioned (static) tokens, the client-credentials grant, and the refresh-token grant (SEP-2207, with rotated-refresh-token capture); all requests carry the RFC 8707resourceindicator.McpProtectedResourceMetadataClientandWwwAuthenticateChallenge— the client half of the OAuth 2.1 baseline: consume a401 WWW-Authenticate resource_metadatapointer, fetch the RFC 9728 PRM document, select an authorization server, and validate its issuer via RFC 8414 / OIDC discovery.McpAuthorizationCodeAcquirerandLoopbackRedirectReceiver— interactive authorization-code + PKCE (S256) acquisition over a loopback redirect for headless/CLI use, including the SEP-2468isscheck on the callback.
Adoption-focused documentation for this module is intentionally tracked as a separate follow-up.
- Since:
- 10.0.0
-
ClassDescriptionSingle-use, TTL-bounded store for the per-authorization
state→(codeVerifier, expectedIssuer)association created when an interactive authorization-code + PKCE flow is started and consumed when the loopback redirect arrives.A pending-authorization association awaiting the IdP loopback callback.Thread-safe, process-scoped defaultMcpClientRegistrationStorekeying registrations byissuer.toString()(SEP-2352 "separate registration state per authorization server").A minimal loopback (http://127.0.0.1) HTTP listener that captures the single authorization-code redirect an IdP sends back to a native/CLI OAuth client (SEP-837 loopback redirect handling).Builds the pair of loopback redirect URIs (SEP-837 loopback redirect handling) an MCP native/CLI client registers with an authorization server during Dynamic Client Registration.The OIDC Dynamic Client Registrationapplication_type(SEP-837) declared by an MCP client when it registers with an authorization server.Runtime exception raised by the MCP client-side auth layer when metadata discovery, PRM fetch/parse, an issuer (iss) validation check, or token acquisition fails.Interactive authorization-code + PKCE (S256) token acquisition for headless / CLI use.Builder.Immutable result of a Dynamic Client Registration (SEP-837) round-trip — the client credentials and metadata an authorization server issued, keyed by the ASissuerfor SEP-2352 credential binding.Orchestrates SEP-2352 registration-mechanism selection, issuer-keying, and re-registration on authorization-server migration, returning a usableMcpClientRegistrationfor a discovered AS.Builder.Bridges a Dynamic-Client-Registration result (McpClientRegistration) into the existing token flows — theMcpAuthorizationCodeAcquirer(interactive auth-code + PKCE) andMcpTokenProvider(client-credentials / refresh).SEP-2352 optional persistence SPI for Dynamic-Client-Registration / pre-registered credentials, keyed by the authorization server'sissueridentifier.Performs an RFC 7591 / OpenID Connect Dynamic Client Registration (SEP-837) round-trip against an authorization server'sregistration_endpoint, returning the issued credentials as a redaction-safeMcpClientRegistrationkeyed by the ASissuer(the SEP-2352 binding key).Builder.Signals that an MCP call was rejected with a SEP-2350401/403 insufficient_scopestep-up challenge.Immutable view of an RFC 9728 Protected Resource Metadata (PRM) document, as an MCP client consumes it to discover which authorization server(s) protect a given MCP server.Fetches and parses an RFC 9728 Protected Resource Metadata (PRM) document, and resolves the authorization server a protected MCP resource delegates to.Builder.Computes and tracks the SEP-2350 step-up scope union — the set of scopes a client re-authorizes with after a server emits a per-operationinsufficient_scopechallenge.Client-side SEP-2350 step-up state machine: wraps an MCP call so that, on a401/403 insufficient_scopechallenge, it computes the required-scope union (McpScopeAccumulator), drives (re-)authorization via a caller-suppliedMcpStepUpAuthorizer.Reauthorizer, and retries the original call — bounded by a hard attempt cap with per-(resource, operation)attempt tracking so a misconfigured server can't drive an unbounded re-authorization loop (spec "no more than a few times").Builder.Drives (re-)authorization with the computed scope union and installs the resulting token.A caller-supplied MCP call that throwsMcpInsufficientScopeExceptionon a step-up challenge.A headless bearer-token provider that feeds theMcpAuthInterceptortoken seam (Supplier<String>).Builder.A parsedWWW-Authenticate: Bearer ...challenge as returned by an OAuth 2.1 / MCP resource server on a401/403response (RFC 6750 §3, RFC 9728 §5.1).