Skip to content

Commit eeb59f2

Browse files
Merge pull request chrisbjr#94 from sashahilton00/master
Fix X-Authorization Error
2 parents d76e382 + 0d1a64a commit eeb59f2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Http/Middleware/ApiGuard.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,22 @@ public function handle($request, Closure $next, $serializedApiMethods=null)
192192

193193
// login User
194194
$headers = apache_request_headers();
195-
$api_key = $headers[Config::get('apiguard.keyName', 'X-Authorization')];
195+
//$api_key = $headers[Config::get('apiguard.keyName', 'X-Authorization')];
196+
197+
if (empty($headers[Config::get('apiguard.keyName', 'X-Authorization')])) {
198+
$api_key = null;
199+
} else {
200+
$api_key = $headers[Config::get('apiguard.keyName', 'X-Authorization')];
201+
}
202+
203+
if(!empty($api_key)) {
196204

197205
$user_id = App::make(Config::get('apiguard.model', 'Chrisbjr\ApiGuard\Models\ApiKey'))->where('key', $api_key)
198206
->pluck('user_id');
199207

200208
if($user_id !== 0)
201209
Auth::loginUsingId($user_id);
202-
210+
}
203211
return $next($request);
204212
}
205213
}

0 commit comments

Comments
 (0)