Merge pull request #1346 from jooola/feat/allow_api_v1_headers_key_auth

Auth to API v1 using Authorization: Api-Key header
This commit is contained in:
Kyle Robbertze 2021-09-15 13:35:57 +00:00 committed by GitHub
commit f722d1a134
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -83,9 +83,19 @@ class ApiController extends Zend_Controller_Action
public function checkAuth()
{
$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;
}