forked from rchavik/oauth-server
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathClientRepository.php
More file actions
61 lines (50 loc) · 1.42 KB
/
ClientRepository.php
File metadata and controls
61 lines (50 loc) · 1.42 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
<?php
namespace OAuthServer\Bridge\Repository;
use Cake\Datasource\ModelAwareTrait;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use OAuthServer\Model\Entity\Client;
use OAuthServer\Model\Table\OauthClientsTable;
/**
* implemented ClientRepositoryInterface
*/
class ClientRepository implements ClientRepositoryInterface
{
use ModelAwareTrait;
/**
* @var OauthClientsTable
*/
private $table;
/**
* RefreshTokenRepository constructor.
*/
public function __construct()
{
$this->table = $this->loadModel('OAuthServer.OauthClients');
}
/**
* @inheritDoc
*/
public function getClientEntity($clientIdentifier)
{
return $this->table->find()->where([$this->table->getPrimaryKey() => $clientIdentifier])->first();
}
/**
* @inheritDoc
*/
public function validateClient($clientIdentifier, $clientSecret, $grantType)
{
$conditions = [
$this->table->getPrimaryKey() => $clientIdentifier,
];
$conditions[$this->table->aliasField('client_secret')] = (string)$clientSecret;
$client = $this->table->find()->where($conditions)->first();
/* @var $client Client|null */
if ($client === null) {
return false;
}
if ($grantType === null) {
return true;
}
return in_array($grantType, $client->grant_types, true);
}
}