浏览代码

Merge branch 'develop'

xielin 5 年之前
父节点
当前提交
4e11a7c79c
共有 2 个文件被更改,包括 11 次插入1 次删除
  1. 9 1
      app/Http/Middleware/JwtAuthMiddleware.php
  2. 2 0
      composer.json

+ 9 - 1
app/Http/Middleware/JwtAuthMiddleware.php

@@ -3,7 +3,7 @@
 namespace App\Http\Middleware;
 
 use Closure;
-use function FastRoute\TestFixtures\empty_options_cached;
+use Illuminate\Support\Facades\Redis;
 use Tymon\JWTAuth\Exceptions\JWTException;
 use Tymon\JWTAuth\Exceptions\TokenExpiredException;
 use Tymon\JWTAuth\Exceptions\TokenInvalidException;
@@ -31,6 +31,14 @@ class JwtAuthMiddleware
                 return response()->json($error);
             }
             $data = JWTAuth::decode($token)['user'];
+            //检测token是否存在黑名单中
+            if(Redis::zscore('blacklist_token', $token->get())){
+                $error = [
+                    'message' => 'token in blacklist',
+                    'code' => 401,
+                ];
+                return response()->json($error);
+            }
             if ($data->sign !== md5($data->uid . config('customer.jwt_secret'))) {
                 $error = [
                     'message' => 'request is not allow',

+ 2 - 0
composer.json

@@ -9,10 +9,12 @@
         "dingo/api": "^2.2",
         "doctrine/dbal": "^2.9",
         "hhxsv5/laravel-s": "~3.4.0",
+        "illuminate/redis": "^5.8",
         "jeroendesloovere/distance": "1.0.2.1",
         "junliuxian/ali-oss-storage": "~2.0",
         "laravel/lumen-framework": "5.8.*",
         "league/fractal": "^0.17.0",
+        "predis/predis": "^1.1",
         "tymon/jwt-auth": "1.0.0-rc.4.1",
         "multilinguals/apollo-client": "^0.1.2",
         "vlucas/phpdotenv": "^3.3"