|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Admin\Oauth2\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Admin\Oauth2\Entity\Client as Entity; |
|
8
|
|
|
use AbterPhp\Framework\Crypto\Crypto; |
|
9
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
|
|
|
|
|
|
10
|
|
|
use League\OAuth2\Server\Repositories\ClientRepositoryInterface; |
|
|
|
|
|
|
11
|
|
|
use Opulence\Databases\ConnectionPools\ConnectionPool; |
|
12
|
|
|
use Opulence\QueryBuilders\MySql\QueryBuilder; |
|
13
|
|
|
|
|
14
|
|
|
class Client implements ClientRepositoryInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var Crypto */ |
|
17
|
|
|
protected $crypto; |
|
18
|
|
|
|
|
19
|
|
|
/** @var ConnectionPool */ |
|
20
|
|
|
protected $connectionPool; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Client constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param Crypto $crypto |
|
26
|
|
|
* @param ConnectionPool $connectionPool |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(Crypto $crypto, ConnectionPool $connectionPool) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->crypto = $crypto; |
|
31
|
|
|
$this->connectionPool = $connectionPool; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $clientIdentifier |
|
38
|
|
|
* @param null $grantType |
|
|
|
|
|
|
39
|
|
|
* @param null $clientSecret |
|
|
|
|
|
|
40
|
|
|
* @param bool $mustValidateSecret |
|
41
|
|
|
* |
|
42
|
|
|
* @return ClientEntityInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getClientEntity( |
|
45
|
|
|
$clientIdentifier, |
|
46
|
|
|
$grantType = null, |
|
47
|
|
|
$clientSecret = null, |
|
48
|
|
|
$mustValidateSecret = true |
|
49
|
|
|
) { |
|
50
|
|
|
$clientData = $this->query($clientIdentifier); |
|
51
|
|
|
|
|
52
|
|
|
if (empty($clientData['secret'])) { |
|
53
|
|
|
return null; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$clientSecret = $this->crypto->prepareSecret($clientSecret); |
|
|
|
|
|
|
57
|
|
|
if (!$this->crypto->verifySecret($clientSecret, $clientData['secret'])) { |
|
58
|
|
|
return null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$client = new Entity($clientIdentifier, $clientIdentifier, ''); |
|
62
|
|
|
|
|
63
|
|
|
return $client; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $clientId |
|
68
|
|
|
* |
|
69
|
|
|
* @return array|bool |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function query(string $clientId) |
|
72
|
|
|
{ |
|
73
|
|
|
// TODO: Implement getClientEntity() method. |
|
74
|
|
|
$query = (new QueryBuilder()) |
|
75
|
|
|
->select('ac.secret') |
|
76
|
|
|
->from('api_clients', 'ac') |
|
77
|
|
|
->where('ac.deleted = 0') |
|
78
|
|
|
->andWhere('ac.id = :clientId'); |
|
79
|
|
|
|
|
80
|
|
|
$sql = $query->getSql(); |
|
81
|
|
|
$params = ['clientId' => $clientId]; |
|
82
|
|
|
|
|
83
|
|
|
$connection = $this->connectionPool->getReadConnection(); |
|
84
|
|
|
$statement = $connection->prepare($sql); |
|
85
|
|
|
$statement->bindValues($params); |
|
86
|
|
|
if (!$statement->execute()) { |
|
87
|
|
|
return false; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $statement->fetch(\PDO::FETCH_ASSOC); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths