X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/9490457d044b51fbe330998ce37dcfe255038f55..refs/pull/4467/head:/app/Http/Middleware/ApiAuthenticate.php diff --git a/app/Http/Middleware/ApiAuthenticate.php b/app/Http/Middleware/ApiAuthenticate.php index 5d621ac11..b348473cf 100644 --- a/app/Http/Middleware/ApiAuthenticate.php +++ b/app/Http/Middleware/ApiAuthenticate.php @@ -3,7 +3,6 @@ namespace BookStack\Http\Middleware; use BookStack\Exceptions\ApiAuthException; -use BookStack\Exceptions\UnauthorizedException; use Closure; use Illuminate\Http\Request; @@ -11,15 +10,13 @@ class ApiAuthenticate { /** * Handle an incoming request. + * + * @throws ApiAuthException */ public function handle(Request $request, Closure $next) { // Validate the token and it's users API access - try { - $this->ensureAuthorizedBySessionOrToken(); - } catch (UnauthorizedException $exception) { - return $this->unauthorisedResponse($exception->getMessage(), $exception->getCode()); - } + $this->ensureAuthorizedBySessionOrToken(); return $next($request); } @@ -28,7 +25,7 @@ class ApiAuthenticate * Ensure the current user can access authenticated API routes, either via existing session * authentication or via API Token authentication. * - * @throws UnauthorizedException + * @throws ApiAuthException */ protected function ensureAuthorizedBySessionOrToken(): void { @@ -58,17 +55,4 @@ class ApiAuthenticate return $hasApiPermission && hasAppAccess(); } - - /** - * Provide a standard API unauthorised response. - */ - protected function unauthorisedResponse(string $message, int $code) - { - return response()->json([ - 'error' => [ - 'code' => $code, - 'message' => $message, - ], - ], $code); - } }