San Romilla 1.0.0
Loading...
Searching...
No Matches
JWT Class Reference

Static Public Member Functions

static decode (string $jwt, $keyOrKeyArray)
 
static encode (array $payload, $key, string $alg, string $keyId=null, array $head=null)
 
static sign (string $msg, $key, string $alg)
 
static jsonDecode (string $input)
 
static jsonEncode (array $input)
 
static urlsafeB64Decode (string $input)
 
static urlsafeB64Encode (string $input)
 
static constantTimeEquals (string $left, string $right)
 

Static Public Attributes

static $leeway = 0
 
static $timestamp = null
 
static $supported_algs
 

Member Function Documentation

◆ constantTimeEquals()

static constantTimeEquals ( string $left,
string $right )
static
Parameters
string$leftThe string of known length to compare against
string$rightThe user-supplied string
Returns
bool

◆ decode()

static decode ( string $jwt,
$keyOrKeyArray )
static

Decodes a JWT string into a PHP object.

Parameters
string$jwtThe JWT
Key|array<string,Key>$keyOrKeyArray The Key or associative array of key IDs (kid) to Key objects. If the algorithm used is asymmetric, this is the public key Each Key object contains an algorithm and matching key. Supported algorithms are 'ES384','ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
Returns
stdClass The JWT's payload as a PHP object
Exceptions
InvalidArgumentExceptionProvided key/key-array was empty or malformed
DomainExceptionProvided JWT is malformed
UnexpectedValueExceptionProvided JWT was invalid
SignatureInvalidExceptionProvided JWT was invalid because the signature verification failed
BeforeValidExceptionProvided JWT is trying to be used before it's eligible as defined by 'nbf'
BeforeValidExceptionProvided JWT is trying to be used before it's been created as defined by 'iat'
ExpiredExceptionProvided JWT has since expired, as defined by the 'exp' claim

@uses jsonDecode @uses urlsafeB64Decode

◆ encode()

static encode ( array $payload,
$key,
string $alg,
string $keyId = null,
array $head = null )
static

Converts and signs a PHP array into a JWT string.

Parameters
array<mixed>$payload PHP array
string | resource | OpenSSLAsymmetricKey | OpenSSLCertificate$keyThe secret key.
string$algSupported algorithms are 'ES384','ES256', 'ES256K', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
string$keyId
array<string,string>$head An array with header elements to attach
Returns
string A signed JWT

@uses jsonEncode @uses urlsafeB64Encode

◆ jsonDecode()

static jsonDecode ( string $input)
static

Decode a JSON string into a PHP object.

Parameters
string$inputJSON string
Returns
mixed The decoded JSON string
Exceptions
DomainExceptionProvided string was invalid JSON

◆ jsonEncode()

static jsonEncode ( array $input)
static

Encode a PHP array into a JSON string.

Parameters
array<mixed>$input A PHP array
Returns
string JSON representation of the PHP array
Exceptions
DomainExceptionProvided object could not be encoded to valid JSON

◆ sign()

static sign ( string $msg,
$key,
string $alg )
static

Sign a string with a given key and algorithm.

Parameters
string$msgThe message to sign
string | resource | OpenSSLAsymmetricKey | OpenSSLCertificate$keyThe secret key.
string$algSupported algorithms are 'ES384','ES256', 'ES256K', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
Returns
string An encrypted message
Exceptions
DomainExceptionUnsupported algorithm or bad key was specified

◆ urlsafeB64Decode()

static urlsafeB64Decode ( string $input)
static

Decode a string with URL-safe Base64.

Parameters
string$inputA Base64 encoded string
Returns
string A decoded string
Exceptions
InvalidArgumentExceptioninvalid base64 characters

◆ urlsafeB64Encode()

static urlsafeB64Encode ( string $input)
static

Encode a string with URL-safe Base64.

Parameters
string$inputThe string you want encoded
Returns
string The base64 encode of what you passed in

Field Documentation

◆ $supported_algs

$supported_algs
static
Initial value:
= [
'ES384' => ['openssl', 'SHA384'],
'ES256' => ['openssl', 'SHA256'],
'ES256K' => ['openssl', 'SHA256'],
'HS256' => ['hash_hmac', 'SHA256'],
'HS384' => ['hash_hmac', 'SHA384'],
'HS512' => ['hash_hmac', 'SHA512'],
'RS256' => ['openssl', 'SHA256'],
'RS384' => ['openssl', 'SHA384'],
'RS512' => ['openssl', 'SHA512'],
'EdDSA' => ['sodium_crypto', 'EdDSA'],
]

The documentation for this class was generated from the following file: