PHP code example of veka-server / jwt

1. Go to this page and download the library: Download veka-server/jwt 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/ */

    

veka-server / jwt example snippets



        $data = ['id_user' =>555];

        /** @var VekaServer\JWT\JWT $jwt */
        $jwt = Container::getInstance()->get('JWT');
        $jwtToken = $jwt->getToken($data);

        $decoded = $jwt->decode($jwtToken);

        $retour = [
                "message" => "Successful login",
                "jwt" => $jwtToken,
                "expireAt" => $decoded->exp
        ];


// creation du dispatcher
$Dispatcher = new VekaServer\Dispatcher\Dispatcher();

// creer le jwt
$jwt = new \App\classe\JWT(
                  $private, // private_key
                  $public, // public_key
                  'localhost:8000', // iss
                  3600, // expire time token -- facultatif default = 3600
                  'RS256', // algorithm de chiffrement -- facultatif default = RS256
                  'localhost:8000', // aud -- facultatif default = iss
              );

// ajout le middlewares
$Dispatcher->pipe($jwt);