PHP code example of siu-toba / jwt-util

1. Go to this page and download the library: Download siu-toba/jwt-util library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

siu-toba / jwt-util example snippets

  php
    $keySimetrica = 'test';

    $datos = ['uid'=>'id-usuario', 'name'=>'usuario de prueba'];

    $simetricEncoder = new SimetricEncoder(Util::ALG_HS512, $keySimetrica, $datos);

    $jwt->setEncoder($simetricEncoder);

    $token = $jwt->encode();

    echo $token;
    // eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ1aWQiOjEyMzQ1NiwibmFtZSI6Im15IHVzZXIgbmFtZSJ9.RZcDtMfrzoVEISsVYsVz11-rZ87rWqS7RHYctQnpZKDt8m8YsVZysh9Hu0OpDnPT-8JjHbWS_Xkz6Am11UAulQ
  php
    $keySimetrica = 'test';

    $simetricDecoder = new SimetricDecoder(Util::ALG_HS512, $keySimetrica);

    $this->jwt->setDecoder($simetricDecoder);

    // con el token generado previamente...
    $data = $this->jwt->decode($token);

    echo $data->uid;     // 'id-usuario'

    echo $data->name;    // 'usuario de prueba'