From a7effcce7a4b164ae474f36e426b22de01af4920 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 18 Jun 2015 18:12:10 +0100 Subject: [PATCH] Fixed unauthorized exceptions --- app/Http/Middleware/Admin.php | 4 ++-- app/Http/Middleware/ApiAuthenticate.php | 8 ++++---- app/Http/Middleware/Authenticate.php | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Http/Middleware/Admin.php b/app/Http/Middleware/Admin.php index f2e56c8b..f989a008 100644 --- a/app/Http/Middleware/Admin.php +++ b/app/Http/Middleware/Admin.php @@ -13,7 +13,7 @@ namespace CachetHQ\Cachet\Http\Middleware; use Closure; use Illuminate\Contracts\Auth\Guard; -use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; class Admin { @@ -45,7 +45,7 @@ class Admin public function handle($request, Closure $next) { if (!$this->auth->check() || ($this->auth->check() && !$this->auth->user()->isAdmin)) { - throw new UnauthorizedHttpException(); + throw new HttpException(401); } return $next($request); diff --git a/app/Http/Middleware/ApiAuthenticate.php b/app/Http/Middleware/ApiAuthenticate.php index dc26807e..3a510506 100644 --- a/app/Http/Middleware/ApiAuthenticate.php +++ b/app/Http/Middleware/ApiAuthenticate.php @@ -15,7 +15,7 @@ use CachetHQ\Cachet\Models\User; use Closure; use Illuminate\Contracts\Auth\Guard; use Illuminate\Database\Eloquent\ModelNotFoundException; -use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; class ApiAuthenticate { @@ -51,14 +51,14 @@ class ApiAuthenticate try { $this->auth->onceUsingId(User::findByApiToken($apiToken)->id); } catch (ModelNotFoundException $e) { - throw new UnauthorizedHttpException(); + throw new HttpException(401); } } elseif ($request->getUser()) { if ($this->auth->onceBasic() !== null) { - throw new UnauthorizedHttpException(); + throw new HttpException(401); } } else { - throw new UnauthorizedHttpException(); + throw new HttpException(401); } } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 6922ed42..cc0513cc 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -13,7 +13,7 @@ namespace CachetHQ\Cachet\Http\Middleware; use Closure; use Illuminate\Contracts\Auth\Guard; -use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; class Authenticate { @@ -45,7 +45,7 @@ class Authenticate public function handle($request, Closure $next) { if ($this->auth->guest()) { - throw new UnauthorizedHttpException(); + throw new HttpException(401); } return $next($request);