bitterbyter / jwt
A simple library to sign and verify JWT.
dev-main
2023-08-24 10:24 UTC
Requires
- php: ^8.1
- nesbot/carbon: ^2.6
README
Note : This package uses HS256 algorithm only.
Usage
Requires a 256 bit secret key, needs to be generated manually.
$secret = 'x31thQ9QO0mZb1dKq6uejr9g7YE1uMwf';
Signing a token
$data = [ 'name' => 'John Doe', 'exp' => '1655683200' ]; $token = JWT::sign($data, $secret);
exp
claim in the payload should be an epoch timestamp.
Verifying a token
try { $payload = JWT::verify($token, $secret); } catch (InvalidTokenException $e) { // ... }
If the token is valid, payload of the token is returned.
InvalidTokenException
is thrown if the token is invalid or expired.