Giter Club home page Giter Club logo

thinkphp-auth's Introduction

thinkphp-auth

基于thinkphp6开发的一个JWT权限验证插件

使用方法

1. 安装

composer require cncoders/thinkphp-auth *

2. 配置文件

将安装包内的config/jwt.php复制到thinkphp配置目录

3. 异常处理

如果需要对异常处理成JSON接口可用的格式可以在app\ExceptionHandle.php增加相应的异常处理示例如下:


if ($e instanceof AutherException) {
	exit( json_encode(['code' => $e->getCode(), 'message' => $e->getMessage()]) );
}

4.使用示例:

路由使用 单独使用版本判断可以不用配置jwt

版本判断不支持路由缓存


<?php

use \think\facade\Route;

// 获取当前请求的版本号
$version = \think\facade\Request::header('version');

//实例化auth-api
$router = new \cncoders\auth\Router($version);

#包含的路由文件 必须放到非route目录下 可以市下面的其他目录内 会与TP内置的route冲突
$router->allows(['[<]1.0.0'])->includes(__DIR__ . '/version1/router.php');

$router->allows('[>=]1.0.1')->callback(function(){
    Route::rule('/auth', '/auth/index');
});

$router->boot('1.0.2', function(){
    Route::group(...);
});

auther使用

Auther::make()->token(); //生成TOKEN
Auther::make()->refreshToken(); //刷新TOKEN
AutherMiddleware中间件处理对鉴权的判断

thinkphp-auth's People

Contributors

cncoders avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.