lostinvlg/jwt
最新稳定版本:v1.0.0
Composer 安装命令:
composer require lostinvlg/jwt
包简介
Simple JWT Builder and Parser
README 文档
README
A simple library to encode and decode JWT tokens in PHP (conforming to RFC 7519)
Dependencies
- PHP 8.0+
- OpenSSL Extension
- firebase/php-jwt
Installation
composer require lostinvlg/jwt
Creating jwt
use Lostinvlg\Jwt\Algorithm; use Lostinvlg\Jwt\Jwt; use Lostinvlg\Jwt\Key; $jwtId = '1dA8dDQ5lE'; $time = time(); $jwt = new Jwt(); $token = $jwt ->getBuilder() ->setKey(new Key('YOUR_SECRET_KEY_STRING', Algorithm::HS256)) ->setIssuedBy('https://example.com') ->setAudience('https://example.com') ->setIssuedAt($time) ->setNotBefore($time + 10) ->setExpiresAt($time + 3600) ->setIdentifiedBy($jwtId) ->setClaim('user_id', 1) ->setClaim('role_id', 'admin') ->getToken(); $encoded = (string) $token; // contains jwt encoded string $token->getClaim('user_id'); // equals 1 $token->getClaim('role_id'); // equals "admin" $token->getClaim('exp'); // returns expires timestamp
Parsing from string
use Lostinvlg\Jwt\Algorithm; use Lostinvlg\Jwt\Jwt; use Lostinvlg\Jwt\Key; $jwt = new Jwt(); $token = $jwt->getParser(new Key('YOUR_SECRET_KEY_STRING', Algorithm::HS256))->parse($encoded); $token->getClaim('user_id'); // equals 1 $token->getClaim('role_id'); // equals "admin" $token->getClaim('exp'); // returns expires timestamp
License
统计信息
- 总下载量: 51
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-16