From 275c8abdade0c3b036a16cfa9ef611c25b60a7c0 Mon Sep 17 00:00:00 2001 From: Sasha Hilton Date: Mon, 8 Feb 2016 19:59:20 +0000 Subject: [PATCH 1/2] Fix X-Authorization Error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes (hopefully) the error: Undefined index: X-Authorization that was presented when the X-Authorization header wasn’t present, or was empty. --- src/Http/Middleware/ApiGuard.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Http/Middleware/ApiGuard.php b/src/Http/Middleware/ApiGuard.php index fb03bb9a3..ccaa0a436 100644 --- a/src/Http/Middleware/ApiGuard.php +++ b/src/Http/Middleware/ApiGuard.php @@ -192,7 +192,15 @@ public function handle($request, Closure $next, $serializedApiMethods=null) // login User $headers = apache_request_headers(); - $api_key = $headers[Config::get('apiguard.keyName', 'X-Authorization')]; + //$api_key = $headers[Config::get('apiguard.keyName', 'X-Authorization')]; + + if (empty($headers[Config::get('apiguard.keyName', 'X-Authorization')])) { + $api_key = null; + } else { + $api_key = $headers[Config::get('apiguard.keyName', 'X-Authorization')]; + } + + if(!empty($api_key)) { $user_id = App::make(Config::get('apiguard.model', 'Chrisbjr\ApiGuard\Models\ApiKey'))->where('key', $api_key) ->pluck('user_id'); @@ -201,5 +209,6 @@ public function handle($request, Closure $next, $serializedApiMethods=null) Auth::loginUsingId($user_id); return $next($request); + } } } From 0d1a64a4fb1f2339d52e3cf0f992cc388fcd51f0 Mon Sep 17 00:00:00 2001 From: Sasha Hilton Date: Mon, 8 Feb 2016 20:08:51 +0000 Subject: [PATCH 2/2] Fixed accidental $next in conditional statement. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $next($request) shouldn’t be conditional, otherwise the response will be blank. --- src/Http/Middleware/ApiGuard.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Http/Middleware/ApiGuard.php b/src/Http/Middleware/ApiGuard.php index ccaa0a436..1279d6779 100644 --- a/src/Http/Middleware/ApiGuard.php +++ b/src/Http/Middleware/ApiGuard.php @@ -207,8 +207,7 @@ public function handle($request, Closure $next, $serializedApiMethods=null) if($user_id !== 0) Auth::loginUsingId($user_id); - - return $next($request); } + return $next($request); } }