X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/3d11cba223cad16ad13faee010259e97b05dcee9..refs/pull/2023/head:/app/Api/ApiTokenGuard.php diff --git a/app/Api/ApiTokenGuard.php b/app/Api/ApiTokenGuard.php index ba0b4b5dd..e0a50ebe3 100644 --- a/app/Api/ApiTokenGuard.php +++ b/app/Api/ApiTokenGuard.php @@ -6,6 +6,7 @@ use BookStack\Exceptions\ApiAuthException; use Illuminate\Auth\GuardHelpers; use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\Guard; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Hash; use Symfony\Component\HttpFoundation\Request; @@ -125,6 +126,11 @@ class ApiTokenGuard implements Guard throw new ApiAuthException(trans('errors.api_incorrect_token_secret')); } + $now = Carbon::now(); + if ($token->expires_at <= $now) { + throw new ApiAuthException(trans('errors.api_user_token_expired'), 403); + } + if (!$token->user->can('access-api')) { throw new ApiAuthException(trans('errors.api_user_no_api_permission'), 403); }