Skip to content

Commit 345031b

Browse files
authored
Merge pull request #29 from daycry/development
Fixes
2 parents 77e4bf3 + 18a5829 commit 345031b

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"daycry/settings": "^1.0",
1818
"daycry/relations": "^2.0",
1919
"daycry/jwt": "^1.0",
20-
"daycry/class-finder": "^2.0",
20+
"daycry/class-finder": "^2.2",
2121
"daycry/cronjob": "^2.0"
2222
},
2323
"require-dev":

src/RestServer.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ class RestServer extends ResourceController
114114
*/
115115
protected ?object $apiUser = null;
116116

117+
/**
118+
* Information about the current API user.
119+
*
120+
* @var string
121+
*/
122+
protected ?string $key = null;
123+
117124
/**
118125
* Information about the current AUTH user.
119126
*
@@ -275,7 +282,7 @@ protected function _logRequest($authorized = false)
275282
'uri' => $this->request->uri,
276283
'method' => $this->request->getMethod(),
277284
'params' => $params,
278-
'api_key' => isset($this->apiUser->key) ? $this->apiUser->key : '',
285+
'api_key' => isset($this->key) ? $this->key : '',
279286
'ip_address' => $this->request->getIPAddress(),
280287
'duration' => $this->_benchmark->getElapsedTime('petition'),
281288
'response_code' => $this->response->getStatusCode(),
@@ -340,7 +347,7 @@ public function _remap($method, ...$params)
340347
}
341348
}
342349

343-
$this->apiUser = \Daycry\RestServer\Validators\ApiKey::check($this->request, $this->_petition, $this->args);
350+
$this->apiUser = \Daycry\RestServer\Validators\ApiKey::check($this->request, $this->args, $this->_petition, $this->key);
344351

345352
if ($this->_restConfig->strictApiAndAuth && $this->apiUser instanceof \Exception) {
346353
throw $this->apiUser;

src/Validators/ApiKey.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class ApiKey
99
{
10-
public static function check(RequestInterface $request, object $petition = null, array $args): ?object
10+
public static function check(RequestInterface $request, array $args, object $petition = null, string &$key = null): ?object
1111
{
1212
$row = null;
1313
$usekey = config('RestServer')->restEnableKeys;
@@ -45,16 +45,18 @@ public static function check(RequestInterface $request, object $petition = null,
4545
if ($list_ip) {
4646
if (strpos($list_ip, '/') !== false) {
4747
//check IP is in the range
48-
$found_address = \Daycry\RestServer\Libraries\CheckIp::ipv4_in_range(trim($list_ip), $row->ip_addresses);
48+
$found_address = \Daycry\RestServer\Libraries\CheckIp::ipv4_in_range(trim($ip_address), trim($list_ip));
4949
} elseif ($ip_address === trim($list_ip)) {
5050
// there is a match, set the the value to TRUE and break out of the loop
5151
$found_address = true;
52+
}
53+
if ($found_address) {
5254
break;
5355
}
5456
}
5557
}
5658

57-
if (!$found_address) {
59+
if ($found_address !== true) {
5860
return UnauthorizedException::forIpDenied();
5961
}
6062
} else {

0 commit comments

Comments
 (0)