AccessToken implements JsonSerializable
An OAuth 2.1 token response: the access token plus everything needed to keep using it.
Tags
Table of Contents
Interfaces
- JsonSerializable
Constants
- EXPIRY_LEEWAY_SECONDS : mixed = 30
- Seconds before the expiry at which a stored token isn't worth reusing, as it could expire in flight.
Properties
- $accessToken : string
- $clientId : string|null
- $expiresAt : int|null
- $refreshToken : string|null
- $scopes : array<string|int, mixed>
- $tokenType : string
Methods
- __construct() : mixed
- covers() : bool
- Whether every one of the given scopes was granted.
- fromArray() : self
- fromResponse() : self
- Build a token from a parsed token endpoint response (RFC 6749 section 5.1).
- getAuthorizationHeader() : string
- isExpired() : bool
- isExpiringSoon() : bool
- isIssuedTo() : bool
- Whether the token may be used by this client: a token and its refresh token belong to the client they were issued to (RFC 6749 section 6).
- jsonSerialize() : array<string, mixed>
- withClientId() : self
- withGrantedScopes() : self
- Record the requested scopes when the server reported none (RFC 6749 section 5.1).
- expiresAt() : int|null
- splitScopes() : array<string|int, string>
Constants
EXPIRY_LEEWAY_SECONDS
Seconds before the expiry at which a stored token isn't worth reusing, as it could expire in flight.
private
mixed
EXPIRY_LEEWAY_SECONDS
= 30
Properties
$accessToken read-only
public
string
$accessToken
$clientId read-only
public
string|null
$clientId
= null
$expiresAt read-only
public
int|null
$expiresAt
= null
$refreshToken read-only
public
string|null
$refreshToken
= null
$scopes read-only
public
array<string|int, mixed>
$scopes
= []
$tokenType read-only
public
string
$tokenType
= 'Bearer'
Methods
__construct()
public
__construct(string $accessToken[, string $tokenType = 'Bearer' ][, int|null $expiresAt = null ][, string|null $refreshToken = null ][, array<string|int, string> $scopes = [] ][, string|null $clientId = null ]) : mixed
Parameters
- $accessToken : string
-
the token to present to the resource server
- $tokenType : string = 'Bearer'
-
the token type, "Bearer" for everything MCP defines
- $expiresAt : int|null = null
-
unix timestamp the token expires at, null when the server did not say
- $refreshToken : string|null = null
-
the refresh token, when the grant produced one
- $scopes : array<string|int, string> = []
-
the scopes the authorization server actually granted
- $clientId : string|null = null
-
the client the token was issued to, null when unknown
covers()
Whether every one of the given scopes was granted.
public
covers(array<string|int, string> $scopes) : bool
Parameters
- $scopes : array<string|int, string>
Return values
boolfromArray()
public
static fromArray(array<string, mixed> $data) : self
Parameters
- $data : array<string, mixed>
Return values
selffromResponse()
Build a token from a parsed token endpoint response (RFC 6749 section 5.1).
public
static fromResponse(array<string, mixed> $response[, int|null $now = null ]) : self
Parameters
- $response : array<string, mixed>
- $now : int|null = null
Return values
selfgetAuthorizationHeader()
public
getAuthorizationHeader() : string
Return values
stringisExpired()
public
isExpired([int|null $now = null ]) : bool
Parameters
- $now : int|null = null
Return values
boolisExpiringSoon()
public
isExpiringSoon([int|null $now = null ]) : bool
Parameters
- $now : int|null = null
Return values
boolisIssuedTo()
Whether the token may be used by this client: a token and its refresh token belong to the client they were issued to (RFC 6749 section 6).
public
isIssuedTo(string|null $clientId) : bool
Parameters
- $clientId : string|null
Return values
booljsonSerialize()
public
jsonSerialize() : array<string, mixed>
Return values
array<string, mixed>withClientId()
public
withClientId(string $clientId) : self
Parameters
- $clientId : string
Return values
selfwithGrantedScopes()
Record the requested scopes when the server reported none (RFC 6749 section 5.1).
public
withGrantedScopes(array<string|int, string> $scopes) : self
Parameters
- $scopes : array<string|int, string>
Return values
selfexpiresAt()
private
static expiresAt(mixed $expiresIn, int $now) : int|null
Parameters
- $expiresIn : mixed
- $now : int
Return values
int|nullsplitScopes()
private
static splitScopes(string $scope) : array<string|int, string>
Parameters
- $scope : string