diff --git a/app/Console/Commands/TestApi.php b/app/Console/Commands/TestApi.php index 0e81e411..b80559c4 100644 --- a/app/Console/Commands/TestApi.php +++ b/app/Console/Commands/TestApi.php @@ -19,10 +19,12 @@ class TestApi extends BaseCommand $this->httpClient = new Client([ 'headers' => [ 'Authorization' => $this->argument('apikey'), + 'Content-type' => 'application/json', + 'X-API-Key' => $this->argument('apikey'), ] ]); $result = $this->httpClient->get($this->argument('url')); - print_r(\GuzzleHttp\json_decode($result->getBody())); + echo $result->getBody(); } } diff --git a/app/Http/Middleware/ApiAuth.php b/app/Http/Middleware/ApiAuth.php index ad4cc757..8e411b28 100644 --- a/app/Http/Middleware/ApiAuth.php +++ b/app/Http/Middleware/ApiAuth.php @@ -22,13 +22,15 @@ class ApiAuth public function handle($request, Closure $next) { // Check if Authorization header is in place - $auth = $request->header('Authorization', null); - if($auth === null) { - return $this->unauthorized('Authorization header missing'); + $api_key = $request->header('x-api-key', null); + if($api_key === null) { + $api_key = $request->header('Authorization', null); + if ($api_key === null) { + return $this->unauthorized('X-API-KEY header missing'); + } } // Try to find the user via API key. Cache this lookup - $api_key = $request->header('Authorization'); $user = User::where('api_key', $api_key)->first(); if($user === null) { return $this->unauthorized('User not found with key "'.$api_key.'"'); diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 8b8476a7..3e57889c 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -37,15 +37,15 @@ class ApiTest extends TestCase ->assertStatus(200) ->assertJson(['icao' => $airport->icao], true); - $this->withHeaders(['authorization' => 'testadminapikey'])->get($uri) + $this->withHeaders(['x-api-key' => 'testadminapikey'])->get($uri) ->assertStatus(200) ->assertJson(['icao' => $airport->icao], true); - $this->withHeaders(['AUTHORIZATION' => 'testadminapikey'])->get($uri) + $this->withHeaders(['x-API-key' => 'testadminapikey'])->get($uri) ->assertStatus(200) ->assertJson(['icao' => $airport->icao], true); - $this->withHeaders(['AuThOrIzAtIoN' => 'testadminapikey'])->get($uri) + $this->withHeaders(['X-API-KEY' => 'testadminapikey'])->get($uri) ->assertStatus(200) ->assertJson(['icao' => $airport->icao], true); }