The Data Object - fachsimpeln/EasyJWT GitHub Wiki

Description

All claims are stored in a Data Container Object (JWTData), which also contains the header (JWTOptions) and the signature of the JWT.

So this is the first step to create your first JWT.

Parameters for creating a new JWTData object

The JWTData constructor accepts an array of the data (the claims) you want to save and the options object (JWTOptions). (If the options are empty, it will use the default options.)

Parameter Description
$jwt_data The data (claims) as array for the JWT
$jwt_options JWT Options object

Creating a JWTData object

  1. First, we going to need some sample data in form of an array.
$sample_array = array();
$sample_array['id'] = '0';
$sample_array['name'] = 'fachsimpeln';

$jwt_options = new EasyJWT\JWTOptions( 'HS512' );
  1. Then, create a new JWTData object with this array - if the options are null, it will use the default options.
$jwt_data = new EasyJWT\JWTData( $sample_array, $jwt_options );

Reading from the cookies

If $jwt_data is null, JWTData will attempt to parse the value from the cookie.

$jwt_data = new EasyJWT\JWTData();

Reading from a string

If $jwt_data is a string, JWTData will attempt to parse that string. (JSON Web Token as string [e.g. cookie value])

$value = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
$jwt_data = new EasyJWT\JWTData( $value );

Note: The signature will NOT be validated when you create a JWTData object. The signature is only verified, when you create a JWT object with the JWTData as the parameter.

Encryption

If you want to encrypt the data container object, just use JWTDataEncrypted instead of JWTData

The encryption uses the encryption key specified in the configuration and the process is automatic.


This container should not be accessed by the software directly, you should always use (to read/write) the main class JWT!