AuthenticatingHttpClient implements ClientInterface
FinalYes
A PSR-18 client that authenticates every request and retries the ones the resource server challenges.
Wrapping the HTTP client rather than teaching the transport about OAuth keeps the two concerns apart: the transport still speaks MCP over plain PSR-18, and the same decorator authenticates anything else the application sends to that server.
Tags
Table of Contents
Interfaces
- ClientInterface
Constants
- DEFAULT_MAX_AUTHORIZATION_ATTEMPTS : mixed = 3
- Authorization attempts allowed while serving a single request.
Properties
- $authenticator : AuthenticatorInterface
- $client : ClientInterface
- $maxAuthorizationAttempts : int
Methods
- __construct() : mixed
- sendRequest() : ResponseInterface
- sendUnchallenged() : ResponseInterface
- Send a request that isn't worth a new authorization, such as closing a session.
- replayPosition() : int|null
Constants
DEFAULT_MAX_AUTHORIZATION_ATTEMPTS
Authorization attempts allowed while serving a single request.
public
mixed
DEFAULT_MAX_AUTHORIZATION_ATTEMPTS
= 3
A server that keeps answering "insufficient scope" no matter what is asking for an infinite loop; the specification asks clients to cap the escalation instead.
Properties
$authenticator read-only
private
AuthenticatorInterface
$authenticator
$client read-only
private
ClientInterface
$client
$maxAuthorizationAttempts read-only
private
int
$maxAuthorizationAttempts
= self::DEFAULT_MAX_AUTHORIZATION_ATTEMPTS
Methods
__construct()
public
__construct(ClientInterface $client, AuthenticatorInterface $authenticator[, int $maxAuthorizationAttempts = self::DEFAULT_MAX_AUTHORIZATION_ATTEMPTS ]) : mixed
Parameters
- $client : ClientInterface
- $authenticator : AuthenticatorInterface
- $maxAuthorizationAttempts : int = self::DEFAULT_MAX_AUTHORIZATION_ATTEMPTS
sendRequest()
public
sendRequest(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Return values
ResponseInterfacesendUnchallenged()
Send a request that isn't worth a new authorization, such as closing a session.
public
sendUnchallenged(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Return values
ResponseInterfacereplayPosition()
private
static replayPosition(StreamInterface $body) : int|null
Parameters
- $body : StreamInterface