Parser
in package
Class Parser.
Table of Contents
- $configuration : SdkConfiguration
- $parsed : bool
- State.
- $token : string
- $tokenClaims : array<string|int, mixed>|null
- Decoded claims contained within the JWT.
- $tokenHeaders : array<string|int, mixed>|null
- Decoded headers contained within the JWT.
- $tokenParts : array<string|int, mixed>|null
- Each of the 3 sections of the JWT separated for easier processing.
- $tokenRaw : string|null
- The unaltered JWT string that was passed to the class constructor.
- $tokenSignature : string|null
- The decoded signature hash for the JWT.
- __construct() : mixed
- Constructor for Token Parser class.
- export() : array<string|int, mixed>
- Return an array representing the Token's claims.
- getClaim() : mixed
- Return the value of a claim on a Token, or null if it is not present.
- getClaims() : array<string, (int|string)[]|int|string>
- Return an array representing the Token's claims.
- getHeader() : string|null
- Return the value of a header on a Token, or null if it is not present.
- getHeaders() : array<string|int, int|string>
- Return an array representing the Token's headers.
- getParts() : array<string|int, string>
- Return an array representing the Token's decoded parts.
- getRaw() : string|null
- Returns the unaltered, encoded JWT as it was originally passed to the class.
- getSignature() : string|null
- Return the signature portion of the JWT.
- hasClaim() : bool
- Returns whether a claim is present on a Token.
- hasHeader() : bool
- Returns whether a header is present on a Token.
- parse() : void
- Process a JWT string, breaking up it's header, claims and signature for processing, and ensures values are properly decoded.
- validate() : Validator
- Returns a new instance of the Token claims Validator class using the parsed token's claims.
- verify() : self
- Verify the signature of the Token using either RS256 or HS256.
- decodeClaims() : array<string|int, (int|string)[]|int|string>|null
- Decodes and returns the claims portion of a JWT as an array.
- decodeHeaders() : array<string|int, int|string>|null
- Decodes and returns the headers portion of a JWT as an array.
- decodeSignature() : string|null
- Decodes and returns the signature portion of a JWT as a string.
Properties
$configuration
private
SdkConfiguration
$configuration
$parsed
State.
private
bool
$parsed
= false
$token
private
string
$token
$tokenClaims
Decoded claims contained within the JWT.
private
array<string|int, mixed>|null
$tokenClaims
= null
$tokenHeaders
Decoded headers contained within the JWT.
private
array<string|int, mixed>|null
$tokenHeaders
= null
$tokenParts
Each of the 3 sections of the JWT separated for easier processing.
private
array<string|int, mixed>|null
$tokenParts
= null
$tokenRaw
The unaltered JWT string that was passed to the class constructor.
private
string|null
$tokenRaw
= null
$tokenSignature
The decoded signature hash for the JWT.
private
string|null
$tokenSignature
= null
Methods
__construct()
Constructor for Token Parser class.
public
__construct(SdkConfiguration $configuration, string $token) : mixed
Parameters
- $configuration : SdkConfiguration
-
Base configuration options for the SDK. See the SdkConfiguration class constructor for options.
- $token : string
-
JSON Web Token to work with
Tags
Return values
mixed —export()
Return an array representing the Token's claims.
public
export() : array<string|int, mixed>
Return values
array<string|int, mixed> —getClaim()
Return the value of a claim on a Token, or null if it is not present.
public
getClaim(string $key) : mixed
Parameters
- $key : string
-
claim key to search for
Return values
mixed —getClaims()
Return an array representing the Token's claims.
public
getClaims() : array<string, (int|string)[]|int|string>
Return values
array<string, (int|string)[]|int|string> —getHeader()
Return the value of a header on a Token, or null if it is not present.
public
getHeader(string $key) : string|null
Parameters
- $key : string
-
header key to search for
Return values
string|null —getHeaders()
Return an array representing the Token's headers.
public
getHeaders() : array<string|int, int|string>
Return values
array<string|int, int|string> —getParts()
Return an array representing the Token's decoded parts.
public
getParts() : array<string|int, string>
Return values
array<string|int, string> —getRaw()
Returns the unaltered, encoded JWT as it was originally passed to the class.
public
getRaw() : string|null
Return values
string|null —getSignature()
Return the signature portion of the JWT.
public
getSignature() : string|null
Return values
string|null —hasClaim()
Returns whether a claim is present on a Token.
public
hasClaim(string $key) : bool
Parameters
- $key : string
-
claim key to search for
Return values
bool —hasHeader()
Returns whether a header is present on a Token.
public
hasHeader(string $key) : bool
Parameters
- $key : string
-
header key to search for
Return values
bool —parse()
Process a JWT string, breaking up it's header, claims and signature for processing, and ensures values are properly decoded.
public
parse() : void
Tags
Return values
void —validate()
Returns a new instance of the Token claims Validator class using the parsed token's claims.
public
validate() : Validator
Return values
Validator —verify()
Verify the signature of the Token using either RS256 or HS256.
public
verify([string|null $algorithm = Token::ALGO_RS256 ][, string|null $jwksUri = null ][, string|null $clientSecret = null ][, int|null $cacheExpires = null ][, CacheItemPoolInterface|null $cache = null ]) : self
Parameters
- $algorithm : string|null = Token::ALGO_RS256
-
Optional. Algorithm to use for verification. Expects either RS256 or HS256. Defaults to RS256.
- $jwksUri : string|null = null
-
Optional. URI to the JWKS when verifying RS256 tokens.
- $clientSecret : string|null = null
-
Optional. Client Secret found in the Application settings for verifying HS256 tokens.
- $cacheExpires : int|null = null
-
Optional. Time in seconds to keep JWKS records cached.
- $cache : CacheItemPoolInterface|null = null
-
Optional. A PSR-6 CacheItemPoolInterface instance to cache JWKS results within.
Tags
Return values
self —decodeClaims()
Decodes and returns the claims portion of a JWT as an array.
private
decodeClaims(string $claims) : array<string|int, (int|string)[]|int|string>|null
Parameters
- $claims : string
-
string representing the claims portion of the JWT
Tags
Return values
array<string|int, (int|string)[]|int|string>|null —decodeHeaders()
Decodes and returns the headers portion of a JWT as an array.
private
decodeHeaders(string $headers) : array<string|int, int|string>|null
Parameters
- $headers : string
-
string representing the headers portion of the JWT
Tags
Return values
array<string|int, int|string>|null —decodeSignature()
Decodes and returns the signature portion of a JWT as a string.
private
decodeSignature(string $signature) : string|null
Parameters
- $signature : string
-
string representing the signature portion of the JWT