MCP Authorization support for OAuth 2.1 with PKCE.
This is a cleaned-up version of the Authorization module that delegates to focused, single-responsibility modules:
ExMCP.Authorization.OAuthFlow- OAuth flow implementationsExMCP.Authorization.PKCE- PKCE security implementationExMCP.Authorization.HTTPClient- HTTP communicationExMCP.Authorization.Validator- Parameter validation
This module serves as a facade, maintaining the same public API while leveraging the decomposed architecture for better maintainability.
Summary
Functions
Performs OAuth 2.1 client credentials flow.
Discovers server metadata from the authorization server.
Exchanges an authorization code for an access token using PKCE.
Generates PKCE code challenge parameters.
Refreshes an access token using a refresh token.
Starts an OAuth 2.1 authorization code flow with PKCE.
Makes a token request to the authorization server.
Validates an authorization callback before its code is redeemed.
Validates an access token with the authorization server.
Verifies a PKCE code challenge.
Types
@type authorization_config() :: %{ optional(:issuer) => String.t(), client_id: String.t(), client_secret: String.t() | nil, authorization_endpoint: String.t(), token_endpoint: String.t(), redirect_uri: String.t(), scopes: [String.t()], additional_params: map() | nil, resource: String.t() | [String.t()] | nil }
Functions
@spec client_credentials_flow(map()) :: {:ok, token_response()} | {:error, term()}
Performs OAuth 2.1 client credentials flow.
Delegates to ExMCP.Authorization.OAuthFlow.client_credentials_flow/1
@spec discover_server_metadata(String.t()) :: {:ok, server_metadata()} | {:error, term()}
Discovers server metadata from the authorization server.
Uses HTTPClient for the actual HTTP request and metadata parsing.
@spec exchange_code_for_token(map()) :: {:ok, token_response()} | {:error, term()}
Exchanges an authorization code for an access token using PKCE.
Pass either transaction_id: transaction.transaction_id or
transaction: transaction so redemption is single-use and bound to the
callback's exact redirect URI.
Generates PKCE code challenge parameters.
Delegates to the PKCE module.
@spec refresh_token(String.t(), String.t(), String.t(), String.t() | nil) :: {:ok, token_response()} | {:error, term()}
Refreshes an access token using a refresh token.
Delegates to ExMCP.Authorization.OAuthFlow.refresh_token/4
@spec start_authorization_flow(authorization_config()) :: {:ok, String.t(), map()} | {:error, term()}
Starts an OAuth 2.1 authorization code flow with PKCE.
Delegates to ExMCP.Authorization.OAuthFlow.start_authorization_flow/1
with the same interface and behavior. State and PKCE values are generated by
ExMCP; reserved OAuth fields cannot be overridden through additional_params.
Makes a token request to the authorization server.
Used internally by TokenManager for refresh operations. Delegates to HTTPClient for the actual request.
Validates an authorization callback before its code is redeemed.
Pass the transaction returned by start_authorization_flow/1. This atomically
consumes its recorded state and, when the response contains the RFC 9207
iss parameter, enforces exact equality with the recorded issuer.
Validates an access token with the authorization server.
Uses HTTPClient for the introspection request.
Verifies a PKCE code challenge.
Delegates to the PKCE module.