PHP Класс Psecio\Jwt\Jwt

Показать файл Открыть проект Примеры использования класса

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

Метод Описание
__call ( string $name, array $args ) : Jwt Magic method for setting claims by name Ex. "issuedAt()" calls Claims\IssuedAt
__construct ( Header $header, ClaimsCollection $collection = null ) Initialize the object and set the header and claims collection Empty claims collection is set if none is given
__get ( string $name ) : mixed See if a claim type matches the requested property
addClaim ( Claim $claim ) : Jwt Add a Claim to the current collection
base64Decode ( string $data ) : string Base64 decode (and url decode) the given data
base64Encode ( string $data ) : string Base64 encode data and prepare for the URL NOTE: The "=" is removed as it's just padding in base64 and not needed.
custom ( string | array $value, string $name = null ) : Jwt Allow for the insertion of multiple custom values at once
decode ( string $data, boolean $verify = true ) : stdClass Decode the data with the given key Optional "verify" parameter validates the signature as well (default is on)
decrypt ( string $data, string $algorithm, string $iv, $key ) : string Decrypt given data wtih given key (and algorithm/IV)
encode ( string $claims = null, $addIssued = false ) : string Encode the data, either given or from current object
encrypt ( string $algorithm, string $iv, $key ) : string Encrypt the data with the given key (and algorithm/IV)
getClaims ( ) : ClaimsCollection Get the current claims collection
getHeader ( ) : Header Get the currently assigned header instance
hash_equals ( $a, $b ) Polyfill PHP 5.6.0's hash_equals() feature
setClaims ( ClaimsCollection $collection ) : Jwt Set the claims collection
setHeader ( Header $header ) : Jwt Set the header instance
sign ( string $signWith, string $key ) : string Generate the signature with the given data, key and algorithm
verify ( string $key, stdClass $header, stdClass $claims, string $signature ) : boolean Verify the signature on the JWT message

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

__call() публичный Метод

Magic method for setting claims by name Ex. "issuedAt()" calls Claims\IssuedAt
public __call ( string $name, array $args ) : Jwt
$name string Function name
$args array Arguments to pass
Результат Jwt instance

__construct() публичный Метод

Initialize the object and set the header and claims collection Empty claims collection is set if none is given
public __construct ( Header $header, ClaimsCollection $collection = null )
$header Header Header instance to set on JWT object
$collection ClaimsCollection Claims collection [optional]

__get() публичный Метод

See if a claim type matches the requested property
public __get ( string $name ) : mixed
$name string Property name
Результат mixed Either a null if not found or the matching data

addClaim() публичный Метод

Add a Claim to the current collection
public addClaim ( Claim $claim ) : Jwt
$claim Claim Claim instance to add
Результат Jwt Current Jwt instance

base64Decode() публичный Метод

Base64 decode (and url decode) the given data
public base64Decode ( string $data ) : string
$data string Data to decode
Результат string Decoded data

base64Encode() публичный Метод

Base64 encode data and prepare for the URL NOTE: The "=" is removed as it's just padding in base64 and not needed.
public base64Encode ( string $data ) : string
$data string Data string
Результат string Formatted data

custom() публичный Метод

Allow for the insertion of multiple custom values at once
public custom ( string | array $value, string $name = null ) : Jwt
$value string | array Either a string for a single claim or array for multiple
$name string Name of claim to use if string given for "name" [optional]
Результат Jwt instance

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

Decode the data with the given key Optional "verify" parameter validates the signature as well (default is on)
public decode ( string $data, boolean $verify = true ) : stdClass
$data string Data to decode (entire JWT data string)
$verify boolean Verify the signature on the data [optional]
Результат stdClass Decoded claims data

decrypt() публичный Метод

Decrypt given data wtih given key (and algorithm/IV)
public decrypt ( string $data, string $algorithm, string $iv, $key ) : string
$data string Data to decrypt
$algorithm string Algorithm to use for decrypting the data
$iv string
Результат string Decrypted data

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

Encode the data, either given or from current object
public encode ( string $claims = null, $addIssued = false ) : string
$claims string Claims string to encode [optional]
Результат string Encoded data, appended by periods

encrypt() публичный Метод

Encrypt the data with the given key (and algorithm/IV)
public encrypt ( string $algorithm, string $iv, $key ) : string
$algorithm string Algorithm to use for encryption
$iv string IV for encrypting data
Результат string Encrypted string

getClaims() публичный Метод

Get the current claims collection
public getClaims ( ) : ClaimsCollection
Результат ClaimsCollection instance

getHeader() публичный Метод

Get the currently assigned header instance
public getHeader ( ) : Header
Результат Header Header object instance

hash_equals() публичный Метод

Polyfill PHP 5.6.0's hash_equals() feature
public hash_equals ( $a, $b )

setClaims() публичный Метод

Set the claims collection
public setClaims ( ClaimsCollection $collection ) : Jwt
$collection ClaimsCollection Claims collection instance
Результат Jwt Current Jwt instance

setHeader() публичный Метод

Set the header instance
public setHeader ( Header $header ) : Jwt
$header Header [description]
Результат Jwt Current Jwt instance

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

Generate the signature with the given data, key and algorithm
public sign ( string $signWith, string $key ) : string
$signWith string Data to sign hash with
$key string Key for signing
Результат string Generated signature hash

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

Verify the signature on the JWT message
public verify ( string $key, stdClass $header, stdClass $claims, string $signature ) : boolean
$key string Key used for hashing
$header stdClass Header data (object)
$claims stdClass Set of claims
$signature string Signature string
Результат boolean Pass/fail of verification