Back to the module list

JSON Web Token

This class allow to generate JSON Web Tokens and check if the user provided token is valid

The class definition

Class \jwt

Namespace \


 Allow to manage the JSON Web Tokens
 Based on


No property available


public function createKey ()
 Create a signing key
 @return string the signing key proposed

public function decode ( $jwt, $key, $allowedAlg=null)
 Decode the provide JWT and return an array of the payload
 @param string $jwt The token to examine
 @param string $key The key used to sign the message
 @param array|null $allowedAlg List of allowed algorithms. If null, all the
 algorithms defined in $this->supportedAlgs are allowed
 @return array the decoded payload
 @throw Exception if the key is not able to verify the token with the
 provided password

public function encode ( $payload, $key, $alg="HS256")
 Create the token based on payload, key
 @param array $payload The payload to store
 @param string $key The key to be used to sign the token
 @param string|null $alg The algorithm to use to sign the token (default
   is HS256)
 Allowed algorithms : HS256, HS512, HS384
 @return string The Token