-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebservice.php
More file actions
96 lines (82 loc) · 1.98 KB
/
Webservice.php
File metadata and controls
96 lines (82 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @author : Jakiboy
* @package : FloatPHP
* @subpackage : Kernel Component
* @version : 1.5.x
* @copyright : (c) 2018 - 2025 Jihad Sinnaour <[email protected]>
* @link : https://floatphp.com
* @license : MIT
*
* This file is a part of FloatPHP Framework.
*/
declare(strict_types=1);
namespace FloatPHP\Kernel;
class Webservice extends BaseController
{
/**
* Is HTTP authenticated (Basic).
*
* @access public
* @return bool
*/
public function isHttpAuthenticated() : bool
{
// Basic authentication
if ( $this->applyFilter('basic-auth', true) ) {
if ( $this->isBasicAuth() ) {
$user = $this->getBasicAuthUser();
$pswd = $this->getBasicAuthPwd();
// API authenticate override
$this->doAction('api-authenticate', [
'username' => $user,
'address' => $this->getServerIp(),
'method' => 'basic'
]);
if (
$user == $this->getApiUsername()
&& $pswd == $this->getApiPassword()
) {
return true;
}
}
}
// Bearer token authentication
if ( $this->applyFilter('bearer-auth', true) ) {
if ( ($token = $this->getBearerToken()) ) {
return $this->isGranted($token);
}
}
// Extra authentication
if ( $this->applyFilter('extra-auth', false) ) {
return $this->applyFilter('extra-authenticated', false);
}
return false;
}
/**
* Is HTTP granted (Token).
*
* @access protected
* @param string $token
* @return bool
*/
protected function isGranted(string $token) : bool
{
$access = $this->getAccessToken($token, $this->getSecret(true));
$user = $access['user'] ?? false;
$pswd = $access['pswd'] ?? false;
if ( $user && $pswd ) {
// API authenticate override
$this->doAction('api-authenticate', [
'username' => $user,
'address' => $this->getServerIp(),
'method' => 'token'
]);
// Match authentication
if ( $user == $this->getApiUsername() && $pswd == $this->getApiPassword() ) {
return true;
}
}
return false;
}
}