|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OAuth\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
|
6
|
|
|
use Exception; |
|
7
|
|
|
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; |
|
8
|
|
|
use League\OAuth2\Server\Entities\ClientEntityInterface; |
|
9
|
|
|
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; |
|
10
|
|
|
use OAuth\AccessToken; |
|
11
|
|
|
|
|
12
|
|
|
class AccessTokenRepository extends EntityRepository implements AccessTokenRepositoryInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param AccessTokenEntityInterface $accessTokenEntity |
|
16
|
|
|
* @return AccessTokenEntityInterface |
|
17
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
18
|
|
|
*/ |
|
19
|
3 |
|
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity): AccessTokenEntityInterface |
|
20
|
|
|
{ |
|
21
|
3 |
|
$this->_em->persist($accessTokenEntity); |
|
22
|
3 |
|
$this->_em->flush(); |
|
23
|
3 |
|
return $accessTokenEntity; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param string $tokenId |
|
28
|
|
|
* @throws Exception |
|
29
|
|
|
*/ |
|
30
|
|
|
public function revokeAccessToken($tokenId) |
|
31
|
|
|
{ |
|
32
|
|
|
/** @var AccessToken $token */ |
|
33
|
|
|
$token = $this->find($tokenId); |
|
34
|
|
|
if(!$token) { |
|
|
|
|
|
|
35
|
|
|
throw new Exception('Token not found', 404); |
|
36
|
|
|
} |
|
37
|
|
|
$token->setRevoked(true); |
|
38
|
|
|
$this->_em->flush($token); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public function isAccessTokenRevoked($tokenId) |
|
45
|
|
|
{ |
|
46
|
|
|
/** @var null|AccessToken $token */ |
|
47
|
1 |
|
$token = $this->findOneBy(['identifier' => $tokenId]); |
|
48
|
1 |
|
if(!$token || $token->isRevoked()) { |
|
49
|
|
|
return true; |
|
50
|
|
|
} |
|
51
|
1 |
|
return false; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param ClientEntityInterface $clientEntity |
|
56
|
|
|
* @param array $scopes |
|
57
|
|
|
* @param null $userIdentifier |
|
|
|
|
|
|
58
|
|
|
* @return AccessTokenEntityInterface|AccessToken |
|
59
|
|
|
*/ |
|
60
|
3 |
|
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null): AccessToken |
|
61
|
|
|
{ |
|
62
|
3 |
|
$token = new AccessToken(); |
|
63
|
|
|
|
|
64
|
3 |
|
return $token; |
|
65
|
|
|
} |
|
66
|
|
|
} |