-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathClientRepository.php
More file actions
46 lines (36 loc) · 1.31 KB
/
ClientRepository.php
File metadata and controls
46 lines (36 loc) · 1.31 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
<?php
/**
* @author Ian Simpson <ian@iansimpson.nz>
* @copyright Copyright (c) Ian Simpson
*/
namespace IanSimpson\OAuth2\Repositories;
use IanSimpson\OAuth2\Entities\ClientEntity;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
class ClientRepository implements ClientRepositoryInterface
{
public function getClientEntity($clientIdentifier): ?ClientEntityInterface
{
$clients = ClientEntity::get()->filter([
'ClientIdentifier' => $clientIdentifier,
]);
/** @var ClientEntity|null $client */
$client = $clients->first();
if (!$client instanceof ClientEntity) {
return null;
}
$client->setConfidential();
return $client;
}
/**
* {@inheritDoc}
*/
public function validateClient($clientIdentifier, $clientSecret, $grantType = null): bool
{
$client = $this->getClientEntity($clientIdentifier);
// Validate the client secret and grant type
return $client instanceof ClientEntity && $client->ClientConfidential
&& $client->isSecretValid((string) $clientSecret)
&& $grantType === $client->ClientGrantType;
}
}