Client
NAME
MCP::OAuth::Client - OAuth 2.1 client-side authorization handler
DESCRIPTION
Manages the client side of OAuth 2.1 authorization for MCP transports: metadata discovery, authorization code flow with PKCE, token exchange, refresh, and dynamic client registration.
CLASS
OAuthClientHandler
my $oauth = OAuthClientHandler.new(
resource-url => 'https://mcp.example.com',
client-id => 'my-app',
redirect-uri => 'http://localhost:9999/callback',
);
Key methods:
.discover-metadata(--Promise)> ā Fetch OAuth server metadata from well-known endpoint..authorization-url(--Str)> ā Build the authorization URL with PKCE challenge..exchange-code(Str $code --Promise)> ā Exchange authorization code for tokens..refresh-token(--Promise)> ā Refresh an expired access token..register-client(--Promise)> ā Perform dynamic client registration..access-token(--Str)> ā Get the current access token.
");
@params.push("client_id={uri-encode($!client-id)}");
@params.push("redirect_uri={uri-encode($!redirect-uri)}");
@params.push("code_challenge={uri-encode($challenge)}");
@params.push("code_challenge_method=S256");
@params.push("resource={uri-encode($!resource-url)}");
@params.push("state={uri-encode($state)}");
@params.push("scope={uri-encode(@!scopes.join(' '))}") if @!scopes;