Loading src/Middleware/AuthorizeMiddleware.php +4 −3 Original line number Diff line number Diff line Loading @@ -23,10 +23,11 @@ class AuthorizeMiddleware implements MiddlewareInterface $route = $request->getUri()->getPath(); $token = token(); $applicationName = env('APP_NAME'); $method = $request->getMethod(); if (empty($route)) return $handler->handle($request); //获取对应的 route 对应的权限,如果 route 是不需要登录鉴权,直接返回 $passed = $this->authRouter($applicationName, $route, $token); $passed = $this->authRouter($applicationName, $route, $method, $token); if ($passed) { return $handler->handle($request); } Loading @@ -44,11 +45,11 @@ class AuthorizeMiddleware implements MiddlewareInterface * @param $token * @return bool */ protected function authRouter($applicationName, $route, $token): bool protected function authRouter($applicationName, $route, $method, $token): bool { $userId = $this->getUserIdByToken($token); return $this->authorizationService->authByRouter($applicationName, $route, $userId); return $this->authorizationService->authByRouter($applicationName, $route, $method, $userId); } Loading src/Service/Interfaces/User/AuthenticationServiceInterface.php +3 −2 Original line number Diff line number Diff line Loading @@ -31,11 +31,12 @@ interface AuthenticationServiceInterface /** * 获取对应路由的接口权限结果 * @param $router string 路由名字 * @param $path string 路由名字 * @param $applicationName string 应用名字 * @param $method string 请求方法 * @param $userId integer 用户 ID * @return bool */ public function authByRouter($applicationName, $router, $userId): bool; public function authByRouter($applicationName, $path, $method, $userId): bool; } Loading
src/Middleware/AuthorizeMiddleware.php +4 −3 Original line number Diff line number Diff line Loading @@ -23,10 +23,11 @@ class AuthorizeMiddleware implements MiddlewareInterface $route = $request->getUri()->getPath(); $token = token(); $applicationName = env('APP_NAME'); $method = $request->getMethod(); if (empty($route)) return $handler->handle($request); //获取对应的 route 对应的权限,如果 route 是不需要登录鉴权,直接返回 $passed = $this->authRouter($applicationName, $route, $token); $passed = $this->authRouter($applicationName, $route, $method, $token); if ($passed) { return $handler->handle($request); } Loading @@ -44,11 +45,11 @@ class AuthorizeMiddleware implements MiddlewareInterface * @param $token * @return bool */ protected function authRouter($applicationName, $route, $token): bool protected function authRouter($applicationName, $route, $method, $token): bool { $userId = $this->getUserIdByToken($token); return $this->authorizationService->authByRouter($applicationName, $route, $userId); return $this->authorizationService->authByRouter($applicationName, $route, $method, $userId); } Loading
src/Service/Interfaces/User/AuthenticationServiceInterface.php +3 −2 Original line number Diff line number Diff line Loading @@ -31,11 +31,12 @@ interface AuthenticationServiceInterface /** * 获取对应路由的接口权限结果 * @param $router string 路由名字 * @param $path string 路由名字 * @param $applicationName string 应用名字 * @param $method string 请求方法 * @param $userId integer 用户 ID * @return bool */ public function authByRouter($applicationName, $router, $userId): bool; public function authByRouter($applicationName, $path, $method, $userId): bool; }