Class WwwAuthenticateChallenge

java.lang.Object
org.apache.juneau.rest.client.mcp.auth.WwwAuthenticateChallenge
All Implemented Interfaces:
Serializable

public class WwwAuthenticateChallenge extends Object implements Serializable
A parsed WWW-Authenticate: Bearer ... challenge as returned by an OAuth 2.1 / MCP resource server on a 401/403 response (RFC 6750 §3, RFC 9728 §5.1).

The MCP client uses this to recover the resource_metadata pointer to the RFC 9728 PRM document, the per-operation scope on a step-up challenge, and the error code. Auth-param values are matched case-insensitively on the key per RFC 7235.

Serializable (it is just a scheme string plus an immutable string map) so it can ride along a serialized McpInsufficientScopeException without being dropped.

Since:
10.0.0
See Also:
  • Constructor Details

    • WwwAuthenticateChallenge

      protected WwwAuthenticateChallenge(String scheme, Map<String,String> parameters)
      Constructor.
      Parameters:
      scheme - The auth scheme (e.g. "Bearer"). Must not be null or blank.
      parameters - The auth-params (lower-cased keys). Must not be null.
  • Method Details

    • parse

      public static Optional<WwwAuthenticateChallenge> parse(String headerValue)
      Parses a single WWW-Authenticate header value.

      Recognizes a single challenge of the form <scheme> <key>=<value>, <key>="<value>", .... Both quoted and bare token values are accepted; commas inside quoted values are preserved.

      Parameters:
      headerValue - The raw header value. May be null or blank.
      Returns:
      The parsed challenge, or Optional.empty() if the value is null/blank or has no scheme token.
    • scheme

      public String scheme()
      Returns the auth scheme.
      Returns:
      The scheme (e.g. "Bearer"). Never null.
    • isBearer

      public boolean isBearer()
      Returns whether the scheme is Bearer (case-insensitive).
      Returns:
      true if this is a Bearer challenge.
    • parameters

      Returns the parsed auth-params (lower-cased keys).
      Returns:
      An unmodifiable map. Never null.
    • parameter

      public Optional<String> parameter(String name)
      Returns the raw value of an auth-param.
      Parameters:
      name - The param name (matched case-insensitively). Must not be null.
      Returns:
      The value, or Optional.empty() if absent.
    • resourceMetadata

      Returns the resource_metadata pointer (RFC 9728 §5.1) to the PRM document.
      Returns:
      The PRM document URI, or Optional.empty() if absent or unparseable as a URI.
    • error

      public Optional<String> error()
      Returns the error code (e.g. "insufficient_scope"), if present.
      Returns:
      The error code, or Optional.empty().
    • scopes

      public Set<String> scopes()
      Returns the space-delimited scope param as an order-preserving set.
      Returns:
      The challenged scopes (empty if the param is absent or blank). Never null.