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\ServerBundle\Tests\TestBundle\DataFixtures; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\DataFixtures\FixtureInterface; |
17
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
18
|
|
|
use OAuth2Framework\Component\AuthorizationCodeGrant\AuthorizationCodeId; |
19
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
20
|
|
|
use OAuth2Framework\Component\Core\DataBag\DataBag; |
21
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
22
|
|
|
use OAuth2Framework\ServerBundle\Tests\TestBundle\Entity\AuthorizationCode; |
23
|
|
|
use OAuth2Framework\ServerBundle\Tests\TestBundle\Entity\AuthorizationCodeRepository; |
24
|
|
|
|
25
|
|
|
final class AuthorizationCodeFixtures implements FixtureInterface |
26
|
|
|
{ |
27
|
|
|
private $authorizationCodeRepository; |
28
|
|
|
|
29
|
|
|
public function __construct(AuthorizationCodeRepository $authorizationCodeRepository) |
30
|
|
|
{ |
31
|
|
|
$this->authorizationCodeRepository = $authorizationCodeRepository; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function load(ObjectManager $manager) |
35
|
|
|
{ |
36
|
|
|
foreach ($this->getData() as $datum) { |
37
|
|
|
$authorizationCode = new AuthorizationCode( |
38
|
|
|
new AuthorizationCodeId($datum['authorization_code_id']), |
39
|
|
|
new ClientId($datum['client_id']), |
40
|
|
|
new UserAccountId($datum['user_account_id']), |
41
|
|
|
$datum['query_parameters'], |
42
|
|
|
$datum['redirect_uri'], |
43
|
|
|
$datum['expires_at'], |
44
|
|
|
new DataBag($datum['parameter']), |
45
|
|
|
new DataBag($datum['metadata']), |
46
|
|
|
$datum['resource_server_id'] |
47
|
|
|
); |
48
|
|
|
if ($datum['is_revoked']) { |
49
|
|
|
$authorizationCode->markAsUsed(); |
50
|
|
|
} |
51
|
|
|
$this->authorizationCodeRepository->save($authorizationCode); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private function getData(): array |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
[ |
59
|
|
|
'authorization_code_id' => 'VALID_AUTHORIZATION_CODE', |
60
|
|
|
'client_id' => 'CLIENT_ID_3', |
61
|
|
|
'user_account_id' => 'john.1', |
62
|
|
|
'query_parameters' => [], |
63
|
|
|
'redirect_uri' => 'http://localhost/callback', |
64
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 day'), |
65
|
|
|
'parameter' => [], |
66
|
|
|
'metadata' => [], |
67
|
|
|
'resource_server_id' => null, |
68
|
|
|
'is_revoked' => false, |
69
|
|
|
], |
70
|
|
|
[ |
71
|
|
|
'authorization_code_id' => 'VALID_AUTHORIZATION_CODE_FOR_CONFIDENTIAL_CLIENT', |
72
|
|
|
'client_id' => 'CLIENT_ID_5', |
73
|
|
|
'user_account_id' => 'john.1', |
74
|
|
|
'query_parameters' => [], |
75
|
|
|
'redirect_uri' => 'http://localhost/callback', |
76
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 day'), |
77
|
|
|
'parameter' => [], |
78
|
|
|
'metadata' => [], |
79
|
|
|
'resource_server_id' => null, |
80
|
|
|
'is_revoked' => false, |
81
|
|
|
], |
82
|
|
|
[ |
83
|
|
|
'authorization_code_id' => 'REVOKED_AUTHORIZATION_CODE', |
84
|
|
|
'client_id' => 'CLIENT_ID_3', |
85
|
|
|
'user_account_id' => 'john.1', |
86
|
|
|
'query_parameters' => [], |
87
|
|
|
'redirect_uri' => 'http://localhost/callback', |
88
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 day'), |
89
|
|
|
'parameter' => [], |
90
|
|
|
'metadata' => [], |
91
|
|
|
'resource_server_id' => null, |
92
|
|
|
'is_revoked' => true, |
93
|
|
|
], |
94
|
|
|
[ |
95
|
|
|
'authorization_code_id' => 'EXPIRED_AUTHORIZATION_CODE', |
96
|
|
|
'client_id' => 'CLIENT_ID_3', |
97
|
|
|
'user_account_id' => 'john.1', |
98
|
|
|
'query_parameters' => [], |
99
|
|
|
'redirect_uri' => 'http://localhost/callback', |
100
|
|
|
'expires_at' => new \DateTimeImmutable('now -1 day'), |
101
|
|
|
'parameter' => [], |
102
|
|
|
'metadata' => [], |
103
|
|
|
'resource_server_id' => null, |
104
|
|
|
'is_revoked' => false, |
105
|
|
|
], |
106
|
|
|
]; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|