Reference documentation and code samples for the A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec. Client class JWT.
JSON Web Token implementation, based on this spec: https://tools.ietf.org/html/rfc7519
PHP version 5
Namespace
Firebase \ JWTMethods
static::decode
Decodes a JWT string into a PHP object.
| Parameters | |
|---|---|
| Name | Description |
jwt |
string
The JWT |
keyOrKeyArray |
Key|ArrayAccess<string,\Firebase\JWT\Key>|array
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'. |
headers |
stdClass
Optional. Populates stdClass with headers. |
| Returns | |
|---|---|
| Type | Description |
stdClass |
The JWT's payload as a PHP object |
static::encode
Converts and signs a PHP array into a JWT string.
| Parameters | |
|---|---|
| Name | Description |
payload |
array
PHP array |
key |
string|OpenSSLAsymmetricKey|OpenSSLCertificate
The secret key. |
alg |
string
Supported algorithms are 'ES384','ES256', 'ES256K', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512' |
keyId |
string
|
head |
array
An array with header elements to attach |
| Returns | |
|---|---|
| Type | Description |
string |
A signed JWT |
static::sign
Sign a string with a given key and algorithm.
| Parameters | |
|---|---|
| Name | Description |
msg |
string
The message to sign |
key |
string|OpenSSLAsymmetricKey|OpenSSLCertificate
The secret key. |
alg |
string
Supported algorithms are 'EdDSA', 'ES384', 'ES256', 'ES256K', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', 'PS256' and 'RS512' |
| Returns | |
|---|---|
| Type | Description |
string |
An encrypted message |
static::jsonDecode
Decode a JSON string into a PHP object.
| Parameter | |
|---|---|
| Name | Description |
input |
string
JSON string |
| Returns | |
|---|---|
| Type | Description |
mixed |
The decoded JSON string |
static::jsonEncode
Encode a PHP array into a JSON string.
| Parameter | |
|---|---|
| Name | Description |
input |
array
A PHP array |
| Returns | |
|---|---|
| Type | Description |
string |
JSON representation of the PHP array |
static::urlsafeB64Decode
Decode a string with URL-safe Base64.
| Parameter | |
|---|---|
| Name | Description |
input |
string
A Base64 encoded string |
| Returns | |
|---|---|
| Type | Description |
string |
A decoded string |
static::convertBase64UrlToBase64
See also:
| Parameter | |
|---|---|
| Name | Description |
input |
string
A Base64 encoded string with URL-safe characters (-_ and no padding) |
| Returns | |
|---|---|
| Type | Description |
string |
A Base64 encoded string with standard characters (+/) and padding (=), when needed. |
static::urlsafeB64Encode
Encode a string with URL-safe Base64.
| Parameter | |
|---|---|
| Name | Description |
input |
string
The string you want encoded |
| Returns | |
|---|---|
| Type | Description |
string |
The base64 encode of what you passed in |
static::constantTimeEquals
| Parameters | |
|---|---|
| Name | Description |
left |
string
The string of known length to compare against |
right |
string
The user-supplied string |
| Returns | |
|---|---|
| Type | Description |
bool |
|