|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace rhertogh\Yii2Oauth2Server\components\repositories; |
|
4
|
|
|
|
|
5
|
|
|
use rhertogh\Yii2Oauth2Server\components\repositories\base\Oauth2BaseRepository; |
|
6
|
|
|
use rhertogh\Yii2Oauth2Server\components\repositories\traits\Oauth2ModelRepositoryTrait; |
|
7
|
|
|
use rhertogh\Yii2Oauth2Server\helpers\DiHelper; |
|
8
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\Oauth2ClientRepositoryInterface; |
|
9
|
|
|
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2ClientInterface; |
|
10
|
|
|
use yii\base\InvalidConfigException; |
|
11
|
|
|
|
|
12
|
|
|
class Oauth2ClientRepository extends Oauth2BaseRepository implements Oauth2ClientRepositoryInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use Oauth2ModelRepositoryTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @inheritDoc |
|
18
|
|
|
* @return class-string<Oauth2ClientInterface> |
|
|
|
|
|
|
19
|
|
|
*/ |
|
20
|
12 |
|
public function getModelClass() |
|
21
|
|
|
{ |
|
22
|
12 |
|
return Oauth2ClientInterface::class; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @inheritDoc |
|
27
|
|
|
* @throws InvalidConfigException |
|
28
|
|
|
*/ |
|
29
|
5 |
|
public function getClientEntity($clientIdentifier) |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var Oauth2ClientInterface $client */ |
|
32
|
5 |
|
$client = $this->findModelByIdentifier($clientIdentifier); |
|
33
|
5 |
|
if ($client) { |
|
|
|
|
|
|
34
|
4 |
|
$client->setRedirectUriEnvVarConfig($this->_module->clientRedirectUriEnvVarConfig); |
|
35
|
|
|
} |
|
36
|
5 |
|
return $client; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritDoc |
|
41
|
|
|
*/ |
|
42
|
7 |
|
public function validateClient($clientIdentifier, $clientSecret, $grantType) |
|
43
|
|
|
{ |
|
44
|
|
|
/** @var Oauth2ClientInterface $client */ |
|
45
|
7 |
|
$client = $this->findModelByIdentifier($clientIdentifier); |
|
46
|
|
|
|
|
47
|
|
|
if ( |
|
48
|
7 |
|
$client |
|
49
|
7 |
|
&& $client->isEnabled() |
|
50
|
7 |
|
&& $client->validateGrantType($grantType) |
|
51
|
7 |
|
&& (!$client->isConfidential() || $client->validateSecret($clientSecret, $this->_module->getCryptographer())) |
|
|
|
|
|
|
52
|
|
|
) { |
|
53
|
3 |
|
return true; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
4 |
|
return false; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getAllClients($filter = []) |
|
60
|
|
|
{ |
|
61
|
|
|
$class = $this->getModelClass(); |
|
62
|
|
|
/** @var class-string<Oauth2ClientInterface> $className */ |
|
63
|
|
|
$className = DiHelper::getValidatedClassName($class); |
|
64
|
|
|
|
|
65
|
|
|
return $className::find() |
|
66
|
|
|
->andFilterWhere($filter) |
|
67
|
|
|
->all(); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|