wyzen-packages / simple-jwt
create/check JWT token
v2.1.0
2023-10-16 14:41 UTC
Requires
- php: >=8.1
- lcobucci/jwt: ^5.0
- wyzen-packages/helper: ^1.6
Requires (Dev)
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^3.7
- symfony/var-dumper: ^6.3
This package is auto-updated.
Last update: 2024-12-17 09:12:54 UTC
README
Create/Verify JWT Token
Changelog
- Ajout de createDatetimeFromString : creation d'un DateTime depuis une date format String
- Ajout de removeNullValues : Suppression des champs à NULL d'un tableau
Tests
- Require : php 7.4 minimum
- use docker/composer.sh to use the correct release of php.
Import
composer require wyzen-packages/simple-jwt
Usage - Create token
use Wyzen\Php\SimpleJwt;
$jwt = new SimpleJwt([
'algo' => 'hmac_sha256',
'exp_interval' => 'PT2S',
'private_key' => '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
]);
$token = $jwt->createToken([
'claims1' => 'value1',
'claims2' => 'value2',
'claims3' => [
'data' => 'data claims 3',
],
]);
$jwtdata = $token->toString();
dd($jwtdata);
Usage - Check token
use Wyzen\Php\SimpleJwt;
$jwtdata = '....token_jwt....';
$jwt = new SimpleJwt([
'algo' => 'hmac_sha256',
]);
// Or set to options
$jwt->setPrivateKey('0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
/**
* ret = true or throw RequiredConstraintsViolated exception
*/
$ret = $jwt->check();
Liste des méthodes
- createToken
- getOptions
- setToken
- setPrivateKey
- check
- toString