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
|
|
|
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity): AccessTokenEntityInterface |
20
|
|
|
{ |
21
|
|
|
$this->_em->persist($accessTokenEntity); |
22
|
|
|
$this->_em->flush(); |
23
|
|
|
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
|
|
|
public function isAccessTokenRevoked($tokenId) |
45
|
|
|
{ |
46
|
|
|
/** @var null|AccessToken $token */ |
47
|
|
|
$token = $this->find($tokenId); |
48
|
|
|
if(!$token || $token->isRevoked()) { |
49
|
|
|
return true; |
50
|
|
|
} |
51
|
|
|
return false; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param ClientEntityInterface $clientEntity |
56
|
|
|
* @param array $scopes |
57
|
|
|
* @param null $userIdentifier |
|
|
|
|
58
|
|
|
* @return AccessTokenEntityInterface|AccessToken |
59
|
|
|
*/ |
60
|
|
|
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null): AccessToken |
61
|
|
|
{ |
62
|
|
|
$token = new AccessToken(); |
63
|
|
|
|
64
|
|
|
return $token; |
65
|
|
|
} |
66
|
|
|
} |