MCP PHP SDK

BearerToken implements AuthenticatorInterface

FinalYes

Sends a fixed bearer token, obtained outside the SDK.

Useful when the token comes from somewhere the SDK has no business knowing about -- a secrets manager, an already-authenticated session, a personal access token pasted into a config file. There is nothing to negotiate, so a challenge is never actionable.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Table of Contents

Interfaces

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

Properties

$token  : string

Methods

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

Properties

Methods

__construct()

public __construct(string $token) : mixed
Parameters
$token : string

the raw access token, without the "Bearer " prefix

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
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

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