码云地址:https://gitee.com/thans/jwt-auth
使用方式
对于需要验证的路由或者模块添加中间件:
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中。