Download the PHP package mzh/hyperf-jwt without Composer
On this page you can find all versions of the php package mzh/hyperf-jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package hyperf-jwt
基于Hyperf(https://doc.hyperf.io/#/zh/README) 框架的 jwt 鉴权
思路来源与 (https://github.com/phper666/jwt-auth)组件
重构sso单点登录token失效逻辑
说明:
hyperf-jwt
支持单点登录、多点登录、支持注销 token(token会失效)、支持refresh换取新token 失效老token单点登录:只会有一个 token 生效,一旦刷新 token ,前面生成的 token 都会失效,一般以用户 id 来做区分
多点登录:token 不做限制
单点登录原理:token版本号,
JWT
单点登录必须用到 aud(接收方) 默认字段,aud
字段的值默认为用户 id。当生成 token 时,会更新白名单uid的key值为当前的版本号,但是如果是调用refreshToken
来刷新 token 或者调用logout
注销token,默认前面生成的 token 都会失效。
如果开启单点登录模式,每次验证时候会查询当前uid的对应key是否和当前的版本号对应多点登录原理:暂未实现
token 不做限制原理:token 不做限制,在 token 有效的时间内都能使用
使用:
1、安装依赖
2、发布配置
3、jwt配置
去配置 config/autoload/jwt.php
文件或者在配置文件 .env
里配置
更多的配置请到 config/autoload/jwt.php
查看
4、模拟登录获取token
注意:支持传入用户对象获取 token,支持token类型,
5、使用例子参考 https://github.com/lphkxd/hyperf-admin
6、建议
目前
jwt
抛出的异常目前有两种类型Mzh\JwtAuth\Exception\TokenValidException
和Mzh\JwtAuth\Exception\JWTException,TokenValidException
异常为 token 验证失败的异常,会抛出401
,JWTException
异常会抛出500
,最好你们自己在项目异常重新返回错误信息
All versions of hyperf-jwt with dependencies
ext-swoole Version >=4.5
hyperf/config Version ~2.0.0
hyperf/utils Version ~2.0.0
hyperf/framework Version ~2.0.0
hyperf/di Version ~2.0.0
ext-json Version *
ext-redis Version *