Class McpProtectedResourceMetadataClient
This is the client half of the OAuth 2.1 baseline PRM discovery required by the MCP 2026-07-28 revision: on a
401 WWW-Authenticate challenge the client recovers the resource_metadata pointer
(WwwAuthenticateChallenge.resourceMetadata()), fetches the PRM document here, selects an authorization server
(McpProtectedResourceMetadata.firstAuthorizationServer()), and validates that server's issuer identity via
OidcDiscoveryClient (RFC 8414 / OIDC Discovery).
When an expected resource identifier is supplied (McpProtectedResourceMetadataClient.Builder.expectedResource(URI) or the expectedResource
argument of fetch(URI, URI) / parse(String, URI, URI)), the PRM document's resource field is
validated against it per RFC 9728 §3.3 (exact string match, mirroring the issuer-identity posture) and a mismatch
is rejected — this defends against a malicious server pointing the client at a PRM document minted for a
different resource. When no expected resource is supplied the identity check is skipped.
By default the PRM URL and any discovered authorization-server URI must use https (loopback hosts are always
permitted for local/testing use); McpProtectedResourceMetadataClient.Builder.allowInsecureHttp(boolean) disables the scheme check entirely.
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor. -
Method Summary
Modifier and TypeMethodDescriptioncreate()Static creator.Selects the first authorization server from the PRM document and validates its issuer identity via RFC 8414 / OIDC discovery.Fetches and parses the PRM document at the supplied URL, validating itsresourcefield against the builder-configuredMcpProtectedResourceMetadataClient.Builder.expectedResource(URI)(if any).Fetches and parses the PRM document at the supplied URL, validating itsresourcefield against the supplied expected resource identifier (RFC 9728 §3.3).Parses a PRM JSON document body, validating itsresourcefield against the builder-configuredMcpProtectedResourceMetadataClient.Builder.expectedResource(URI)(if any).Parses a PRM JSON document body, validating itsresourcefield against the supplied expected resource identifier (RFC 9728 §3.3).
-
Constructor Details
-
McpProtectedResourceMetadataClient
Constructor.- Parameters:
b- The builder.
-
-
Method Details
-
create
Static creator.- Returns:
- A new builder.
-
fetch
Fetches and parses the PRM document at the supplied URL, validating itsresourcefield against the builder-configuredMcpProtectedResourceMetadataClient.Builder.expectedResource(URI)(if any).- Parameters:
prmUrl- The PRM document URL (typically theresource_metadatapointer from a401challenge, or the well-known URL for the resource). Must not benull .- Returns:
- The parsed metadata.
- Throws:
McpAuthException- If the fetch fails, the document cannot be parsed, or the resource identity check fails.
-
fetch
Fetches and parses the PRM document at the supplied URL, validating itsresourcefield against the supplied expected resource identifier (RFC 9728 §3.3).- Parameters:
prmUrl- The PRM document URL. Must not benull .expectedResource- The resource identifier the client was actually talking to. May benull to skip the identity check.- Returns:
- The parsed metadata.
- Throws:
McpAuthException- If the fetch fails, the document cannot be parsed, or the resource identity check fails.
-
parse
Parses a PRM JSON document body, validating itsresourcefield against the builder-configuredMcpProtectedResourceMetadataClient.Builder.expectedResource(URI)(if any).- Parameters:
json- The JSON document body. Must not benull .source- The source URI, used only for error messages. May benull .- Returns:
- The parsed metadata.
- Throws:
McpAuthException- If the document cannot be parsed, is missing the requiredresourcefield, or fails the resource identity check.
-
parse
Parses a PRM JSON document body, validating itsresourcefield against the supplied expected resource identifier (RFC 9728 §3.3).- Parameters:
json- The JSON document body. Must not benull .source- The source URI, used only for error messages. May benull .expectedResource- The resource identifier the client was actually talking to. May benull to skip the identity check.- Returns:
- The parsed metadata.
- Throws:
McpAuthException- If the document cannot be parsed, is missing the requiredresourcefield, or fails the resource identity check.
-
discoverAuthorizationServer
Selects the first authorization server from the PRM document and validates its issuer identity via RFC 8414 / OIDC discovery.- Parameters:
prm- The parsed PRM document. Must not benull .- Returns:
- The discovered authorization-server metadata (issuer validated).
- Throws:
McpAuthException- If no authorization server is advertised or discovery/issuer validation fails.
-