PHPackages                             yjj/tp-jwt-auth - 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. yjj/tp-jwt-auth

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

yjj/tp-jwt-auth
===============

thinkphp jwt auth composer

v1.6(6y ago)09[1 issues](https://github.com/yangjinjin2016/tp-jwt-auth/issues)MITPHPPHP &gt;=5.6

Since Sep 30Pushed 6y ago1 watchersCompare

[ Source](https://github.com/yangjinjin2016/tp-jwt-auth)[ Packagist](https://packagist.org/packages/yjj/tp-jwt-auth)[ RSS](/packages/yjj-tp-jwt-auth/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

JWT-AUTH

[](#jwt-auth)

 thinkphp的jwt（JSON Web Token）身份验证包。支持Header、Cookie、Param等多种传参方式。包含：验证、验证并且自动刷新等多种中间件。

新支持thinkphp6.0
--------------

[](#新支持thinkphp60)

环境要求
----

[](#环境要求)

1. php &gt;= 5.6
2. thinkphp ^5.1.10 || ^6.0.0

说明
--

[](#说明)

> 目前支持如下三大类型加密方式：RSA,HASH,DSA。再各分256、384、512位。 默认是HS256，即hash 256位加密。

> 需要修改加密方式，请修改参数：ALGO，参数选项：

- HS256 > 备注：hash 256位
- HS384 > 备注：hash 384位
- HS512 > 备注：hash 512位
- RS256 > 备注：rsa 256位
- RS384 > 备注：rsa 384位
- RS512 > 备注：rsa 512位
- ES256 > 备注：dsa 256位
- ES384 > 备注：dsa 384位
- ES512 > 备注：dsa 512位

> 重要：RSA和DSA 都是非对称加密方式，除了修改参数ALGO外，需要配置：PUBLIC\_KEY、PRIVATE\_KEY两个参数， 这两个参数支持文本（不要开头、结尾和换行）或密钥文件路径。如果密钥设置了密码，请配置好参数：PASSWORD

> env文件不支持内容有等于号，遇到这种情况： 1、使用路径 2、生成没有等于号的密钥。

安装
--

[](#安装)

第一步:

```
$ composer require yjj/tp-jwt-auth
```

第二步:

```
$ php think jwt:create
```

此举将生成jwt.php和.env配置文件。不推荐直接修改jwt.php 同时，env中会随机生成secret。请不要随意更新secret，也请保障secret安全。

使用方式
----

[](#使用方式)

对于需要验证的路由或者模块添加中间件：

```
 thans\jwt\middleware\JWTAuth::class,
```

示例：

```
use thans\jwt\facade\JWTAuth;

$token = JWTAuth::builder(['uid' => 1]);//参数为用户认证的信息，请自行添加

JWTAuth::auth();//token验证

JWTAuth::refresh();//刷新token，会将旧token加入黑名单

```

token刷新说明：

> token默认有效期为60秒，如果需要修改请修改env文件。 refresh\_ttl为刷新token有效期参数，单位为分钟。默认有效期14天。 token过期后，旧token将会被加入黑名单。 如果需要自动刷新，请使用中间件 thans\\jwt\\middleware\\JWTAuthAndRefresh::class, 自动刷新后会通过header返回，请保存好。（注意，此中间件过期后第一次访问正常，第二次进入黑名单。）

token传参方式如下：

- 将token加入到url中作为参数。键名为token
- 将token加入到cookie。键名为token
- 将token加入header，如下：Authorization:bearer token值
- 以上三种方式，任选其一即可。推荐加入header中。

参考与借鉴
-----

[](#参考与借鉴)

感谢
--

[](#感谢)

-Thans

- jwt-auth
- php
- lcobucci/jwt
- thinkphp

下一步
---

[](#下一步)

- 支持动态配置

License
-------

[](#license)

MIT

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Total

5

Last Release

2457d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18164742?v=4)[yangjinjin2016](/maintainers/yangjinjin2016)[@yangjinjin2016](https://github.com/yangjinjin2016)

---

Top Contributors

[![yangjinjin2016](https://avatars.githubusercontent.com/u/18164742?v=4)](https://github.com/yangjinjin2016 "yangjinjin2016 (13 commits)")

### Embed Badge

![Health badge](/badges/yjj-tp-jwt-auth/health.svg)

```
[![Health](https://phpackages.com/badges/yjj-tp-jwt-auth/health.svg)](https://phpackages.com/packages/yjj-tp-jwt-auth)
```

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k50.9M364](/packages/tymon-jwt-auth)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

83910.6M60](/packages/php-open-source-saver-jwt-auth)[scheb/2fa

Two-factor authentication for Symfony applications (please use scheb/2fa-bundle to install)

585665.9k1](/packages/scheb-2fa)[drenso/symfony-oidc-bundle

OpenID connect bundle for Symfony

95714.0k3](/packages/drenso-symfony-oidc-bundle)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1152.7M11](/packages/patrickbussmann-oauth2-apple)[socialiteproviders/apple

Apple OAuth2 Provider for Laravel Socialite

599.1M13](/packages/socialiteproviders-apple)

PHPackages © 2026

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