imemento / jwt
自定义JWT逻辑
v8.1.0
2021-07-25 08:47 UTC
Requires
- php: ^8.0
- firebase/php-jwt: ^5.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-08-26 21:17:26 UTC
README
A custom JWT Wrapper to be used in iMemento projects. It uses the RS256 algorithm and it is framework independent.
安装
composer require imemento/jwt
使用方法
use iMemento\JWT\JWT;
编码
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);
解码
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.