]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Middleware/ApiAuthenticate.php
Decode HTML entities
[bookstack] / app / Http / Middleware / ApiAuthenticate.php
index 655334450f8d1cfac8a2efc148c337edcccf4cb3..728057bed175b42a880014b0ecfbd6c3962d2701 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace BookStack\Http\Middleware;
 
+use BookStack\Exceptions\ApiAuthException;
 use BookStack\Exceptions\UnauthorizedException;
 use Closure;
 use Illuminate\Http\Request;
@@ -34,8 +35,11 @@ class ApiAuthenticate
     {
         // Return if the user is already found to be signed in via session-based auth.
         // This is to make it easy to browser the API via browser after just logging into the system.
-        if (signedInUser()) {
+        if (signedInUser() || session()->isStarted()) {
             $this->ensureEmailConfirmedIfRequested();
+            if (!user()->can('access-api')) {
+                throw new ApiAuthException(trans('errors.api_user_no_api_permission'), 403);
+            }
             return;
         }