Class McpOAuthPolicy
MCP's authorization spec makes a protected server a resource server and nothing more — the authorization server is somebody else's (Entra, Okta, Keycloak, Auth0). So this does the four things the spec requires of that role, and deliberately none of the things it requires of an authorization server:
- publish Protected Resource Metadata (RFC 9728) naming the authorization server;
- validate the access token's signature against the authorization server's JWKS;
- validate that the token was issued for this server (RFC 8707 audience binding) — the requirement that stops a token minted for some other API being replayed here;
- answer 401 with a
WWW-Authenticatechallenge pointing at the metadata, and 403 witherror="insufficient_scope"when the token is valid but too weak.
Why a library does the signature check
Verification is delegated to Nimbus rather than hand-rolled. The classic JWT failures — an
"alg":"none" token accepted, an HMAC token verified against the public key, expiry never
checked, kid ignored — all turn the control silently into a no-op. The accepted algorithms
here are declared up front and are asymmetric only, which is what closes the confusion cases.
Copyright 2003-2026 ATB Consultancy Services Ltd
(formerly Orinda Software Ltd, Dublin, Ireland)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classWhat the caller should do with a request. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIssuer URL of the authorization server that mints tokens for this server.static final StringOptional explicit JWKS URI; derived from the issuer when unset.static final StringWhere the metadata document is served, per RFC 9728.static final StringThis server's canonical URI — the audience a token must carry to be accepted here.static final StringOptional space- or comma-separated scopes a token must carry. -
Method Summary
Modifier and TypeMethodDescriptionWhether this request carries an acceptable access token.static McpOAuthPolicyBuild from the environment; fails closed if the required variables are absent.Absolute URL of the metadata document, for the challenge header.The RFC 9728 document, served atMETADATA_PATH.
-
Field Details
-
ISSUER_VARIABLE
Issuer URL of the authorization server that mints tokens for this server.- See Also:
-
RESOURCE_VARIABLE
This server's canonical URI — the audience a token must carry to be accepted here.- See Also:
-
JWKS_URI_VARIABLE
Optional explicit JWKS URI; derived from the issuer when unset.- See Also:
-
SCOPES_VARIABLE
Optional space- or comma-separated scopes a token must carry.- See Also:
-
METADATA_PATH
Where the metadata document is served, per RFC 9728.- See Also:
-
-
Method Details
-
fromEnvironment
Build from the environment; fails closed if the required variables are absent.- Throws:
CSException
-
authorize
Whether this request carries an acceptable access token.- Parameters:
theAuthorizationHeader- the rawAuthorizationheader, or null
-
protectedResourceMetadataJson
The RFC 9728 document, served atMETADATA_PATH. -
metadataUrl
Absolute URL of the metadata document, for the challenge header.
-