-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathConfiguration.php
More file actions
289 lines (267 loc) · 11.8 KB
/
Configuration.php
File metadata and controls
289 lines (267 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
declare(strict_types=1);
namespace League\Bundle\OAuth2ServerBundle\DependencyInjection;
use Defuse\Crypto\Key;
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
use League\Bundle\OAuth2ServerBundle\Model\Client;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
final class Configuration implements ConfigurationInterface
{
/**
* @return TreeBuilder<'array'>
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('league_oauth2_server');
$rootNode = $treeBuilder->getRootNode();
$rootNode->append($this->createAuthorizationServerNode());
$rootNode->append($this->createResourceServerNode());
$rootNode->append($this->createScopesNode());
$rootNode->append($this->createPersistenceNode());
$rootNode->append($this->createClientNode());
$rootNode
->children()
->scalarNode('role_prefix')
->info('Set a custom prefix that replaces the default \'ROLE_OAUTH2_\' role prefix')
->defaultValue('ROLE_OAUTH2_')
->cannotBeEmpty()
->end()
->end();
return $treeBuilder;
}
/**
* @return ArrayNodeDefinition<TreeBuilder<'array'>>
*/
private function createAuthorizationServerNode(): NodeDefinition
{
$treeBuilder = new TreeBuilder('authorization_server');
$node = $treeBuilder->getRootNode();
$node
->isRequired()
->children()
->scalarNode('private_key')
->info("Full path to the private key file.\nHow to generate a private key: https://oauth2.thephpleague.com/installation/#generating-public-and-private-keys")
->example('/var/oauth/private.key')
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('private_key_passphrase')
->info('Passphrase of the private key, if any')
->defaultValue(null)
->end()
->scalarNode('encryption_key')
->info(\sprintf("The plain string or the ascii safe string used to create a %s to be used as an encryption key.\nHow to generate an encryption key: https://oauth2.thephpleague.com/installation/#string-password", Key::class))
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('encryption_key_type')
->info("The type of value of 'encryption_key'\nShould be either 'plain' or 'defuse'")
->cannotBeEmpty()
->defaultValue('plain')
->end()
->scalarNode('access_token_ttl')
->info("How long the issued access token should be valid for.\nThe value should be a valid interval: http://php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters")
->cannotBeEmpty()
->defaultValue('PT1H')
->end()
->scalarNode('refresh_token_ttl')
->info("How long the issued refresh token should be valid for.\nThe value should be a valid interval: http://php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters")
->cannotBeEmpty()
->defaultValue('P1M')
->end()
->scalarNode('auth_code_ttl')
->info("How long the issued auth code should be valid for.\nThe value should be a valid interval: http://php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters")
->cannotBeEmpty()
->defaultValue('PT10M')
->end()
->booleanNode('enable_client_credentials_grant')
->info('Whether to enable the client credentials grant')
->defaultTrue()
->end()
->booleanNode('enable_password_grant')
->info('Whether to enable the password grant')
->defaultTrue()
->end()
->booleanNode('enable_refresh_token_grant')
->info('Whether to enable the refresh token grant')
->defaultTrue()
->end()
->booleanNode('enable_auth_code_grant')
->info('Whether to enable the authorization code grant')
->defaultTrue()
->end()
->booleanNode('require_code_challenge_for_public_clients')
->info('Whether to require code challenge for public clients for the auth code grant')
->defaultTrue()
->end()
->booleanNode('enable_implicit_grant')
->info('Whether to enable the implicit grant')
->defaultTrue()
->end()
->booleanNode('persist_access_token')
->info('Whether to enable access token saving to persistence layer')
->defaultTrue()
->end()
->scalarNode('response_type_class')
->info('Define a custom ResponseType')
->defaultValue(null)
->end()
->booleanNode('revoke_refresh_tokens')
->info('Whether to revoke refresh tokens after they were used for all grant types')
->defaultTrue()
->end()
->end()
;
return $node;
}
/**
* @return ArrayNodeDefinition<TreeBuilder<'array'>>
*/
private function createResourceServerNode(): NodeDefinition
{
$treeBuilder = new TreeBuilder('resource_server');
$node = $treeBuilder->getRootNode();
$node
->isRequired()
->children()
->scalarNode('public_key')
->info("Full path to the public key file\nHow to generate a public key: https://oauth2.thephpleague.com/installation/#generating-public-and-private-keys")
->example('/var/oauth/public.key')
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('jwt_leeway')
->info('The leeway in seconds to allow for clock skew in JWT verification. Default PT0S (no leeway).')
->example('PT60S')
->defaultValue(null)
->end()
->end()
;
return $node;
}
/**
* @return ArrayNodeDefinition<TreeBuilder<'array'>>
*/
private function createScopesNode(): NodeDefinition
{
$treeBuilder = new TreeBuilder('scopes');
$node = $treeBuilder->getRootNode();
$node
->isRequired()
->children()
->arrayNode('available')
->info("Scopes that you wish to utilize in your application.\nThis should be a simple array of strings.")
->isRequired()
->cannotBeEmpty()
->scalarPrototype()
->cannotBeEmpty()
->end()
->end()
->arrayNode('default')
->info("Scopes that will be assigned when no scope given.\nThis should be a simple array of strings.")
->isRequired()
->cannotBeEmpty()
->scalarPrototype()
->cannotBeEmpty()
->end()
->end()
->end()
;
return $node;
}
/**
* @return ArrayNodeDefinition<TreeBuilder<'array'>>
*/
private function createPersistenceNode(): NodeDefinition
{
$treeBuilder = new TreeBuilder('persistence');
$node = $treeBuilder->getRootNode();
$node
->info("Configures different persistence methods that can be used by the bundle for saving client and token data.\nOnly one persistence method can be configured at a time.")
->isRequired()
->performNoDeepMerging()
->children()
// Doctrine persistence
->arrayNode('doctrine')
->children()
->scalarNode('entity_manager')
->info('Name of the entity manager that you wish to use for managing clients and tokens.')
->cannotBeEmpty()
->defaultValue('default')
->end()
->scalarNode('table_prefix')
->info('Table name prefix.')
->cannotBeEmpty()
->defaultValue('oauth2_')
->end()
->end()
->end()
// In-memory persistence
->scalarNode('in_memory')
->end()
// Custom persistence
->arrayNode('custom')
->children()
->scalarNode('access_token_manager')
->info('Service id of the custom access token manager')
->cannotBeEmpty()
->isRequired()
->end()
->scalarNode('authorization_code_manager')
->info('Service id of the custom authorization code manager')
->cannotBeEmpty()
->isRequired()
->end()
->scalarNode('client_manager')
->info('Service id of the custom client manager')
->cannotBeEmpty()
->isRequired()
->end()
->scalarNode('refresh_token_manager')
->info('Service id of the custom refresh token manager')
->cannotBeEmpty()
->isRequired()
->end()
->scalarNode('credentials_revoker')
->info('Service id of the custom credentials revoker')
->cannotBeEmpty()
->isRequired()
->end()
->end()
->end()
->end()
;
return $node;
}
/**
* @return ArrayNodeDefinition<TreeBuilder<'array'>>
*/
private function createClientNode(): NodeDefinition
{
$treeBuilder = new TreeBuilder('client');
$node = $treeBuilder->getRootNode();
$node
->addDefaultsIfNotSet()
->children()
->scalarNode('classname')
->info(\sprintf('Set a custom client class. Must be a %s', AbstractClient::class))
->defaultValue(Client::class)
->validate()
->ifTrue(static function ($v) {
return !is_a($v, AbstractClient::class, true);
})
->thenInvalid(\sprintf('%%s must be a %s', AbstractClient::class))
->end()
->end()
->booleanNode('allow_plaintext_secrets')
->info('Whether to allow plaintext client secrets.')
->defaultTrue()
->end()
->end()
;
return $node;
}
}