|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
|
9
|
|
|
* |
|
10
|
|
|
* This software may be modified and distributed under the terms |
|
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Bundle\Tests\TestBundle\Entity; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCode; |
|
17
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeId; |
|
18
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeRepository as AuthorizationCodeRepositoryInterface; |
|
19
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
|
20
|
|
|
use OAuth2Framework\Component\Core\DataBag\DataBag; |
|
21
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
|
22
|
|
|
|
|
23
|
|
|
class AuthorizationCodeRepository implements AuthorizationCodeRepositoryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var AuthorizationCode[] |
|
27
|
|
|
*/ |
|
28
|
|
|
private $authorizationCodes = []; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->initAuthorizationCodes(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function find(AuthorizationCodeId $authCodeId): ? AuthorizationCode |
|
39
|
|
|
{ |
|
40
|
|
|
return array_key_exists($authCodeId->getValue(), $this->authorizationCodes) ? $this->authorizationCodes[$authCodeId->getValue()] : null; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param AuthorizationCode $authCode |
|
45
|
|
|
*/ |
|
46
|
|
|
public function save(AuthorizationCode $authCode) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->authorizationCodes[$authCode->getTokenId()->getValue()] = $authCode; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
private function initAuthorizationCodes() |
|
52
|
|
|
{ |
|
53
|
|
|
$refreshToken = AuthorizationCode::createEmpty(); |
|
54
|
|
|
$refreshToken = $refreshToken->create( |
|
55
|
|
|
AuthorizationCodeId::create('VALID_AUTHORIZATION_CODE'), |
|
56
|
|
|
ClientId::create('CLIENT_ID_3'), |
|
57
|
|
|
UserAccountId::create('john.1'), |
|
58
|
|
|
[], |
|
59
|
|
|
'http://localhost/callback', |
|
60
|
|
|
new \DateTimeImmutable('now +1 day'), |
|
61
|
|
|
DataBag::create([]), |
|
62
|
|
|
DataBag::create([]), |
|
63
|
|
|
null |
|
64
|
|
|
); |
|
65
|
|
|
$refreshToken->eraseMessages(); |
|
66
|
|
|
$this->save($refreshToken); |
|
67
|
|
|
|
|
68
|
|
|
$refreshToken = AuthorizationCode::createEmpty(); |
|
69
|
|
|
$refreshToken = $refreshToken->create( |
|
70
|
|
|
AuthorizationCodeId::create('REVOKED_AUTHORIZATION_CODE'), |
|
71
|
|
|
ClientId::create('CLIENT_ID_3'), |
|
72
|
|
|
UserAccountId::create('john.1'), |
|
73
|
|
|
[], |
|
74
|
|
|
'http://localhost/callback', |
|
75
|
|
|
new \DateTimeImmutable('now +1 day'), |
|
76
|
|
|
DataBag::create([]), |
|
77
|
|
|
DataBag::create([]), |
|
78
|
|
|
null |
|
79
|
|
|
); |
|
80
|
|
|
$refreshToken = $refreshToken->markAsRevoked(); |
|
81
|
|
|
$refreshToken->eraseMessages(); |
|
82
|
|
|
$this->save($refreshToken); |
|
83
|
|
|
|
|
84
|
|
|
$refreshToken = AuthorizationCode::createEmpty(); |
|
85
|
|
|
$refreshToken = $refreshToken->create( |
|
86
|
|
|
AuthorizationCodeId::create('EXPIRED_AUTHORIZATION_CODE'), |
|
87
|
|
|
ClientId::create('CLIENT_ID_3'), |
|
88
|
|
|
UserAccountId::create('john.1'), |
|
89
|
|
|
[], |
|
90
|
|
|
'http://localhost/callback', |
|
91
|
|
|
new \DateTimeImmutable('now -1 day'), |
|
92
|
|
|
DataBag::create([]), |
|
93
|
|
|
DataBag::create([]), |
|
94
|
|
|
null |
|
95
|
|
|
); |
|
96
|
|
|
$refreshToken->eraseMessages(); |
|
97
|
|
|
$this->save($refreshToken); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|