]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Middleware/ApiAuthenticate.php
Fixed OIDC Logout
[bookstack] / app / Http / Middleware / ApiAuthenticate.php
index 5d621ac119a22abf16c103d4cfc40dc617fcb5e8..b348473cf4d3dc40c1e353f1fb31c3b90e3c00de 100644 (file)
@@ -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);
-    }
 }