imemento / jwt
Custom JWT logic
Installs: 2 958
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- firebase/php-jwt: ^5.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-26 21:40:03 UTC
README
A custom JWT Wrapper to be used in iMemento projects. It uses the RS256 algorithm and it is framework independent.
Install
composer require imemento/jwt
Usage
use iMemento\JWT\JWT;
Encoding
To encode a JWT just use the encode
static method:
/** * $payload object/array * $privateKey mixed the key used to sign the token */ $token = JWT::encode($payload, $private_key);
Decoding
To decode a JWT we must follow the next steps.
-
Instantiate the class with the token we want to decode:
$jwt = new JWT($token);
-
Get the issuer before checking the signature (used to find the correct public key):
$issuer = $jwt->getIssuer();
-
Get the payload and check the signature at the same time:
$payload = $jwt->decode($public_key);
Additional Classes
Guard.php - Decrypts the token and is used to extract the permissions from it.
Issuer.php - Represents the current application.
Payload.php - Is used to create a standard payload for the JWT.