All Projects → QThans → jwt-auth

QThans / jwt-auth

Licence: MIT license
JSON Web Token Authentication for Thinkphp

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to jwt-auth

Nonecms
基于thinkphp5.1 的内容管理系统,可快速搭建博客、企业站;并且增加了实时聊天室
Stars: ✭ 261 (+130.97%)
Mutual labels:  thinkphp, thinkphp5
Thinkadmin
基于 ThinkPHP 基础开发平台(登录账号密码都是 admin )
Stars: ✭ 1,938 (+1615.04%)
Mutual labels:  thinkphp, thinkphp5
Uniadmin
UniAdmin是一套渐进式模块化开源后台,采用前后端分离技术,数据交互采用json格式,功能低耦合高内聚;核心模块支持系统设置、权限管理、用户管理、菜单管理、API管理等功能,后期上线模块商城将打造类似composer、npm的开放式插件市场;同时我们将打造一套兼容性的API标准,从ThinkPHP5.1+Vue2开始,逐步吸引爱好者共同加入,以覆盖larval、spring-boot、django、yii、koa、react等多语言框架。
Stars: ✭ 277 (+145.13%)
Mutual labels:  thinkphp, thinkphp5
say-love-wall
💖 由ThinkPHP5框架开发即开箱可用的告白墙、校园表白墙。表白可以通过发送邮箱告知对方,也可以分享表白内容。更多趣味查看 README.md 或网站。
Stars: ✭ 32 (-71.68%)
Mutual labels:  thinkphp, thinkphp5
Leacmf
leacmf是一款基于ThinkPHP5.1+layui的极速后台和api开发框架。
Stars: ✭ 244 (+115.93%)
Mutual labels:  auth, thinkphp5
Wemall
wemall7 开源版本 (不含商城)
Stars: ✭ 315 (+178.76%)
Mutual labels:  thinkphp, thinkphp5
Lyadmin
lyadmin是一套轻量级通用后台,采用ThinkPHP+Bootstrap3制作,内置系统设置、上传管理、权限管理、模块管理、插件管理等功能,独有的Builder页面自动生成技术节省50%开发成本,先进的模块化开发的支持让开发成本一降再降,致力于为个人和中小型企业打造全方位的PHP企业级开发解决方案。另外提供整套企业开发解决方案,集PC、手机、微信、App、小程序五端于一体,更有用户中心模块、门户模块、钱包支付中心模块、商城模块、OAuth2统一登陆、内部Git模块、Docker模块可供选择。
Stars: ✭ 1,066 (+843.36%)
Mutual labels:  thinkphp, thinkphp5
kauth
🔑 kauth is JWT API Authentication ( jwt-auth ) for laravel
Stars: ✭ 14 (-87.61%)
Mutual labels:  auth, jwt-auth
Lara Vue Auth
A repo for laravel vue authentication tutorial.
Stars: ✭ 54 (-52.21%)
Mutual labels:  auth, jwt-auth
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (+182.3%)
Mutual labels:  auth, jwt-auth
think-redisd
thinkphp 5 redis读写分离驱动
Stars: ✭ 24 (-78.76%)
Mutual labels:  thinkphp, thinkphp5
lake-admin
lake-admin是一款基于ThinkPHP6和Layui的后台开发框架。
Stars: ✭ 28 (-75.22%)
Mutual labels:  thinkphp, thinkphp5
think-permission
ThinkPHP 6 权限认证
Stars: ✭ 32 (-71.68%)
Mutual labels:  thinkphp, thinkphp5
react-auth-kit
Easily manage Authentication state of users in React-based Apps using Hooks and Higher-order components
Stars: ✭ 177 (+56.64%)
Mutual labels:  auth
TwitchAuth
Unreal Engine 4 Plugin for In-Game Twitch Authentication.
Stars: ✭ 21 (-81.42%)
Mutual labels:  auth
PiggyAuth
Safe & feature-rich auth plugin. Project has been discontinued
Stars: ✭ 33 (-70.8%)
Mutual labels:  auth
worker-auth-providers
worker-auth-providers is an open-source providers to make authentication easy with workers. Very lightweight script which doesn't need a lot of dependencies. Plug it with any framework or template of workers.
Stars: ✭ 85 (-24.78%)
Mutual labels:  auth
capacitor-firebase-authentication
⚡️ Capacitor plugin for Firebase Authentication.
Stars: ✭ 67 (-40.71%)
Mutual labels:  auth
svelte-commerce
Svelte ecommerce - Headless, Authentication, Cart & Checkout, TailwindCSS, Server Rendered, Proxy + API Integrated, Animations, Stores, Lazy Loading, Loading Indicators, Carousel, Instant Search, Faceted Filters, Typescript, Open Source, MIT license. 1 command deploy to your own server, 1 click deploy to netlify.
Stars: ✭ 695 (+515.04%)
Mutual labels:  auth
sqlx-adapter
Asynchronous casbin adapter for mysql, postgres, sqlite based on sqlx-rs
Stars: ✭ 27 (-76.11%)
Mutual labels:  auth

JWT-AUTH

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

thinkphp6.0的demo下载

支持Swoole

环境要求

  1. php ^7.0 || ^8.0
  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 thans/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加入黑名单

$tokenStr = JWTAuth::token()->get(); //可以获取请求中的完整token字符串

$payload = JWTAuth::auth(); //可验证token, 并获取token中的payload部分
$uid = $payload['uid']->getValue(); //可以继而获取payload里自定义的字段,比如uid

token刷新说明:

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

token传参方式如下:

可通过jwt.php配置文件内token_mode参数来调整参数接收方式及优先级 token_mode默认值为['header', 'cookie', 'param'];

在某些前后端分离的情况下可选择取消cookie接收方式来避免token冲突

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

其他操作

  1. 拉黑Token JWTAuth::invalidate($token);
  2. 查询Token是否黑名单 JWTAuth::validate($token);

常见问题

  • 使用RSA256方式的时候,请使用文本形式。如下:

image

联系&打赏

打赏名单

image

参考与借鉴

https://github.com/tymondesigns/jwt-auth

感谢

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

下一步

  • 支持动态配置

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].