sky-web-dev/jwt
最新稳定版本:1.0.1
Composer 安装命令:
composer require sky-web-dev/jwt
包简介
A library for JWT manipulation
README 文档
README
Introduction
Installation
composer require sky-web-dev/jwt
Single Type Use
// Create a token by RSA256 algorithm $pemKey = 'full-path/private-key.pem'; $time = 60*60; // number of seconds $jwt = JwtInit::init($pemKey, $time, JwtAlgorithm::RSA256); $token = $jwt->generateToken(['id' => 22, 'name' => 'John Ben']); // Create a token by SHA256 algorithm $time = 60*60; // number of seconds $secretKey = 'htugjgldiufd'; $jwt = JwtInit::init($secretKey, $time); $token = $jwt->generateToken(['id' => 22, 'name' => 'John Ben']); // Decode tokens $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwibmFtZSI6IlBldGFyIiwiZXhwIjoxNzQyODUwNDc2fQ.o5y2tT_TzFuNGMAy3anOxHROmhnXfbtsangECjUbumM'; $time = 60*60; // number of seconds $secretKey = 'htugjgldiufd'; $jwt = JwtInit::init($secretKey, $time); $jwt->decodeToken($token); $status = $jwt->getTokenStatus(); $payload = $jwt->getTokenPayloadData();
Validate token
$token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwibmFtZSI6IlBldGFyIiwiZXhwIjoxNzQyODUwNDc2fQ.o5y2tT_TzFuNGMAy3anOxHROmhnXfbtsangECjUbumM'; $time = 60*60; // number of seconds $secretKey = 'htugjgldiufd'; $jwt = JwtInit::init($secretKey, $time); $jwt->decodeToken($token); $status = $jwt->getTokenStatus(); if ($status == JwtStatus::TOKEN_STATUS_OK) { // Token is valid } if ($status == JwtStatus::TOKEN_STATUS_EXPIRED) { // Token expired } if ($status == JwtStatus::TOKEN_STATUS_INVALID) { // Token is invalid }
Available Algorithms
| Algorithm | Description |
|---|---|
| JwtAlgorithm::SHA256 | Generate JWT using sha256 algorithm |
| JwtAlgorithm::RSA256 | Generate JWT using RSA encryption |
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-25