MCP PHP SDK

AuthenticatorInterface

Attaches credentials to outgoing HTTP requests and reacts to authentication challenges.

The two halves are deliberately separate: self::authenticate() runs on every request and must stay cheap, while self::handleChallenge() only runs when the resource server actually pushes back, which is where an interactive or network-bound flow belongs.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Table of Contents

Methods

authenticate()  : RequestInterface
Return the request carrying whatever credentials are currently available.
handleChallenge()  : bool
React to a 401 or 403 answer from the resource server.

Methods

authenticate()

Return the request carrying whatever credentials are currently available.

public authenticate(RequestInterface $request) : RequestInterface

Implementations return the request unchanged when they hold none: the resource server answering with a challenge is what starts the flow.

Parameters
$request : RequestInterface
Tags
throws
AuthorizationException

when the credentials cannot be obtained

Return values
RequestInterface

handleChallenge()

React to a 401 or 403 answer from the resource server.

public handleChallenge(RequestInterface $request, ResponseInterface $response) : bool
Parameters
$request : RequestInterface

the request that was rejected

$response : ResponseInterface

the rejecting response, carrying the challenge

Tags
throws
AuthorizationException

when the credentials cannot be obtained

Return values
bool —

true when credentials were obtained and the request should be retried, false when the authenticator cannot make progress

On this page

Search results