X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a7a97a53f1d7b9e180d9296cec02c42d0a987a89..refs/pull/2274/head:/app/Http/Middleware/ApiAuthenticate.php diff --git a/app/Http/Middleware/ApiAuthenticate.php b/app/Http/Middleware/ApiAuthenticate.php index 655334450..728057bed 100644 --- a/app/Http/Middleware/ApiAuthenticate.php +++ b/app/Http/Middleware/ApiAuthenticate.php @@ -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; }