Change header from Authorization to X-API-KEY to avoid Apache issues
This commit is contained in:
parent
41227d3fdb
commit
5e32bcc52d
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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.'"');
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user