|
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\ClientRegistrationEndpoint\InitialAccessToken; |
|
17
|
|
|
use OAuth2Framework\Component\ClientRegistrationEndpoint\InitialAccessTokenId; |
|
18
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
|
19
|
|
|
|
|
20
|
|
|
class InitialAccessTokenRepository implements \OAuth2Framework\Component\ClientRegistrationEndpoint\InitialAccessTokenRepository |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var InitialAccessToken[] |
|
24
|
|
|
*/ |
|
25
|
|
|
private $initialAccessTokens = []; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->createInitialAccessTokens(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function find(InitialAccessTokenId $initialAccessTokenId): ? InitialAccessToken |
|
36
|
|
|
{ |
|
37
|
|
|
return array_key_exists($initialAccessTokenId->getValue(), $this->initialAccessTokens) ? $this->initialAccessTokens[$initialAccessTokenId->getValue()] : null; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function save(InitialAccessToken $initialAccessToken) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->initialAccessTokens[$initialAccessToken->getTokenId()->getValue()] = $initialAccessToken; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
private function createInitialAccessTokens() |
|
49
|
|
|
{ |
|
50
|
|
|
$iat = InitialAccessToken::createEmpty(); |
|
51
|
|
|
$iat = $iat->create( |
|
52
|
|
|
InitialAccessTokenId::create('VALID_INITIAL_ACCESS_TOKEN_ID'), |
|
53
|
|
|
UserAccountId::create('john.1'), |
|
54
|
|
|
new \DateTimeImmutable('now +1 day') |
|
55
|
|
|
); |
|
56
|
|
|
$iat->eraseMessages(); |
|
57
|
|
|
$this->save($iat); |
|
58
|
|
|
|
|
59
|
|
|
$iat = InitialAccessToken::createEmpty(); |
|
60
|
|
|
$iat = $iat->create( |
|
61
|
|
|
InitialAccessTokenId::create('EXPIRED_INITIAL_ACCESS_TOKEN_ID'), |
|
62
|
|
|
UserAccountId::create('john.1'), |
|
63
|
|
|
new \DateTimeImmutable('now -1 day') |
|
64
|
|
|
); |
|
65
|
|
|
$iat->eraseMessages(); |
|
66
|
|
|
$this->save($iat); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|