PHP Класс JWT

PHP version 5
Автор: Neuman Vong ([email protected])
Автор: Anant Narayanan ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$methods

Открытые методы

Метод Описание
decode ( string $jwt, string | Array | null $key = null, boolean $verify = true ) : object Decodes a JWT string into a PHP object.
encode ( object | array $payload, string $key, string $algo = 'HS256', $keyId = null ) : string Converts and signs a PHP object or array into a JWT string.
jsonDecode ( string $input ) : object Decode a JSON string into a PHP object.
jsonEncode ( object | array $input ) : string Encode a PHP object into a JSON string.
sign ( string $msg, string | resource $key, string $method = 'HS256' ) : string Sign a string with a given key and algorithm.
urlsafeB64Decode ( string $input ) : string Decode a string with URL-safe Base64.
urlsafeB64Encode ( string $input ) : string Encode a string with URL-safe Base64.
verify ( string $msg, string $signature, string | resource $key, string $method = 'HS256' ) : boolean Verify a signature with the mesage, key and method. Not all methods are symmetric, so we must have a separate verify and sign method.

Приватные методы

Метод Описание
handleJsonError ( integer $errno ) : void Helper method to create a JSON error.

Описание методов

decode() публичный статический Метод

Decodes a JWT string into a PHP object.
public static decode ( string $jwt, string | Array | null $key = null, boolean $verify = true ) : object
$jwt string The JWT
$key string | Array | null The secret key, or map of keys
$verify boolean Don't skip verification process
Результат object The JWT's payload as a PHP object

encode() публичный статический Метод

Converts and signs a PHP object or array into a JWT string.
public static encode ( object | array $payload, string $key, string $algo = 'HS256', $keyId = null ) : string
$payload object | array PHP object or array
$key string The secret key
$algo string The signing algorithm. Supported algorithms are 'HS256', 'HS384' and 'HS512'
Результат string A signed JWT

jsonDecode() публичный статический Метод

Decode a JSON string into a PHP object.
public static jsonDecode ( string $input ) : object
$input string JSON string
Результат object Object representation of JSON string

jsonEncode() публичный статический Метод

Encode a PHP object into a JSON string.
public static jsonEncode ( object | array $input ) : string
$input object | array A PHP object or array
Результат string JSON representation of the PHP object or array

sign() публичный статический Метод

Sign a string with a given key and algorithm.
public static sign ( string $msg, string | resource $key, string $method = 'HS256' ) : string
$msg string The message to sign
$key string | resource The secret key
$method string The signing algorithm. Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
Результат string An encrypted message

urlsafeB64Decode() публичный статический Метод

Decode a string with URL-safe Base64.
public static urlsafeB64Decode ( string $input ) : string
$input string A Base64 encoded string
Результат string A decoded string

urlsafeB64Encode() публичный статический Метод

Encode a string with URL-safe Base64.
public static urlsafeB64Encode ( string $input ) : string
$input string The string you want encoded
Результат string The base64 encode of what you passed in

verify() публичный статический Метод

Verify a signature with the mesage, key and method. Not all methods are symmetric, so we must have a separate verify and sign method.
public static verify ( string $msg, string $signature, string | resource $key, string $method = 'HS256' ) : boolean
$msg string the original message
$signature string
$key string | resource for HS*, a string key works. for RS*, must be a resource of an openssl public key
$method string
Результат boolean

Описание свойств

$methods публичное статическое свойство

public static $methods