Auth to API v1 using Authorization: Api-Key header

This commit is contained in:
jo 2021-09-15 14:56:14 +02:00
parent b9bfa618a6
commit 512c67b1a6
1 changed files with 12 additions and 2 deletions

View File

@ -83,9 +83,19 @@ class ApiController extends Zend_Controller_Action
public function checkAuth() public function checkAuth()
{ {
$CC_CONFIG = Config::getConfig(); $CC_CONFIG = Config::getConfig();
$api_key = $this->_getParam('api_key'); $apiKey = $this->_getParam('api_key');
if (in_array($api_key, $CC_CONFIG["apiKey"])) { if (in_array($apiKey, $CC_CONFIG['apiKey'])) {
return true;
}
$authHeader = $this->getRequest()->getHeader('Authorization');
$authHeaderArray = explode(' ', $authHeader);
if (
count($authHeaderArray) >= 2
&& $authHeaderArray[0] == 'Api-Key'
&& in_array($authHeaderArray[1], $CC_CONFIG['apiKey'])
) {
return true; return true;
} }