ExMCP.Authorization (ex_mcp v0.10.0)
View SourceMCP 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 access token with the authorization server.
Verifies a PKCE code challenge.
Types
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.
Delegates to ExMCP.Authorization.OAuthFlow.exchange_code_for_token/1
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.
Makes a token request to the authorization server.
Used internally by TokenManager for refresh operations. Delegates to HTTPClient for the actual request.
Validates an access token with the authorization server.
Uses HTTPClient for the introspection request.
Verifies a PKCE code challenge.
Delegates to the PKCE module.