|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OAuth\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use OAuth\Client; |
|
6
|
|
|
use Doctrine\ORM\EntityRepository; |
|
7
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
|
8
|
|
|
use League\OAuth2\Server\Repositories\ClientRepositoryInterface; |
|
9
|
|
|
|
|
10
|
|
|
class ClientRepository extends EntityRepository implements ClientRepositoryInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param string $clientIdentifier |
|
14
|
|
|
* @param string $grantType |
|
15
|
|
|
* @param null|string|null $clientSecret |
|
16
|
|
|
* @param bool $mustValidateSecret |
|
17
|
|
|
* |
|
18
|
|
|
* @return ClientEntityInterface|null |
|
19
|
|
|
*/ |
|
20
|
|
|
public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true) |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var Client $client */ |
|
23
|
|
|
$client = $this->findOneBy([ |
|
24
|
|
|
'identifier' => $clientIdentifier |
|
25
|
|
|
]); |
|
26
|
|
|
|
|
27
|
|
|
if ($client instanceof Client == false) { |
|
|
|
|
|
|
28
|
|
|
return null; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if ( |
|
32
|
|
|
$mustValidateSecret === true |
|
33
|
|
|
&& $client['is_confidential'] === true |
|
34
|
|
|
&& $clientSecret != $client->getSecret() |
|
35
|
|
|
) { |
|
36
|
|
|
return null; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $client; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param Client $client |
|
44
|
|
|
* @return Client |
|
45
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
46
|
|
|
*/ |
|
47
|
|
|
public function create(Client $client) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->_em->persist($client); |
|
50
|
|
|
$this->_em->flush($client); |
|
51
|
|
|
return $client; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param Client $client |
|
56
|
|
|
* @return Client |
|
57
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
58
|
|
|
*/ |
|
59
|
|
|
public function save(Client $client) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->_em->flush($client); |
|
62
|
|
|
return $client; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param Client $client |
|
67
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
68
|
|
|
*/ |
|
69
|
|
|
public function delete(Client $client) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->_em->remove($client); |
|
72
|
|
|
$this->_em->flush($client); |
|
73
|
|
|
} |
|
74
|
|
|
} |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.