3 Star 3 Fork 0

梦中程序员 / tp-jwt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

tp6-jwt

thinkphp6的jwt身份验证包。目前仅支持header传参验证。

安装

composer require leruge/jwt

说明

  • 目前仅支持HS256算法加密。
  • 准备支持如下三大类型加密方式:RSA,HASH,DSA。再各分256、384、512位。 默认是HS256,即hash 256位加密。
  • 需要修改加密方式,请修改参数ALGO,参数选项:
    • HS256:hash256位
    • HS384:hash384位
    • HS512:hash512位
    • RS256:rsa256位
    • RS384:rsa384位
    • RS512:rsa512位
    • ES256:dsa256位
    • ES384:dsa384位
    • ES512:dsa512位

提示:RSA和DSA是非对称加密方式,除了修改ALGO参数外,需要配置public_key和private_key俩个参数。如果秘钥设置了密码,请配置好password参数。

使用方式

  1. builder方法,生成token字符串
$user = ['id' => 1];
$token = \leruge\facade\JWT::builder($user);
  1. validate方法,如果通过返回true,失败抛出异常
\leruge\facade\JWT::validate();
  1. auth方法,返回一个对象,可以数组式访问,token有效的时候可以获取正常的数据,无效的时候获取的都是空
$user = \leruge\facade\JWT::auth();
$uid = $user->id; // $user['id'];
  1. 可以使用中间件JWT,如果成功就进行下一步,失败则返回 ['code' =>0, 'msg' => '失败信息'] \leruge\middleware\JWT::class

传参方式

  • 将token加入header,如下Authorization:Bearer token
MIT License Copyright (c) 2020 leruge Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

thinkphp5.1的jwt(JSON Web Token)身份验证包。支持Header、Cookie、Param等多种传参方式。 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/sjclub/tp-jwt.git
git@gitee.com:sjclub/tp-jwt.git
sjclub
tp-jwt
tp-jwt
master

搜索帮助