From 07868ce321ebca535e4010d3b83e8899a3c9f6b8 Mon Sep 17 00:00:00 2001 From: chaerla <chelgchen@gmail.com> Date: Tue, 14 Nov 2023 11:41:12 +0700 Subject: [PATCH] fix: api key on headers --- src/clients/RestApi.php | 2 +- src/clients/SoapApi.php | 2 +- src/middlewares/ExternalServiceMiddleware.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/clients/RestApi.php b/src/clients/RestApi.php index 6268632..4985fbf 100644 --- a/src/clients/RestApi.php +++ b/src/clients/RestApi.php @@ -17,7 +17,7 @@ class RestApi // Set common options in the constructor $this->baseUrl = Application::$config['REST_API_URL']; - $apiKey = Application::$config['PHP_API_KEY']; + $apiKey = Application::$config['REST_API_KEY']; curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->ch, CURLOPT_HTTPHEADER, ['x-api-key: ' . $apiKey]); } diff --git a/src/clients/SoapApi.php b/src/clients/SoapApi.php index b3b09a5..7af98d0 100644 --- a/src/clients/SoapApi.php +++ b/src/clients/SoapApi.php @@ -17,7 +17,7 @@ class SoapApi $baseUrl = Application::$config['SOAP_BASE_URL']; $headers = array( "http" => array( - "header" => "x-api-key: " . Application::$config['PHP_API_KEY'] + "header" => "x-api-key: " . Application::$config['SOAP_API_KEY'] ) ); diff --git a/src/middlewares/ExternalServiceMiddleware.php b/src/middlewares/ExternalServiceMiddleware.php index b1af512..0b1a636 100644 --- a/src/middlewares/ExternalServiceMiddleware.php +++ b/src/middlewares/ExternalServiceMiddleware.php @@ -14,7 +14,7 @@ class ExternalServiceMiddleware extends Middleware { if(!isset($_SERVER['HTTP_X_API_KEY'])){ throw new UnauthorizedException($isView); } - if ($_SERVER['HTTP_X_API_KEY'] != Application::$config['SOAP_API_KEY'] && $_SERVER['HTTP_X_API_KEY'] != Application::$config['REST_API_KEY']) { + if ($_SERVER['HTTP_X_API_KEY'] != Application::$config['PHP_API_KEY']) { throw new UnauthorizedException($isView); } } -- GitLab