Generator
in package
implements
GeneratorInterface, Stringable
Table of Contents
Interfaces
- GeneratorInterface
- Stringable
Constants
- CONST_DIGEST_STRING : array<int, string> = [\OPENSSL_ALGO_SHA256 => 'sha256', \OPENSSL_ALG...
- CONST_KEYTYPE_STRING : array<string|int, string> = [\OPENSSL_KEYTYPE_RSA => 'RSA']
- CONST_SUPPORTED_ALGORITHMS : array<string|int, string> = [\Auth0\SDK\Token::ALGO_HS256, \Auth0\SDK\Token...
Properties
- $algorithm : string
- $claims : array<string|int, mixed>
- $headers : array<string|int, mixed>
- $signingKey : OpenSSLAsymmetricKey|string
- $signingKeyPassphrase : null|string
Methods
- __toString() : string
- Generate a new token and return it as a string.
- create() : static
- Create a new token generator instance.
- toArray() : array<string|int, mixed>
- Generate a new token and return it as an array.
- toString() : string
- Generate a new token and return it as a string.
- __construct() : mixed
- Create a new token generator instance.
- encode() : string
- Encode the provided data segment as a base64-encoded string. Optionally, encode the data as JSON.
- getDigestAlgorithm() : int
- Get the digest algorithm to use for the provided algorithm.
- getOpenSslKeyType() : null|int
- Get the OpenSSL key type to use for the provided algorithm.
- glue() : string
- Glue the provided data segments together with a period, to produce a formatted token.
- loadSigningKey() : OpenSSLAsymmetricKey|string
- Load the provided signing key and return as an appropriate object type.
- openSslErrors() : string
- Retrieve and format the OpenSSL error stack as a string suitable for logging.
- sign() : string
- Sign the provided data with the provided signing key.
Constants
CONST_DIGEST_STRING
public
array<int, string>
CONST_DIGEST_STRING
= [\OPENSSL_ALGO_SHA256 => 'sha256', \OPENSSL_ALGO_SHA384 => 'sha384', \OPENSSL_ALGO_SHA512 => 'sha512']
CONST_KEYTYPE_STRING
public
array<string|int, string>
CONST_KEYTYPE_STRING
= [\OPENSSL_KEYTYPE_RSA => 'RSA']
CONST_SUPPORTED_ALGORITHMS
public
array<string|int, string>
CONST_SUPPORTED_ALGORITHMS
= [\Auth0\SDK\Token::ALGO_HS256, \Auth0\SDK\Token::ALGO_HS384, \Auth0\SDK\Token::ALGO_HS512, \Auth0\SDK\Token::ALGO_RS256, \Auth0\SDK\Token::ALGO_RS384, \Auth0\SDK\Token::ALGO_RS512]
Properties
$algorithm read-only
private
string
$algorithm
= Token::ALGO_RS256
$claims read-only
private
array<string|int, mixed>
$claims
= []
$headers
private
array<string|int, mixed>
$headers
= []
$signingKey
private
OpenSSLAsymmetricKey|string
$signingKey
$signingKeyPassphrase read-only
private
null|string
$signingKeyPassphrase
= null
Methods
__toString()
Generate a new token and return it as a string.
public
__toString() : string
Return values
stringcreate()
Create a new token generator instance.
public
static create(OpenSSLAsymmetricKey|string $signingKey[, string $algorithm = Token::ALGO_RS256 ][, array<string|int, mixed> $claims = [] ][, array<string|int, mixed> $headers = [] ][, null|string $signingKeyPassphrase = null ]) : static
Parameters
- $signingKey : OpenSSLAsymmetricKey|string
-
Signing key to use for signing the token. This MUST be a string for HS256. MUST be either a string or OpenSSLAsymmetricKey for RS256.
- $algorithm : string = Token::ALGO_RS256
-
Algorithm to use for signing the token. Defaults to RS256.
- $claims : array<string|int, mixed> = []
-
Claims to include in the token. Defaults to an empty array.
- $headers : array<string|int, mixed> = []
-
Headers to include in the token. Defaults to an empty array. The the "alg" header will be set to represent $algorithm appropriately.
- $signingKeyPassphrase : null|string = null
-
Optional. Passphrase to use for signing key if it is encrypted. Defaults to null.
Return values
statictoArray()
Generate a new token and return it as an array.
public
toArray([mixed $encodeSegments = true ]) : array<string|int, mixed>
Parameters
- $encodeSegments : mixed = true
-
Whether to encode the segments or not. Defaults to true.
Return values
array<string|int, mixed>toString()
Generate a new token and return it as a string.
public
toString() : string
Return values
string__construct()
Create a new token generator instance.
private
__construct(OpenSSLAsymmetricKey|string $signingKey[, string $algorithm = Token::ALGO_RS256 ][, array<string|int, mixed> $claims = [] ][, array<string|int, string> $headers = [] ][, null|string $signingKeyPassphrase = null ]) : mixed
Parameters
- $signingKey : OpenSSLAsymmetricKey|string
-
Signing key to use for signing the token. This MUST be a string for HS256. MUST be either a string or OpenSSLAsymmetricKey for RS256.
- $algorithm : string = Token::ALGO_RS256
-
Algorithm to use for signing the token. Defaults to RS256.
- $claims : array<string|int, mixed> = []
-
Claims to include in the token. Defaults to an empty array.
- $headers : array<string|int, string> = []
-
Headers to include in the token. Defaults to an empty array. The the "alg" header will be set to represent $algorithm appropriately.
- $signingKeyPassphrase : null|string = null
-
Optional. Passphrase to use for signing key if it is encrypted. Defaults to null.
Tags
encode()
Encode the provided data segment as a base64-encoded string. Optionally, encode the data as JSON.
private
encode(array<string|int, mixed>|string $data, string $segment[, bool $json = true ][, bool $skip = false ]) : string
Parameters
- $data : array<string|int, mixed>|string
-
Data to encode.
- $segment : string
-
Segment name to use for error messages.
- $json : bool = true
-
Whether to encode the data as JSON. Defaults to true.
- $skip : bool = false
-
Whether to skip encoding the data. Defaults to false.
Tags
Return values
stringgetDigestAlgorithm()
Get the digest algorithm to use for the provided algorithm.
private
getDigestAlgorithm() : int
Return values
int —The digest algorithm to use.
getOpenSslKeyType()
Get the OpenSSL key type to use for the provided algorithm.
private
getOpenSslKeyType() : null|int
Return values
null|int —The OpenSSL key type to use.
glue()
Glue the provided data segments together with a period, to produce a formatted token.
private
glue(array<string|int, mixed> $data) : string
Parameters
- $data : array<string|int, mixed>
-
Data segments to glue together.
Return values
stringloadSigningKey()
Load the provided signing key and return as an appropriate object type.
private
loadSigningKey(OpenSSLAsymmetricKey|string $signingKey[, null|string $signingKeyPassphrase = null ]) : OpenSSLAsymmetricKey|string
Parameters
- $signingKey : OpenSSLAsymmetricKey|string
-
Signing key to use for signing the token. This MUST be a string for HS256. MUST be either a string or OpenSSLAsymmetricKey for RS256.
- $signingKeyPassphrase : null|string = null
-
Optional. Passphrase to use for signing key if it is encrypted. Defaults to null.
Tags
Return values
OpenSSLAsymmetricKey|stringopenSslErrors()
Retrieve and format the OpenSSL error stack as a string suitable for logging.
private
openSslErrors() : string
Tags
Return values
string —The OpenSSL error stack.
sign()
Sign the provided data with the provided signing key.
private
sign(string $data) : string
Parameters
- $data : string
-
Data to sign.