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 Domframework\Jwt

Namespace Domframework

Description

/**
 Allow to manage the JSON Web Tokens
 Based on https://tools.ietf.org/html/rfc7519

 Do not put confidential data in payload without encrypt it, as the result
 is only a Base64 format of JSON...

Properties

No property available

Methods

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

public function decode ( $jwt, $key, $allowedAlg=null, $ckey=null, $cipherMethod="des-ede3-cbc")
/**
 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
 @param string|null $ckey The cipher key to decrypt the payload
 @param string|null $cipherMethod The method to cipher the payload
 des-ede3-cbc by default
 @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", $ckey=null, $cipherMethod="des-ede3-cbc")
/**
 Create the token based on payload, sign it with key, and optionally
 encrypt it with ckey
 Do not put confidential data in payload without encrypt it, as the result
 is only a Base64 format of JSON...
 @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
 @param string|null $ckey The cipher key to encrypt the payload
 @param string|null $cipherMethod The method to cipher the payload
 des-ede3-cbc by default
 @return string The Token