|
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\OpenIdConnectPlugin; |
|
15
|
|
|
|
|
16
|
|
|
use Assert\Assertion; |
|
17
|
|
|
use Matthias\BundlePlugins\BundlePlugin; |
|
18
|
|
|
use OAuth2Framework\Bundle\Server\CommonPluginMethod; |
|
19
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\ClaimSourceCompilerPass; |
|
20
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\IdTokenMetadataCompilerPass; |
|
21
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\IssuerDiscoveryCompilerPass; |
|
22
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\JwksUriMetadataCompilerPass; |
|
23
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\MetadataRouteCompilerPass; |
|
24
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\PairwiseSubjectIdentifierCompilerPass; |
|
25
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\SessionIFrameRouteCompilerPass; |
|
26
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\UserInfoEndpointSignatureSupportCompilerPass; |
|
27
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\UserinfoRouteCompilerPass; |
|
28
|
|
|
use OAuth2Framework\Bundle\Server\OpenIdConnectPlugin\DependencyInjection\Compiler\UserInfoScopeSupportCompilerPass; |
|
29
|
|
|
use SpomkyLabs\JoseBundle\Helper\ConfigurationHelper; |
|
30
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
31
|
|
|
use Symfony\Component\Config\FileLocator; |
|
32
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
33
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
34
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
35
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
|
36
|
|
|
|
|
37
|
|
|
class OpenIdConnectPlugin extends CommonPluginMethod implements BundlePlugin, PrependExtensionInterface |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
|
|
public function name() |
|
43
|
|
|
{ |
|
44
|
|
|
return 'openid_connect'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
public function addConfiguration(ArrayNodeDefinition $pluginNode) |
|
51
|
|
|
{ |
|
52
|
|
|
$pluginNode |
|
53
|
|
|
->addDefaultsIfNotSet() |
|
54
|
|
|
->children() |
|
55
|
|
|
->scalarNode('user_account_manager') |
|
56
|
|
|
->info('The user account manager.') |
|
57
|
|
|
->isRequired() |
|
58
|
|
|
->end() |
|
59
|
|
|
->scalarNode('pairwise_subject_identifier') |
|
60
|
|
|
->defaultNull() |
|
61
|
|
|
->end() |
|
62
|
|
|
->end(); |
|
63
|
|
|
$this->addClaimsSection($pluginNode); |
|
64
|
|
|
$this->addIdTokenSection($pluginNode); |
|
65
|
|
|
$this->addUserinfoEndpointSection($pluginNode); |
|
66
|
|
|
$this->addJwksUriSection($pluginNode); |
|
67
|
|
|
$this->addMetadataSection($pluginNode); |
|
68
|
|
|
$this->addIssuerDiscoverySection($pluginNode); |
|
69
|
|
|
$this->addSessionManagementSection($pluginNode); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function addSessionManagementSection(ArrayNodeDefinition $node) |
|
73
|
|
|
{ |
|
74
|
|
|
$node |
|
|
|
|
|
|
75
|
|
|
->children() |
|
76
|
|
|
->arrayNode('session_management') |
|
77
|
|
|
->validate() |
|
78
|
|
|
->ifTrue(function ($value) { |
|
79
|
|
|
return $value['enabled'] && empty($value['path']); |
|
80
|
|
|
})->thenInvalid('The option "path" must be set when the Session Management is enabled.') |
|
81
|
|
|
->end() |
|
82
|
|
|
->validate() |
|
83
|
|
|
->ifTrue(function ($value) { |
|
84
|
|
|
return $value['enabled'] && empty($value['storage_name']); |
|
85
|
|
|
})->thenInvalid('The option "storage_name" must be set when the Session Management is enabled.') |
|
86
|
|
|
->end() |
|
87
|
|
|
->validate() |
|
88
|
|
|
->ifTrue(function ($value) { |
|
89
|
|
|
return $value['enabled'] && empty($value['template']); |
|
90
|
|
|
})->thenInvalid('The option "template" must be set when the Session Management is enabled.') |
|
91
|
|
|
->end() |
|
92
|
|
|
->addDefaultsIfNotSet() |
|
93
|
|
|
->children() |
|
94
|
|
|
->booleanNode('enabled') |
|
95
|
|
|
->info('Enable the session management.') |
|
96
|
|
|
->defaultFalse() |
|
97
|
|
|
->end() |
|
98
|
|
|
->scalarNode('storage_name') |
|
99
|
|
|
->defaultValue('oidc_browser_state') |
|
100
|
|
|
->end() |
|
101
|
|
|
->scalarNode('template') |
|
102
|
|
|
->info('The template of the OP iframe.') |
|
103
|
|
|
->defaultValue('@OAuth2FrameworkServerBundle/iframe/iframe.html.twig') |
|
104
|
|
|
->end() |
|
105
|
|
|
->scalarNode('path') |
|
106
|
|
|
->info('The route of the session iframe.') |
|
107
|
|
|
->defaultValue('/session/iframe') |
|
108
|
|
|
->end() |
|
109
|
|
|
->end() |
|
110
|
|
|
->end() |
|
111
|
|
|
->end(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $pluginNode |
|
116
|
|
|
*/ |
|
117
|
|
|
private function addClaimsSection(ArrayNodeDefinition $pluginNode) |
|
118
|
|
|
{ |
|
119
|
|
|
$pluginNode |
|
120
|
|
|
->addDefaultsIfNotSet() |
|
121
|
|
|
->children() |
|
122
|
|
|
->arrayNode('claims_locales_supported') |
|
123
|
|
|
->useAttributeAsKey('name') |
|
124
|
|
|
->prototype('scalar')->end() |
|
125
|
|
|
->info('A list of claim locales supported by this server (optional).') |
|
126
|
|
|
->treatNullLike([]) |
|
127
|
|
|
->end() |
|
128
|
|
|
->arrayNode('claims_supported') |
|
129
|
|
|
->useAttributeAsKey('name') |
|
130
|
|
|
->prototype('scalar')->end() |
|
131
|
|
|
->info('A list of claim supported by this server (optional).') |
|
132
|
|
|
->treatNullLike([]) |
|
133
|
|
|
->end() |
|
134
|
|
|
->end(); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $pluginNode |
|
139
|
|
|
*/ |
|
140
|
|
|
private function addIdTokenSection(ArrayNodeDefinition $pluginNode) |
|
141
|
|
|
{ |
|
142
|
|
|
$pluginNode |
|
143
|
|
|
->addDefaultsIfNotSet() |
|
144
|
|
|
->children() |
|
145
|
|
|
->arrayNode('id_token') |
|
146
|
|
|
->addDefaultsIfNotSet() |
|
147
|
|
|
->children() |
|
148
|
|
|
->scalarNode('manager') |
|
149
|
|
|
->info('The ID Token manager.') |
|
150
|
|
|
->defaultValue('oauth2_server.openid_connect.id_token.manager.default') |
|
151
|
|
|
->end() |
|
152
|
|
|
->scalarNode('signature_algorithm') |
|
153
|
|
|
->isRequired() |
|
154
|
|
|
->end() |
|
155
|
|
|
->scalarNode('signature_key_set') |
|
156
|
|
|
->isRequired() |
|
157
|
|
|
->end() |
|
158
|
|
|
->scalarNode('issuer') |
|
159
|
|
|
->isRequired() |
|
160
|
|
|
->end() |
|
161
|
|
|
->booleanNode('response_type') |
|
162
|
|
|
->defaultTrue() |
|
163
|
|
|
->end() |
|
164
|
|
|
->arrayNode('claim_checkers') |
|
165
|
|
|
->info('Checkers will verify the JWT claims.') |
|
166
|
|
|
->useAttributeAsKey('name') |
|
167
|
|
|
->prototype('scalar')->end() |
|
168
|
|
|
->treatNullLike(['exp', 'iat', 'nbf']) |
|
169
|
|
|
->end() |
|
170
|
|
|
->arrayNode('header_checkers') |
|
171
|
|
|
->info('Checkers will verify the JWT headers.') |
|
172
|
|
|
->useAttributeAsKey('name') |
|
173
|
|
|
->prototype('scalar')->end() |
|
174
|
|
|
->treatNullLike(['crit']) |
|
175
|
|
|
->end() |
|
176
|
|
|
->arrayNode('encryption') |
|
177
|
|
|
->addDefaultsIfNotSet() |
|
178
|
|
|
->children() |
|
179
|
|
|
->booleanNode('enabled')->defaultFalse()->end() |
|
180
|
|
|
->booleanNode('required')->defaultFalse()->end() |
|
181
|
|
|
->scalarNode('key_set')->defaultNull()->end() |
|
182
|
|
|
->arrayNode('key_encryption_algorithms') |
|
183
|
|
|
->info('Supported key encryption algorithms.') |
|
184
|
|
|
->useAttributeAsKey('name') |
|
185
|
|
|
->prototype('scalar')->end() |
|
186
|
|
|
->treatNullLike([]) |
|
187
|
|
|
->end() |
|
188
|
|
|
->arrayNode('content_encryption_algorithms') |
|
189
|
|
|
->info('Supported content encryption algorithms.') |
|
190
|
|
|
->useAttributeAsKey('name') |
|
191
|
|
|
->prototype('scalar')->end() |
|
192
|
|
|
->treatNullLike([]) |
|
193
|
|
|
->end() |
|
194
|
|
|
->end() |
|
195
|
|
|
->end() |
|
196
|
|
|
->end() |
|
197
|
|
|
->end() |
|
198
|
|
|
->end(); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $pluginNode |
|
203
|
|
|
*/ |
|
204
|
|
|
private function addUserinfoEndpointSection(ArrayNodeDefinition $pluginNode) |
|
205
|
|
|
{ |
|
206
|
|
|
$pluginNode |
|
207
|
|
|
->addDefaultsIfNotSet() |
|
208
|
|
|
->children() |
|
209
|
|
|
->arrayNode('userinfo_endpoint') |
|
210
|
|
|
->addDefaultsIfNotSet() |
|
211
|
|
|
->children() |
|
212
|
|
|
->booleanNode('enabled') |
|
213
|
|
|
->defaultTrue() |
|
214
|
|
|
->end() |
|
215
|
|
|
->scalarNode('path') |
|
216
|
|
|
->info('The path to the userinfo endpoint') |
|
217
|
|
|
->defaultValue('/userinfo') |
|
218
|
|
|
->end() |
|
219
|
|
|
->arrayNode('signature') |
|
220
|
|
|
->addDefaultsIfNotSet() |
|
221
|
|
|
->children() |
|
222
|
|
|
->booleanNode('enabled')->defaultFalse()->end() |
|
223
|
|
|
->end() |
|
224
|
|
|
->end() |
|
225
|
|
|
->end() |
|
226
|
|
|
->end() |
|
227
|
|
|
->end(); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $pluginNode |
|
232
|
|
|
*/ |
|
233
|
|
|
private function addJwksUriSection(ArrayNodeDefinition $pluginNode) |
|
234
|
|
|
{ |
|
235
|
|
|
$pluginNode |
|
236
|
|
|
->addDefaultsIfNotSet() |
|
237
|
|
|
->children() |
|
238
|
|
|
->arrayNode('jwks_uri') |
|
239
|
|
|
->addDefaultsIfNotSet() |
|
240
|
|
|
->children() |
|
241
|
|
|
->scalarNode('route_name') |
|
242
|
|
|
->info('The route name to the JWKSet. Set null to disable that feature.') |
|
243
|
|
|
->defaultNull() |
|
244
|
|
|
->end() |
|
245
|
|
|
->arrayNode('route_parameters') |
|
246
|
|
|
->info('Route parameters (optional).') |
|
247
|
|
|
->useAttributeAsKey('name') |
|
248
|
|
|
->prototype('scalar')->end() |
|
249
|
|
|
->treatNullLike([]) |
|
250
|
|
|
->end() |
|
251
|
|
|
->end() |
|
252
|
|
|
->end() |
|
253
|
|
|
->end(); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $pluginNode |
|
258
|
|
|
*/ |
|
259
|
|
|
private function addMetadataSection(ArrayNodeDefinition $pluginNode) |
|
260
|
|
|
{ |
|
261
|
|
|
$pluginNode |
|
262
|
|
|
->addDefaultsIfNotSet() |
|
263
|
|
|
->children() |
|
264
|
|
|
->arrayNode('metadata') |
|
265
|
|
|
->addDefaultsIfNotSet() |
|
266
|
|
|
->children() |
|
267
|
|
|
->booleanNode('enabled') |
|
268
|
|
|
->defaultTrue() |
|
269
|
|
|
->end() |
|
270
|
|
|
->end() |
|
271
|
|
|
->end() |
|
272
|
|
|
->end(); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $pluginNode |
|
277
|
|
|
*/ |
|
278
|
|
|
private function addIssuerDiscoverySection(ArrayNodeDefinition $pluginNode) |
|
279
|
|
|
{ |
|
280
|
|
|
$pluginNode |
|
|
|
|
|
|
281
|
|
|
->addDefaultsIfNotSet() |
|
282
|
|
|
->children() |
|
283
|
|
|
->arrayNode('issuer_discovery') |
|
284
|
|
|
->defaultValue([]) |
|
285
|
|
|
->useAttributeAsKey('name') |
|
286
|
|
|
->prototype('array') |
|
287
|
|
|
->children() |
|
288
|
|
|
->scalarNode('path')->isRequired()->end() |
|
289
|
|
|
->scalarNode('issuer')->isRequired()->end() |
|
290
|
|
|
->scalarNode('server')->isRequired()->end() |
|
291
|
|
|
->end() |
|
292
|
|
|
->end() |
|
293
|
|
|
->end() |
|
294
|
|
|
->end(); |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* {@inheritdoc} |
|
299
|
|
|
*/ |
|
300
|
|
|
public function load(array $pluginConfiguration, ContainerBuilder $container) |
|
301
|
|
|
{ |
|
302
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/Resources/config')); |
|
303
|
|
|
$files = ['id_token_manager', 'userinfo', 'userinfo.scope_support', 'id_token_extension', 'metadata', 'issuer_discovery', 'claim_source_manager']; |
|
304
|
|
|
|
|
305
|
|
|
$parameters = [ |
|
306
|
|
|
'oauth2_server.openid_connect.user_account_manager' => ['type' => 'alias', 'path' => '[user_account_manager]'], |
|
307
|
|
|
'oauth2_server.openid_connect.id_token.manager' => ['type' => 'alias', 'path' => '[id_token][manager]'], |
|
308
|
|
|
'oauth2_server.openid_connect.id_token.manager.signature_key_set' => ['type' => 'alias', 'path' => '[id_token][signature_key_set]'], |
|
309
|
|
|
'oauth2_server.openid_connect.id_token.manager.header_checkers' => ['type' => 'parameter', 'path' => '[id_token][header_checkers]'], |
|
310
|
|
|
'oauth2_server.openid_connect.id_token.manager.claim_checkers' => ['type' => 'parameter', 'path' => '[id_token][claim_checkers]'], |
|
311
|
|
|
'oauth2_server.openid_connect.issuer_discovery' => ['type' => 'parameter', 'path' => '[issuer_discovery]'], |
|
312
|
|
|
'oauth2_server.openid_connect.pairwise_subject_identifier' => ['type' => 'parameter', 'path' => '[pairwise_subject_identifier]'], |
|
313
|
|
|
'oauth2_server.openid_connect.id_token.manager.issuer' => ['type' => 'parameter', 'path' => '[id_token][issuer]'], |
|
314
|
|
|
'oauth2_server.openid_connect.id_token.manager.signature_algorithm' => ['type' => 'parameter', 'path' => '[id_token][signature_algorithm]'], |
|
315
|
|
|
'oauth2_server.openid_connect.userinfo_endpoint.enabled' => ['type' => 'parameter', 'path' => '[userinfo_endpoint][enabled]'], |
|
316
|
|
|
'oauth2_server.openid_connect.userinfo_endpoint.signature.enabled' => ['type' => 'parameter', 'path' => '[userinfo_endpoint][signature][enabled]'], |
|
317
|
|
|
'oauth2_server.openid_connect.metadata.enabled' => ['type' => 'parameter', 'path' => '[metadata][enabled]'], |
|
318
|
|
|
'oauth2_server.openid_connect.id_token.response_type.id_token' => ['type' => 'parameter', 'path' => '[response_type][id_token]'], |
|
319
|
|
|
'oauth2_server.openid_connect.claims_supported' => ['type' => 'parameter', 'path' => '[claims_supported]', 'callback' => function ($data) { |
|
320
|
|
|
return array_unique($data); |
|
321
|
|
|
}], |
|
322
|
|
|
'oauth2_server.openid_connect.claims_locales_supported' => ['type' => 'parameter', 'path' => '[claims_locales_supported]', 'callback' => function ($data) { |
|
323
|
|
|
return array_unique($data); |
|
324
|
|
|
}], |
|
325
|
|
|
]; |
|
326
|
|
|
|
|
327
|
|
|
if (true === $pluginConfiguration['id_token']['response_type']) { |
|
328
|
|
|
$files[] = 'id_token_response_type'; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
if (true === $pluginConfiguration['userinfo_endpoint']['enabled']) { |
|
332
|
|
|
$files[] = 'userinfo_endpoint'; |
|
333
|
|
|
$parameters['oauth2_server.openid_connect.userinfo_endpoint.path'] = ['type' => 'parameter', 'path' => '[userinfo_endpoint][path]']; |
|
334
|
|
|
$parameters['oauth2_server.openid_connect.userinfo_endpoint.signature.enabled'] = ['type' => 'parameter', 'path' => '[userinfo_endpoint][signature][enabled]']; |
|
335
|
|
|
if (true === $pluginConfiguration['userinfo_endpoint']['signature']['enabled']) { |
|
336
|
|
|
$parameters['oauth2_server.openid_connect.userinfo_endpoint.signature.signature_key_set'] = ['type' => 'alias', 'path' => '[id_token][signature_key_set]']; |
|
337
|
|
|
$parameters['oauth2_server.openid_connect.userinfo_endpoint.signature.issuer'] = ['type' => 'parameter', 'path' => '[id_token][issuer]']; |
|
338
|
|
|
$parameters['oauth2_server.openid_connect.userinfo_endpoint.signature.signature_algorithm'] = ['type' => 'parameter', 'path' => '[id_token][signature_algorithm]']; |
|
339
|
|
|
} |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
if (null !== $pluginConfiguration['jwks_uri']['route_name']) { |
|
343
|
|
|
$parameters['oauth2_server.openid_connect.jwks_uri.route_name'] = ['type' => 'parameter', 'path' => '[jwks_uri][route_name]']; |
|
344
|
|
|
$parameters['oauth2_server.openid_connect.jwks_uri.route_parameters'] = ['type' => 'parameter', 'path' => '[jwks_uri][route_parameters]']; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
if (true === $pluginConfiguration['metadata']['enabled']) { |
|
348
|
|
|
$files[] = 'metadata'; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
if (true === $pluginConfiguration['session_management']['enabled']) { |
|
352
|
|
|
$files[] = 'session_state_parameter_extension'; |
|
353
|
|
|
$parameters['oauth2_server.openid_connect.session_state_parameter_extension.enabled'] = ['type' => 'parameter', 'path' => '[session_management][enabled]']; |
|
354
|
|
|
$parameters['oauth2_server.openid_connect.session_state_parameter_extension.storage_name'] = ['type' => 'parameter', 'path' => '[session_management][storage_name]']; |
|
355
|
|
|
$parameters['oauth2_server.openid_connect.session_state_parameter_extension.template'] = ['type' => 'parameter', 'path' => '[session_management][template]']; |
|
356
|
|
|
$parameters['oauth2_server.openid_connect.session_state_parameter_extension.path'] = ['type' => 'parameter', 'path' => '[session_management][path]']; |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
$this->loadParameters($parameters, $pluginConfiguration, $container); |
|
360
|
|
|
|
|
361
|
|
|
$files[] = 'extensions/id_token_hint'; |
|
362
|
|
|
$files[] = 'extensions/max_age'; |
|
363
|
|
|
$files[] = 'extensions/prompt_login'; |
|
364
|
|
|
$files[] = 'extensions/prompt_none'; |
|
365
|
|
|
|
|
366
|
|
|
foreach ($files as $basename) { |
|
367
|
|
|
$loader->load(sprintf('%s.yml', $basename)); |
|
368
|
|
|
} |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
/** |
|
372
|
|
|
* {@inheritdoc} |
|
373
|
|
|
*/ |
|
374
|
|
|
public function build(ContainerBuilder $container) |
|
375
|
|
|
{ |
|
376
|
|
|
$container->addCompilerPass(new PairwiseSubjectIdentifierCompilerPass()); |
|
377
|
|
|
$container->addCompilerPass(new UserInfoScopeSupportCompilerPass()); |
|
378
|
|
|
$container->addCompilerPass(new UserInfoEndpointSignatureSupportCompilerPass()); |
|
379
|
|
|
$container->addCompilerPass(new JwksUriMetadataCompilerPass()); |
|
380
|
|
|
$container->addCompilerPass(new IdTokenMetadataCompilerPass()); |
|
381
|
|
|
$container->addCompilerPass(new IssuerDiscoveryCompilerPass()); |
|
382
|
|
|
$container->addCompilerPass(new ClaimSourceCompilerPass()); |
|
383
|
|
|
$container->addCompilerPass(new MetadataRouteCompilerPass()); |
|
384
|
|
|
$container->addCompilerPass(new UserinfoRouteCompilerPass()); |
|
385
|
|
|
$container->addCompilerPass(new SessionIFrameRouteCompilerPass()); |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* {@inheritdoc} |
|
390
|
|
|
*/ |
|
391
|
|
|
public function boot(ContainerInterface $container) |
|
392
|
|
|
{ |
|
393
|
|
|
$container->get('twig.loader')->addPath(__DIR__.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'views', 'OAuth2FrameworkServerBundle'); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
/** |
|
397
|
|
|
* {@inheritdoc} |
|
398
|
|
|
*/ |
|
399
|
|
|
public function prepend(ContainerBuilder $container) |
|
400
|
|
|
{ |
|
401
|
|
|
$config = current($container->getExtensionConfig('oauth2_server')); |
|
402
|
|
|
Assertion::keyExists($config, 'scope', 'The "ScopeManagerPlugin" must be enabled to use the OpenIdConnectPlugin.'); |
|
403
|
|
|
|
|
404
|
|
|
$config = current($container->getExtensionConfig('oauth2_server')); |
|
405
|
|
|
if (array_key_exists('token_endpoint', $config)) { |
|
406
|
|
|
foreach (['user_account_manager'] as $name) { |
|
407
|
|
|
$config[$this->name()][$name] = $config['token_endpoint'][$name]; |
|
408
|
|
|
} |
|
409
|
|
|
} |
|
410
|
|
|
if (array_key_exists('jwt_access_token', $config)) { |
|
411
|
|
|
$config[$this->name()]['id_token']['issuer'] = $config['jwt_access_token']['issuer']; |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
$this->prependJoseServices($container); |
|
415
|
|
|
|
|
416
|
|
|
$container->prependExtensionConfig('oauth2_server', $config); |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
/** |
|
420
|
|
|
* {@inheritdoc} |
|
421
|
|
|
*/ |
|
422
|
|
|
public function prependJoseServices(ContainerBuilder $container) |
|
423
|
|
|
{ |
|
424
|
|
|
$bundle_config = current($container->getExtensionConfig('oauth2_server'))[$this->name()]; |
|
425
|
|
|
$this->updateJoseBundleConfigurationForSigner($container, $this->name(), $bundle_config['id_token']); |
|
426
|
|
|
$this->updateJoseBundleConfigurationForVerifier($container, $this->name(), $bundle_config['id_token']); |
|
427
|
|
|
$this->updateJoseBundleConfigurationForChecker($container, $this->name(), $bundle_config['id_token']); |
|
428
|
|
|
$this->updateJoseBundleConfigurationForJWTCreator($container, $this->name()); |
|
429
|
|
|
$this->updateJoseBundleConfigurationForJWTLoader($container, $this->name()); |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
/** |
|
433
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
434
|
|
|
* @param string $service_name |
|
435
|
|
|
* @param array $bundle_config |
|
436
|
|
|
*/ |
|
437
|
|
|
private function updateJoseBundleConfigurationForSigner(ContainerBuilder $container, $service_name, array $bundle_config) |
|
438
|
|
|
{ |
|
439
|
|
|
ConfigurationHelper::addSigner($container, $service_name, [$bundle_config['signature_algorithm']], false); |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
/** |
|
443
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
444
|
|
|
* @param string $service_name |
|
445
|
|
|
* @param array $bundle_config |
|
446
|
|
|
*/ |
|
447
|
|
|
private function updateJoseBundleConfigurationForVerifier(ContainerBuilder $container, $service_name, array $bundle_config) |
|
448
|
|
|
{ |
|
449
|
|
|
ConfigurationHelper::addVerifier($container, $service_name, [$bundle_config['signature_algorithm']], false); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
/** |
|
453
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
454
|
|
|
* @param string $service_name |
|
455
|
|
|
* @param array $bundle_config |
|
456
|
|
|
*/ |
|
457
|
|
|
private function updateJoseBundleConfigurationForChecker(ContainerBuilder $container, $service_name, array $bundle_config) |
|
458
|
|
|
{ |
|
459
|
|
|
ConfigurationHelper::addChecker($container, $service_name, $bundle_config['header_checkers'], $bundle_config['claim_checkers'], false); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
/** |
|
463
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
464
|
|
|
* @param string $service_name |
|
465
|
|
|
*/ |
|
466
|
|
|
private function updateJoseBundleConfigurationForJWTCreator(ContainerBuilder $container, $service_name) |
|
467
|
|
|
{ |
|
468
|
|
|
$encrypter = null; |
|
469
|
|
|
ConfigurationHelper::addJWTCreator($container, $service_name, sprintf('jose.signer.%s', $service_name), $encrypter, false); |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
|
|
/** |
|
473
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
474
|
|
|
* @param string $service_name |
|
475
|
|
|
*/ |
|
476
|
|
|
private function updateJoseBundleConfigurationForJWTLoader(ContainerBuilder $container, $service_name) |
|
477
|
|
|
{ |
|
478
|
|
|
$decrypter = null; |
|
479
|
|
|
ConfigurationHelper::addJWTLoader($container, $service_name, sprintf('jose.verifier.%s', $service_name), sprintf('jose.checker.%s', $service_name), $decrypter, false); |
|
480
|
|
|
} |
|
481
|
|
|
} |
|
482
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: