Skip to content

Commit

Permalink
Log api key even if authentication for method is turned off.
Browse files Browse the repository at this point in the history
  • Loading branch information
cernicc committed May 22, 2015
1 parent 565562e commit 42e44a1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Http/Controllers/ApiGuardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,32 @@ public function __construct()
$keyAuthentication = false;
}

if ($keyAuthentication === true) {
$key = $request->header(Config::get('apiguard.keyName', 'X-Authorization'));

$key = $request->header(Config::get('apiguard.keyName', 'X-Authorization'));
if (empty($key)) {
// Try getting the key from elsewhere
$key = Input::get(Config::get('apiguard.keyName', 'X-Authorization'));
}

if (empty($key)) {
// Try getting the key from elsewhere
$key = Input::get(Config::get('apiguard.keyName', 'X-Authorization'));
}
$apiKeyModel = App::make(Config::get('apiguard.model', 'Chrisbjr\ApiGuard\Models\ApiKey'));

if (!empty($key)) {
$this->apiKey = $apiKeyModel->getByKey($key);
}

if ($keyAuthentication === true) {

if (empty($key)) {
// It's still empty!
return $this->response->errorUnauthorized();
}

$apiKeyModel = App::make(Config::get('apiguard.model', 'Chrisbjr\ApiGuard\Models\ApiKey'));

if ( ! $apiKeyModel instanceof ApiKeyRepository) {
Log::error('[Chrisbjr/ApiGuard] You ApiKey model should be an instance of ApiKeyRepository.');
$exception = new Exception("You ApiKey model should be an instance of ApiKeyRepository.");
throw($exception);
}

$this->apiKey = $apiKeyModel->getByKey($key);

if (empty($this->apiKey)) {
return $this->response->errorUnauthorized();
}
Expand Down

0 comments on commit 42e44a1

Please sign in to comment.