jonlink / jwt
a tiny JWT package for php
v0.2.1
2024-09-22 04:13 UTC
Requires
- php: ^8.1
Requires (Dev)
- enlightn/security-checker: ^1.10
- mockery/mockery: ^1
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^10.0.0
- psy/psysh: ^0.11.18
- slevomat/coding-standard: ^8.10
- squizlabs/php_codesniffer: ^3.7
README
A tiny library for jwt auth with no dependencies.
installation
Install via packagist & composer:
composer require jonlink/jwt
usage
Create a new JWT and get the token:
$jwt = new JwtPhp(
payload: (object) ['foo' => 'bar'],
secret: 'abc',
);
echo $jwt->getToken();
Validate a JWT:
$jwt = new JwtPhp(
token: 123.abc.123,
secret: 'foo',
);
echo $jwt->isValid() ? 'this is valid' : 'this is NOT valid';
Update a supported (reserved) claim:
$jwt = new JwtPhp(
token: 123.abc.123,
secret: 'foo',
);
$jwt->setExpiration(123);
$jwt->setSupportedClaim('exp', 123);
Update a non-supported claim:
$jwt = new JwtPhp(
token: 123.abc.123,
secret: 'foo',
);
$jwt->setClaim('funnyClaim', 'hello world');