MCP PHP SDK

AccessToken implements JsonSerializable

FinalYes

The validated access token a request was authorized with.

The HTTP transports read it from the PSR-7 request attribute AccessToken::class and expose it to handlers through RequestContext::getAccessToken(). AuthorizationMiddleware sets that attribute; an application authenticating requests itself sets it instead. It only lives for the request it arrived with: it is never written to a session store, so a request without a token never inherits an earlier one.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Table of Contents

Interfaces

JsonSerializable

Properties

$claims  : array<string|int, mixed>
$scopes  : array<string|int, mixed>

Methods

__construct()  : mixed
getClaim()  : mixed
getClaims()  : array<string, mixed>
getClientId()  : string|null
The client the token was issued to: `client_id` (RFC 9068), falling back to `azp` (OpenID Connect).
getPrincipal()  : string
Who the token identifies: its issuer, client and subject, which outlive a token refresh.
getScopes()  : array<int, string>
getSubject()  : string|null
The resource owner the token was issued for (`sub`).
hasScope()  : bool
jsonSerialize()  : mixed
Never serialized: the token must not outlive its request in a session store.

Properties

$claims read-only

private array<string|int, mixed> $claims = []

$scopes read-only

private array<string|int, mixed> $scopes = []

Methods

__construct()

public __construct([array<int, string> $scopes = [] ][, array<string, mixed> $claims = [] ]) : mixed
Parameters
$scopes : array<int, string> = []

scopes granted to the token

$claims : array<string, mixed> = []

claims of the token, e.g. a JWT payload or an introspection response

getClaim()

public getClaim(string $name) : mixed
Parameters
$name : string

getClaims()

public getClaims() : array<string, mixed>
Return values
array<string, mixed>

getClientId()

The client the token was issued to: `client_id` (RFC 9068), falling back to `azp` (OpenID Connect).

public getClientId() : string|null
Return values
string|null

getPrincipal()

Who the token identifies: its issuer, client and subject, which outlive a token refresh.

public getPrincipal() : string
Return values
string

getScopes()

public getScopes() : array<int, string>
Return values
array<int, string>

getSubject()

The resource owner the token was issued for (`sub`).

public getSubject() : string|null
Return values
string|null

hasScope()

public hasScope(string $scope) : bool
Parameters
$scope : string
Return values
bool

jsonSerialize()

Never serialized: the token must not outlive its request in a session store.

public jsonSerialize() : mixed
On this page

Search results