|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2017 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\Server\Tests\Context; |
|
15
|
|
|
|
|
16
|
|
|
/* |
|
17
|
|
|
* The MIT License (MIT) |
|
18
|
|
|
* |
|
19
|
|
|
* Copyright (c) 2014-2017 Spomky-Labs |
|
20
|
|
|
* |
|
21
|
|
|
* This software may be modified and distributed under the terms |
|
22
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
use Behat\Behat\Context\Context; |
|
26
|
|
|
use Behat\Symfony2Extension\Context\KernelDictionary; |
|
27
|
|
|
use OAuth2Framework\Bundle\Server\Model\AuthCodeRepository; |
|
28
|
|
|
use OAuth2Framework\Bundle\Server\Model\ClientRepository; |
|
29
|
|
|
use OAuth2Framework\Bundle\Server\Model\InitialAccessTokenRepository; |
|
30
|
|
|
use OAuth2Framework\Bundle\Server\Model\PreConfiguredAuthorizationRepository; |
|
31
|
|
|
use OAuth2Framework\Component\Server\Model\AccessToken\AccessToken; |
|
32
|
|
|
use OAuth2Framework\Component\Server\Model\AccessToken\AccessTokenId; |
|
33
|
|
|
use OAuth2Framework\Component\Server\Model\AccessToken\AccessTokenRepositoryInterface; |
|
34
|
|
|
use OAuth2Framework\Component\Server\Model\AuthCode\AuthCode; |
|
35
|
|
|
use OAuth2Framework\Component\Server\Model\AuthCode\AuthCodeId; |
|
36
|
|
|
use OAuth2Framework\Component\Server\Model\Client\Client; |
|
37
|
|
|
use OAuth2Framework\Component\Server\Model\Client\ClientId; |
|
38
|
|
|
use OAuth2Framework\Component\Server\Model\DataBag\DataBag; |
|
39
|
|
|
use OAuth2Framework\Component\Server\Model\InitialAccessToken\InitialAccessToken; |
|
40
|
|
|
use OAuth2Framework\Component\Server\Model\InitialAccessToken\InitialAccessTokenId; |
|
41
|
|
|
use OAuth2Framework\Component\Server\Model\RefreshToken\RefreshToken; |
|
42
|
|
|
use OAuth2Framework\Component\Server\Model\RefreshToken\RefreshTokenId; |
|
43
|
|
|
use OAuth2Framework\Component\Server\Model\RefreshToken\RefreshTokenRepositoryInterface; |
|
44
|
|
|
use OAuth2Framework\Component\Server\Model\ResourceServer\ResourceServerId; |
|
45
|
|
|
use OAuth2Framework\Component\Server\Model\UserAccount\UserAccountId; |
|
46
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
47
|
|
|
|
|
48
|
|
|
final class FixturesContext implements Context |
|
49
|
|
|
{ |
|
50
|
|
|
use KernelDictionary; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @BeforeScenario |
|
54
|
|
|
*/ |
|
55
|
|
|
public function loadFixtures() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->loadClients(); |
|
58
|
|
|
$this->loadAccessTokens(); |
|
59
|
|
|
$this->loadRefreshTokens(); |
|
60
|
|
|
$this->loadAuthorizationCodes(); |
|
61
|
|
|
$this->loadInitialAccessTokens(); |
|
62
|
|
|
$this->loadPreConfiguredAuthorizations(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @AfterScenario |
|
67
|
|
|
*/ |
|
68
|
|
|
public function removeFixtures() |
|
69
|
|
|
{ |
|
70
|
|
|
$storagePath = sprintf('%s/fixtures', $this->getContainer()->getParameter('kernel.cache_dir')); |
|
71
|
|
|
|
|
72
|
|
|
$fs = new Filesystem(); |
|
73
|
|
|
$fs->remove($storagePath); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
private function loadClients() |
|
77
|
|
|
{ |
|
78
|
|
|
$clientRepository = $this->getContainer()->get(ClientRepository::class); |
|
79
|
|
|
|
|
80
|
|
|
foreach ($this->getClients() as $clientInformation) { |
|
81
|
|
|
$client = Client::createEmpty(); |
|
82
|
|
|
$client = $client->create( |
|
83
|
|
|
$clientInformation['id'], |
|
84
|
|
|
$clientInformation['parameters'], |
|
85
|
|
|
$clientInformation['user_account_id'] |
|
86
|
|
|
); |
|
87
|
|
|
if ($clientInformation['is_deleted']) { |
|
88
|
|
|
$client = $client->markAsDeleted(); |
|
89
|
|
|
} |
|
90
|
|
|
$clientRepository->save($client); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return array |
|
96
|
|
|
*/ |
|
97
|
|
|
private function getClients(): array |
|
98
|
|
|
{ |
|
99
|
|
|
return [ |
|
100
|
|
|
[ |
|
101
|
|
|
'id' => ClientId::create('client1'), |
|
102
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
103
|
|
|
'parameters' => DataBag::createFromArray([ |
|
104
|
|
|
'client_id' => 'client1', |
|
105
|
|
|
'registration_access_token' => 'REGISTRATION_ACCESS_TOKEN', |
|
106
|
|
|
'registration_client_uri' => 'https://oauth2.test/client/configure/client1', |
|
107
|
|
|
'token_endpoint_auth_method' => 'client_secret_basic', |
|
108
|
|
|
'client_secret' => 'secret', |
|
109
|
|
|
'grant_types' => ['client_credentials', 'password', 'refresh_token', 'authorization_code', 'urn:ietf:params:oauth:grant-type:jwt-bearer'], |
|
110
|
|
|
'response_types' => ['code', 'token', 'id_token', 'code token', 'code id_token', 'id_token token', 'code id_token token', 'none'], |
|
111
|
|
|
'redirect_uris' => ['https://example.com/'], |
|
112
|
|
|
]), |
|
113
|
|
|
'is_deleted' => false, |
|
114
|
|
|
], |
|
115
|
|
|
[ |
|
116
|
|
|
'id' => ClientId::create('client2'), |
|
117
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
118
|
|
|
'parameters' => DataBag::createFromArray([ |
|
119
|
|
|
'client_id' => 'client2', |
|
120
|
|
|
'registration_access_token' => 'REGISTRATION_ACCESS_TOKEN', |
|
121
|
|
|
'registration_client_uri' => 'https://oauth2.test/client/configure/client2', |
|
122
|
|
|
'token_endpoint_auth_method' => 'none', |
|
123
|
|
|
'grant_types' => ['client_credentials', 'authorization_code'], |
|
124
|
|
|
'userinfo_signed_response_alg' => 'none', |
|
125
|
|
|
]), |
|
126
|
|
|
'is_deleted' => false, |
|
127
|
|
|
], |
|
128
|
|
|
[ |
|
129
|
|
|
'id' => ClientId::create('client3'), |
|
130
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
131
|
|
|
'parameters' => DataBag::createFromArray([ |
|
132
|
|
|
'client_id' => 'client3', |
|
133
|
|
|
'registration_access_token' => 'REGISTRATION_ACCESS_TOKEN', |
|
134
|
|
|
'registration_client_uri' => 'https://oauth2.test/client/configure/client3', |
|
135
|
|
|
'token_endpoint_auth_method' => 'client_secret_jwt', |
|
136
|
|
|
'client_secret' => 'secret', |
|
137
|
|
|
'client_secret_expires_at' => (new \DateTimeImmutable('now + 1 day'))->getTimestamp(), |
|
138
|
|
|
'grant_types' => ['client_credentials', 'password', 'refresh_token', 'authorization_code'], |
|
139
|
|
|
]), |
|
140
|
|
|
'is_deleted' => false, |
|
141
|
|
|
], |
|
142
|
|
|
[ |
|
143
|
|
|
'id' => ClientId::create('client4'), |
|
144
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
145
|
|
|
'parameters' => DataBag::createFromArray([ |
|
146
|
|
|
'client_id' => 'client4', |
|
147
|
|
|
'registration_access_token' => 'REGISTRATION_ACCESS_TOKEN', |
|
148
|
|
|
'registration_client_uri' => 'https://oauth2.test/client/configure/client4', |
|
149
|
|
|
'token_endpoint_auth_method' => 'client_secret_post', |
|
150
|
|
|
'client_secret' => 'secret', |
|
151
|
|
|
'client_secret_expires_at' => (new \DateTimeImmutable('now + 1 day'))->getTimestamp(), |
|
152
|
|
|
]), |
|
153
|
|
|
'is_deleted' => false, |
|
154
|
|
|
], |
|
155
|
|
|
[ |
|
156
|
|
|
'id' => ClientId::create('client5'), |
|
157
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
158
|
|
|
'parameters' => DataBag::createFromArray([ |
|
159
|
|
|
'client_id' => 'client4', |
|
160
|
|
|
'registration_access_token' => 'REGISTRATION_ACCESS_TOKEN', |
|
161
|
|
|
'registration_client_uri' => 'https://oauth2.test/client/configure/client4', |
|
162
|
|
|
'token_endpoint_auth_method' => 'client_secret_post', |
|
163
|
|
|
'client_secret' => 'secret', |
|
164
|
|
|
'client_secret_expires_at' => (new \DateTimeImmutable('now -1 day'))->getTimestamp(), |
|
165
|
|
|
]), |
|
166
|
|
|
'is_deleted' => false, |
|
167
|
|
|
], |
|
168
|
|
|
[ |
|
169
|
|
|
'id' => ClientId::create('client6'), |
|
170
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
171
|
|
|
'parameters' => DataBag::createFromArray([ |
|
172
|
|
|
'client_id' => 'client4', |
|
173
|
|
|
'registration_access_token' => 'REGISTRATION_ACCESS_TOKEN', |
|
174
|
|
|
'registration_client_uri' => 'https://oauth2.test/client/configure/client4', |
|
175
|
|
|
'token_endpoint_auth_method' => 'client_secret_post', |
|
176
|
|
|
'client_secret' => 'secret', |
|
177
|
|
|
'client_secret_expires_at' => (new \DateTimeImmutable('now -1 day'))->getTimestamp(), |
|
178
|
|
|
]), |
|
179
|
|
|
'is_deleted' => true, |
|
180
|
|
|
], |
|
181
|
|
|
]; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
private function loadInitialAccessTokens() |
|
185
|
|
|
{ |
|
186
|
|
|
$manager = $this->getContainer()->get(InitialAccessTokenRepository::class); |
|
187
|
|
|
|
|
188
|
|
|
foreach ($this->getInitialAccessTokens() as $initial_access_Token_information) { |
|
189
|
|
|
$initialAccessToken = InitialAccessToken::createEmpty(); |
|
190
|
|
|
$initialAccessToken = $initialAccessToken->create( |
|
191
|
|
|
$initial_access_Token_information['id'], |
|
192
|
|
|
$initial_access_Token_information['user_account_id'], |
|
193
|
|
|
$initial_access_Token_information['expires_at'] |
|
194
|
|
|
); |
|
195
|
|
|
if (true === $initial_access_Token_information['is_revoked']) { |
|
196
|
|
|
$initialAccessToken = $initialAccessToken->markAsRevoked(); |
|
197
|
|
|
} |
|
198
|
|
|
$manager->save($initialAccessToken); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @return array |
|
204
|
|
|
*/ |
|
205
|
|
|
private function getInitialAccessTokens(): array |
|
206
|
|
|
{ |
|
207
|
|
|
return [ |
|
208
|
|
|
[ |
|
209
|
|
|
'id' => InitialAccessTokenId::create('INITIAL_ACCESS_TOKEN_VALID'), |
|
210
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
211
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 hour'), |
|
212
|
|
|
'is_revoked' => false, |
|
213
|
|
|
], |
|
214
|
|
|
[ |
|
215
|
|
|
'id' => InitialAccessTokenId::create('INITIAL_ACCESS_TOKEN_EXPIRED'), |
|
216
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
217
|
|
|
'expires_at' => new \DateTimeImmutable('now -1 hour'), |
|
218
|
|
|
'is_revoked' => false, |
|
219
|
|
|
], |
|
220
|
|
|
[ |
|
221
|
|
|
'id' => InitialAccessTokenId::create('INITIAL_ACCESS_TOKEN_REVOKED'), |
|
222
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
223
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 hour'), |
|
224
|
|
|
'is_revoked' => true, |
|
225
|
|
|
], |
|
226
|
|
|
]; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
private function loadAccessTokens() |
|
230
|
|
|
{ |
|
231
|
|
|
$manager = $this->getContainer()->get(AccessTokenRepositoryInterface::class); |
|
232
|
|
|
|
|
233
|
|
|
foreach ($this->getAccessTokens() as $accessTokenInformation) { |
|
234
|
|
|
$accessToken = AccessToken::createEmpty(); |
|
235
|
|
|
$accessToken = $accessToken->create( |
|
236
|
|
|
$accessTokenInformation['id'], |
|
237
|
|
|
$accessTokenInformation['resource_owner_id'], |
|
238
|
|
|
$accessTokenInformation['client_id'], |
|
239
|
|
|
$accessTokenInformation['parameters'], |
|
240
|
|
|
$accessTokenInformation['metadatas'], |
|
241
|
|
|
$accessTokenInformation['scope'], |
|
242
|
|
|
$accessTokenInformation['expires_at'], |
|
243
|
|
|
$accessTokenInformation['refresh_token'], |
|
244
|
|
|
$accessTokenInformation['resource_server_id'] |
|
245
|
|
|
); |
|
246
|
|
|
$manager->save($accessToken); |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @return array |
|
252
|
|
|
*/ |
|
253
|
|
|
private function getAccessTokens(): array |
|
254
|
|
|
{ |
|
255
|
|
|
return [ |
|
256
|
|
|
[ |
|
257
|
|
|
'id' => AccessTokenId::create('ACCESS_TOKEN_#1'), |
|
258
|
|
|
'resource_owner_id' => UserAccountId::create('john.1'), |
|
259
|
|
|
'client_id' => ClientId::create('client1'), |
|
260
|
|
|
'parameters' => DataBag::createFromArray(['token_type' => 'Bearer']), |
|
261
|
|
|
'metadatas' => DataBag::createFromArray([]), |
|
262
|
|
|
'scope' => [], |
|
263
|
|
|
'expires_at' => new \DateTimeImmutable('now +3600 seconds'), |
|
264
|
|
|
'refresh_token' => null, |
|
265
|
|
|
'resource_server_id' => ResourceServerId::create('ResourceServer1'), |
|
266
|
|
|
], |
|
267
|
|
|
[ |
|
268
|
|
|
'id' => AccessTokenId::create('ACCESS_TOKEN_#2'), |
|
269
|
|
|
'resource_owner_id' => UserAccountId::create('john.1'), |
|
270
|
|
|
'client_id' => ClientId::create('client2'), |
|
271
|
|
|
'parameters' => DataBag::createFromArray([]), |
|
272
|
|
|
'metadatas' => DataBag::createFromArray([]), |
|
273
|
|
|
'scope' => [], |
|
274
|
|
|
'expires_at' => new \DateTimeImmutable('now +3600 seconds'), |
|
275
|
|
|
'refresh_token' => null, |
|
276
|
|
|
'resource_server_id' => null, |
|
277
|
|
|
], |
|
278
|
|
|
[ |
|
279
|
|
|
'id' => AccessTokenId::create('VALID_ACCESS_TOKEN_FOR_USERINFO'), |
|
280
|
|
|
'resource_owner_id' => UserAccountId::create('john.1'), |
|
281
|
|
|
'client_id' => ClientId::create('client1'), |
|
282
|
|
|
'parameters' => DataBag::createFromArray(['token_type' => 'Bearer']), |
|
283
|
|
|
'metadatas' => DataBag::createFromArray(['redirect_uri' => 'http://127.0.0.1:8080']), |
|
284
|
|
|
'scope' => ['openid', 'profile', 'email', 'phone', 'address'], |
|
285
|
|
|
'expires_at' => new \DateTimeImmutable('now +3600 seconds'), |
|
286
|
|
|
'refresh_token' => null, |
|
287
|
|
|
'resource_server_id' => null, |
|
288
|
|
|
], |
|
289
|
|
|
[ |
|
290
|
|
|
'id' => AccessTokenId::create('VALID_ACCESS_TOKEN_FOR_SIGNED_USERINFO'), |
|
291
|
|
|
'resource_owner_id' => UserAccountId::create('john.1'), |
|
292
|
|
|
'client_id' => ClientId::create('client2'), |
|
293
|
|
|
'parameters' => DataBag::createFromArray(['token_type' => 'Bearer']), |
|
294
|
|
|
'metadatas' => DataBag::createFromArray(['redirect_uri' => 'http://127.0.0.1:8080']), |
|
295
|
|
|
'scope' => ['openid', 'profile', 'email', 'phone', 'address'], |
|
296
|
|
|
'expires_at' => new \DateTimeImmutable('now +3600 seconds'), |
|
297
|
|
|
'refresh_token' => null, |
|
298
|
|
|
'resource_server_id' => null, |
|
299
|
|
|
], |
|
300
|
|
|
[ |
|
301
|
|
|
'id' => AccessTokenId::create('INVALID_ACCESS_TOKEN_FOR_USERINFO'), |
|
302
|
|
|
'resource_owner_id' => UserAccountId::create('john.1'), |
|
303
|
|
|
'client_id' => ClientId::create('client2'), |
|
304
|
|
|
'parameters' => DataBag::createFromArray(['token_type' => 'Bearer']), |
|
305
|
|
|
'metadatas' => DataBag::createFromArray(['redirect_uri' => 'http://127.0.0.1:8080']), |
|
306
|
|
|
'scope' => [], |
|
307
|
|
|
'expires_at' => new \DateTimeImmutable('now +3600 seconds'), |
|
308
|
|
|
'refresh_token' => null, |
|
309
|
|
|
'resource_server_id' => null, |
|
310
|
|
|
], |
|
311
|
|
|
[ |
|
312
|
|
|
'id' => AccessTokenId::create('ACCESS_TOKEN_ISSUED_THROUGH_TOKEN_ENDPOINT'), |
|
313
|
|
|
'resource_owner_id' => UserAccountId::create('john.1'), |
|
314
|
|
|
'client_id' => ClientId::create('client2'), |
|
315
|
|
|
'parameters' => DataBag::createFromArray(['token_type' => 'Bearer']), |
|
316
|
|
|
'metadatas' => DataBag::createFromArray([]), |
|
317
|
|
|
'scope' => ['openid', 'profile', 'email', 'phone', 'address'], |
|
318
|
|
|
'expires_at' => new \DateTimeImmutable('now +3600 seconds'), |
|
319
|
|
|
'refresh_token' => null, |
|
320
|
|
|
'resource_server_id' => null, |
|
321
|
|
|
], |
|
322
|
|
|
]; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
private function loadAuthorizationCodes() |
|
326
|
|
|
{ |
|
327
|
|
|
$manager = $this->getContainer()->get(AuthCodeRepository::class); |
|
328
|
|
|
|
|
329
|
|
|
foreach ($this->getAuthCodes() as $authCodeInformation) { |
|
330
|
|
|
$authCode = AuthCode::createEmpty(); |
|
331
|
|
|
$authCode = $authCode->create( |
|
332
|
|
|
$authCodeInformation['id'], |
|
333
|
|
|
$authCodeInformation['client_id'], |
|
334
|
|
|
$authCodeInformation['user_account_id'], |
|
335
|
|
|
$authCodeInformation['query_parameters'], |
|
336
|
|
|
$authCodeInformation['redirect_uri'], |
|
337
|
|
|
$authCodeInformation['expires_at'], |
|
338
|
|
|
$authCodeInformation['parameters'], |
|
339
|
|
|
$authCodeInformation['metadatas'], |
|
340
|
|
|
$authCodeInformation['scope'], |
|
341
|
|
|
$authCodeInformation['with_refresh_token'], |
|
342
|
|
|
null |
|
343
|
|
|
); |
|
344
|
|
|
if ($authCodeInformation['is_used']) { |
|
345
|
|
|
$authCode = $authCode->markAsUsed(); |
|
346
|
|
|
} |
|
347
|
|
|
if ($authCodeInformation['is_revoked']) { |
|
348
|
|
|
$authCode = $authCode->markAsRevoked(); |
|
349
|
|
|
} |
|
350
|
|
|
$manager->save($authCode); |
|
351
|
|
|
} |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
/** |
|
355
|
|
|
* @return array |
|
356
|
|
|
*/ |
|
357
|
|
|
private function getAuthCodes(): array |
|
358
|
|
|
{ |
|
359
|
|
|
return [ |
|
360
|
|
|
[ |
|
361
|
|
|
'id' => AuthCodeId::create('VALID_AUTH_CODE'), |
|
362
|
|
|
'client_id' => ClientId::create('client1'), |
|
363
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
364
|
|
|
'query_parameters' => [], |
|
365
|
|
|
'redirect_uri' => 'https://www.example.com/callback', |
|
366
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 day'), |
|
367
|
|
|
'parameters' => new DataBag(), |
|
368
|
|
|
'metadatas' => new DataBag(), |
|
369
|
|
|
'scope' => ['openid', 'email', 'phone', 'address'], |
|
370
|
|
|
'with_refresh_token' => false, |
|
371
|
|
|
'is_revoked' => false, |
|
372
|
|
|
'is_used' => false, |
|
373
|
|
|
], |
|
374
|
|
|
[ |
|
375
|
|
|
'id' => AuthCodeId::create('EXPIRED_AUTH_CODE'), |
|
376
|
|
|
'client_id' => ClientId::create('client1'), |
|
377
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
378
|
|
|
'query_parameters' => [], |
|
379
|
|
|
'redirect_uri' => 'https://www.example.com/callback', |
|
380
|
|
|
'expires_at' => new \DateTimeImmutable('now -1 day'), |
|
381
|
|
|
'parameters' => new DataBag(), |
|
382
|
|
|
'metadatas' => new DataBag(), |
|
383
|
|
|
'scope' => ['openid', 'email', 'phone', 'address'], |
|
384
|
|
|
'with_refresh_token' => false, |
|
385
|
|
|
'is_revoked' => false, |
|
386
|
|
|
'is_used' => false, |
|
387
|
|
|
], |
|
388
|
|
|
[ |
|
389
|
|
|
'id' => AuthCodeId::create('AUTH_CODE_WITH_CODE_VERIFIER_PLAIN'), |
|
390
|
|
|
'client_id' => ClientId::create('client1'), |
|
391
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
392
|
|
|
'query_parameters' => [ |
|
393
|
|
|
'code_challenge' => 'E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM', |
|
394
|
|
|
'code_challenge_method' => 'plain', |
|
395
|
|
|
], |
|
396
|
|
|
'redirect_uri' => 'https://www.example.com/callback', |
|
397
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 day'), |
|
398
|
|
|
'parameters' => new DataBag(), |
|
399
|
|
|
'metadatas' => new DataBag(), |
|
400
|
|
|
'scope' => ['openid', 'email', 'phone', 'address'], |
|
401
|
|
|
'with_refresh_token' => false, |
|
402
|
|
|
'is_revoked' => false, |
|
403
|
|
|
'is_used' => false, |
|
404
|
|
|
], |
|
405
|
|
|
[ |
|
406
|
|
|
'id' => AuthCodeId::create('AUTH_CODE_WITH_CODE_VERIFIER_S256'), |
|
407
|
|
|
'client_id' => ClientId::create('client1'), |
|
408
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
409
|
|
|
'query_parameters' => [ |
|
410
|
|
|
'code_challenge' => 'DSmbHrVIcI0EU05-BQxCe1bt-hXRNjejSEvdYbq_g4Q', |
|
411
|
|
|
'code_challenge_method' => 'S256', |
|
412
|
|
|
], |
|
413
|
|
|
'redirect_uri' => 'https://www.example.com/callback', |
|
414
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 day'), |
|
415
|
|
|
'parameters' => new DataBag(), |
|
416
|
|
|
'metadatas' => new DataBag(), |
|
417
|
|
|
'scope' => ['openid', 'email', 'phone', 'address'], |
|
418
|
|
|
'with_refresh_token' => false, |
|
419
|
|
|
'is_revoked' => false, |
|
420
|
|
|
'is_used' => false, |
|
421
|
|
|
], |
|
422
|
|
|
[ |
|
423
|
|
|
'id' => AuthCodeId::create('AUTH_CODE_REVOKED'), |
|
424
|
|
|
'client_id' => ClientId::create('client1'), |
|
425
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
426
|
|
|
'query_parameters' => [ |
|
427
|
|
|
'code_challenge' => 'DSmbHrVIcI0EU05-BQxCe1bt-hXRNjejSEvdYbq_g4Q', |
|
428
|
|
|
'code_challenge_method' => 'S256', |
|
429
|
|
|
], |
|
430
|
|
|
'redirect_uri' => 'https://www.example.com/callback', |
|
431
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 day'), |
|
432
|
|
|
'parameters' => new DataBag(), |
|
433
|
|
|
'metadatas' => new DataBag(), |
|
434
|
|
|
'scope' => ['openid', 'email', 'phone', 'address'], |
|
435
|
|
|
'with_refresh_token' => false, |
|
436
|
|
|
'is_revoked' => true, |
|
437
|
|
|
'is_used' => false, |
|
438
|
|
|
], |
|
439
|
|
|
[ |
|
440
|
|
|
'id' => AuthCodeId::create('AUTH_CODE_USED'), |
|
441
|
|
|
'client_id' => ClientId::create('client1'), |
|
442
|
|
|
'user_account_id' => UserAccountId::create('john.1'), |
|
443
|
|
|
'query_parameters' => [ |
|
444
|
|
|
'code_challenge' => 'DSmbHrVIcI0EU05-BQxCe1bt-hXRNjejSEvdYbq_g4Q', |
|
445
|
|
|
'code_challenge_method' => 'S256', |
|
446
|
|
|
], |
|
447
|
|
|
'redirect_uri' => 'https://www.example.com/callback', |
|
448
|
|
|
'expires_at' => new \DateTimeImmutable('now +1 day'), |
|
449
|
|
|
'parameters' => new DataBag(), |
|
450
|
|
|
'metadatas' => new DataBag(), |
|
451
|
|
|
'scope' => ['openid', 'email', 'phone', 'address'], |
|
452
|
|
|
'with_refresh_token' => false, |
|
453
|
|
|
'is_revoked' => false, |
|
454
|
|
|
'is_used' => true, |
|
455
|
|
|
], |
|
456
|
|
|
]; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
private function loadRefreshTokens() |
|
460
|
|
|
{ |
|
461
|
|
|
$manager = $this->getContainer()->get(RefreshTokenRepositoryInterface::class); |
|
462
|
|
|
|
|
463
|
|
|
foreach ($this->getRefreshTokens() as $refreshTokenInformation) { |
|
464
|
|
|
$refreshToken = RefreshToken::createEmpty(); |
|
465
|
|
|
$refreshToken = $refreshToken->create( |
|
466
|
|
|
$refreshTokenInformation['id'], |
|
467
|
|
|
$refreshTokenInformation['resource_owner_id'], |
|
468
|
|
|
$refreshTokenInformation['client_id'], |
|
469
|
|
|
$refreshTokenInformation['parameters'], |
|
470
|
|
|
$refreshTokenInformation['metadatas'], |
|
471
|
|
|
$refreshTokenInformation['scope'], |
|
472
|
|
|
$refreshTokenInformation['expires_at'], |
|
473
|
|
|
$refreshTokenInformation['resource_server_id'] |
|
474
|
|
|
); |
|
475
|
|
|
if ($refreshTokenInformation['is_revoked']) { |
|
476
|
|
|
$refreshToken = $refreshToken->markAsRevoked(); |
|
477
|
|
|
} |
|
478
|
|
|
$manager->save($refreshToken); |
|
479
|
|
|
} |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* @return array |
|
484
|
|
|
*/ |
|
485
|
|
|
private function getRefreshTokens(): array |
|
486
|
|
|
{ |
|
487
|
|
|
return [ |
|
488
|
|
|
[ |
|
489
|
|
|
'id' => RefreshTokenId::create('EXPIRED_REFRESH_TOKEN'), |
|
490
|
|
|
'resource_owner_id' => UserAccountId::create('john.1'), |
|
491
|
|
|
'client_id' => ClientId::create('client1'), |
|
492
|
|
|
'parameters' => DataBag::createFromArray([]), |
|
493
|
|
|
'metadatas' => DataBag::createFromArray([]), |
|
494
|
|
|
'scope' => [], |
|
495
|
|
|
'resource_server_id' => null, |
|
496
|
|
|
'expires_at' => new \DateTimeImmutable('now -2 days'), |
|
497
|
|
|
'is_revoked' => false, |
|
498
|
|
|
], |
|
499
|
|
|
[ |
|
500
|
|
|
'id' => RefreshTokenId::create('VALID_REFRESH_TOKEN'), |
|
501
|
|
|
'resource_owner_id' => UserAccountId::create('john.1'), |
|
502
|
|
|
'client_id' => ClientId::create('client1'), |
|
503
|
|
|
'parameters' => DataBag::createFromArray([]), |
|
504
|
|
|
'metadatas' => DataBag::createFromArray([]), |
|
505
|
|
|
'scope' => [], |
|
506
|
|
|
'resource_server_id' => null, |
|
507
|
|
|
'expires_at' => new \DateTimeImmutable('now +2 days'), |
|
508
|
|
|
'is_revoked' => false, |
|
509
|
|
|
], |
|
510
|
|
|
[ |
|
511
|
|
|
'id' => RefreshTokenId::create('REVOKED_REFRESH_TOKEN'), |
|
512
|
|
|
'resource_owner_id' => UserAccountId::create('john.1'), |
|
513
|
|
|
'client_id' => ClientId::create('client1'), |
|
514
|
|
|
'parameters' => DataBag::createFromArray([]), |
|
515
|
|
|
'metadatas' => DataBag::createFromArray([]), |
|
516
|
|
|
'scope' => [], |
|
517
|
|
|
'resource_server_id' => null, |
|
518
|
|
|
'expires_at' => new \DateTimeImmutable('now +2 days'), |
|
519
|
|
|
'is_revoked' => true, |
|
520
|
|
|
], |
|
521
|
|
|
]; |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
private function loadPreConfiguredAuthorizations() |
|
525
|
|
|
{ |
|
526
|
|
|
$manager = $this->getContainer()->get(PreConfiguredAuthorizationRepository::class); |
|
527
|
|
|
|
|
528
|
|
|
foreach ($this->getPreConfiguredAuthorizations() as $preConfiguredAuthorizationInformation) { |
|
529
|
|
|
$preConfiguredAuthorization = $manager->create( |
|
530
|
|
|
$preConfiguredAuthorizationInformation['user-account-id'], |
|
531
|
|
|
$preConfiguredAuthorizationInformation['client-id'], |
|
532
|
|
|
$preConfiguredAuthorizationInformation['scope'], |
|
533
|
|
|
$preConfiguredAuthorizationInformation['resource-server-id'] |
|
534
|
|
|
); |
|
535
|
|
|
$manager->save($preConfiguredAuthorization); |
|
536
|
|
|
} |
|
537
|
|
|
} |
|
538
|
|
|
|
|
539
|
|
|
/** |
|
540
|
|
|
* @return array |
|
541
|
|
|
*/ |
|
542
|
|
|
private function getPreConfiguredAuthorizations(): array |
|
543
|
|
|
{ |
|
544
|
|
|
return [ |
|
545
|
|
|
[ |
|
546
|
|
|
'user-account-id' => UserAccountId::create('john.1'), |
|
547
|
|
|
'client-id' => ClientId::create('client1'), |
|
548
|
|
|
'scope' => ['openid', 'profile', 'phone', 'address', 'email'], |
|
549
|
|
|
'resource-server-id' => null, |
|
550
|
|
|
], |
|
551
|
|
|
]; |
|
552
|
|
|
} |
|
553
|
|
|
} |
|
554
|
|
|
|