1. Go to this page and download the library: Download little-apps/littlejwt 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/ */
little-apps / littlejwt example snippets
use LittleApps\LittleJWT\Facades\LittleJWT;
use LittleApps\LittleJWT\Build\Builder;
$jwt = LittleJWT::create(function (Builder $builder) {
$builder
// Adds claim 'abc' with value 'def' to header claims.
->abc('def', true)
// Adds claim 'ghi' with value 'klm' to payload claims.
->ghi('klm')
// Adds claim 'nop' with value 'qrs' to payload claims.
->nop('qrs', false);
});
$token = (string) $jwt;
// $token = "ey...";
use LittleApps\LittleJWT\Facades\LittleJWT;
use LittleApps\LittleJWT\Validation\Validator;
$token = "ey...";
$passes = LittleJWT::validateToken($token, function (Validator $validator) {
$validator
// Checks the value of the 'abc' claim in the header === (strictly equals) 'def'
->equals('abc', 'def', true, true)
// Checks the value of the 'ghi' claim in the payload == (equals) 'klm'
->equals('ghi', 'klm')
// Checks the value of the 'nop' claim in the payload === (strictly equals) 'qrs'
->equals('nop', 'qrs', true, false);
});
if ($passes) {
// JWT is valid.
} else {
// JWT is invalid.
}