PHPackages                             irooit/simple-jwt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. irooit/simple-jwt

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

irooit/simple-jwt
=================

简单的 jwt 实现

v2.6.8(4y ago)0241Apache-2.0PHPPHP &gt;=7.1

Since May 28Pushed 4y agoCompare

[ Source](https://github.com/irooit/simple-jwt)[ Packagist](https://packagist.org/packages/irooit/simple-jwt)[ RSS](/packages/irooit-simple-jwt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (24)Used By (1)

simple-jwt
==========

[](#simple-jwt)

超简单的 jwt 实现。支持 Laravel、Hyperf 以及支持 composer 的其他框架

如何安装 ？
------

[](#如何安装-)

```
composer require irooit/simple-jwt
```

如何使用 ？
------

[](#如何使用-)

```
require 'vendor/autoload.php';

use Qbhy\SimpleJwt\JWTManager;
use Qbhy\SimpleJwt\JWT;
use Qbhy\SimpleJwt\Encoders;
use Qbhy\SimpleJwt\EncryptAdapters;
use Qbhy\SimpleJwt\Exceptions;

$secret = 'irooit/simple-jwt';

$headers = ['ver' => 0.1,];

$payload = [
    'user_id' => 'qbhy@gmail.com',
    'tester'  => 'qbhy',
];

// 可以使用自己实现的 encrypter 进行签名和校验，请继承自 AbstractEncrypter 抽象类
$encrypter = new EncryptAdapters\Md5Encrypter($secret);

// 可以使用自己实现的 encoder 进行编码，请实现 Encoder 接口
$encoder = new Encoders\Base64Encoder();
$cache = function(JWTManager $JWTManager){
return new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir());
};

// 实例化 jwt manager
$jwtManager = new JWTManager(compact('secret', 'encode','cache'));

// 设置 token 有效时间，单位 秒
$jwtManager->setTtl(60);
// 设置 token 过期后多久时间内允许刷新，单位 秒
$jwtManager->setRefreshTtl(120);

// 通过 jwt manager 实例化 jwt ，标准 jwt
$jwt0 = $jwtManager->make($payload, $headers);

// 生成 token，当然你也可以使用链式调用，例如:  $jwtManager->make($payload, $headers)->token()
$token = $jwt0->token();
print_r($token);

try {
// 通过 token 得到 jwt 对象
    $jwt1 = $jwtManager->parse($token);

    // 单纯解析，只判断签名是否正确，不判断时效性和黑名单
//    $jwt1 = $jwtManager->justParse($token);
} catch (Exceptions\TokenExpiredException $tokenExpiredException) {
    // 如果已经过期了，也可以尝试刷新此 jwt ,第二个参数如果为 true 将忽略 refresh ttl 检查
    $jwt1 = $jwtManager->refresh($tokenExpiredException->getJwt(), true);
}

// 得到 payload
$jwt1->getPayload();

// 得到 headers
$jwt1->getHeaders();

print_r($jwt1);

// 自己实例化 jwt ，完全纯净的 jwt ，无多余 payload
$jwt2 = new JWT($jwtManager, $headers, $payload);
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 83.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~49 days

Total

23

Last Release

1496d ago

Major Versions

0.0.5 → v1.0.02020-05-22

v1.4.2 → v2.6.82022-04-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ad3f906d2e98a353467f367677eacdaaf410f180db05d4d04c8a37d27a364d1?d=identicon)[irooit](/maintainers/irooit)

---

Top Contributors

[![qbhy](https://avatars.githubusercontent.com/u/24204533?v=4)](https://github.com/qbhy "qbhy (49 commits)")[![irooit](https://avatars.githubusercontent.com/u/42669741?v=4)](https://github.com/irooit "irooit (4 commits)")[![qbhy0715](https://avatars.githubusercontent.com/u/16954340?v=4)](https://github.com/qbhy0715 "qbhy0715 (4 commits)")[![ljyljy0211](https://avatars.githubusercontent.com/u/1272007?v=4)](https://github.com/ljyljy0211 "ljyljy0211 (1 commits)")[![lphkxd](https://avatars.githubusercontent.com/u/16346895?v=4)](https://github.com/lphkxd "lphkxd (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/irooit-simple-jwt/health.svg)

```
[![Health](https://phpackages.com/badges/irooit-simple-jwt/health.svg)](https://phpackages.com/packages/irooit-simple-jwt)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
