Auth0-PHP

Parser
in package

FinalYes

Table of Contents

Properties

$configuration  : SdkConfiguration
$parsed  : bool
State.
$token  : string
$tokenClaims  : array<string, array<string|int, int|string>|int|string>
Decoded claims contained within the JWT.
$tokenHeaders  : null|array<string|int, int>|array<string|int, string>
Decoded headers contained within the JWT.
$tokenParts  : null|array<string|int, string>
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.

Methods

__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, array<string|int, 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()  : null|array<string|int, array<string|int, int|string>|int|string>
Decodes and returns the claims portion of a JWT as an array.
decodeHeaders()  : null|array<string|int, int|string>
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

$parsed

State.

private bool $parsed

$token read-only

private string $token

$tokenClaims

Decoded claims contained within the JWT.

private array<string, array<string|int, int|string>|int|string> $tokenClaims = null

$tokenHeaders

Decoded headers contained within the JWT.

private null|array<string|int, int>|array<string|int, string> $tokenHeaders = null

$tokenParts

Each of the 3 sections of the JWT separated for easier processing.

private null|array<string|int, string> $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
throws
InvalidTokenException

When Token parsing fails. See the exception message for further details.

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

getClaims()

Return an array representing the Token's claims.

public getClaims() : array<string, array<string|int, int|string>|int|string>
Return values
array<string, array<string|int, 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
throws
InvalidTokenException

When Token parsing fails. See the exception message for further details.

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([null|string $algorithm = Token::ALGO_RS256 ][, null|string $jwksUri = null ][, null|string $clientSecret = null ][, null|int $cacheExpires = null ][, null|CacheItemPoolInterface $cache = null ]) : self
Parameters
$algorithm : null|string = Token::ALGO_RS256

Optional. Algorithm to use for verification. Expects either RS256 or HS256. Defaults to RS256.

$jwksUri : null|string = null

Optional. URI to the JWKS when verifying RS256 tokens.

$clientSecret : null|string = null

Optional. Client Secret found in the Application settings for verifying HS256 tokens.

$cacheExpires : null|int = null

Optional. Time in seconds to keep JWKS records cached.

$cache : null|CacheItemPoolInterface = null

Optional. A PSR-6 CacheItemPoolInterface instance to cache JWKS results within.

Tags
throws
InvalidTokenException

When Token signature verification fails. See the exception message for further details.

Return values
self

decodeClaims()

Decodes and returns the claims portion of a JWT as an array.

private decodeClaims(string $claims) : null|array<string|int, array<string|int, int|string>|int|string>
Parameters
$claims : string

string representing the claims portion of the JWT

Tags
throws
JsonException

when claims portion cannot be decoded properly

codeCoverageIgnore
Return values
null|array<string|int, array<string|int, int|string>|int|string>

decodeHeaders()

Decodes and returns the headers portion of a JWT as an array.

private decodeHeaders(string $headers) : null|array<string|int, int|string>
Parameters
$headers : string

string representing the headers portion of the JWT

Tags
throws
JsonException

when headers portion cannot be decoded properly

codeCoverageIgnore
Return values
null|array<string|int, int|string>

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

Tags
codeCoverageIgnore
Return values
string|null
On this page

Search results