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\DependencyInjection\Source\OpenIdConnect; |
15
|
|
|
|
16
|
|
|
use Fluent\PhpConfigFileLoader; |
17
|
|
|
use OAuth2Framework\Bundle\Server\DependencyInjection\Source\ActionableSource; |
18
|
|
|
use OAuth2Framework\Bundle\Server\DependencyInjection\Source\SourceInterface; |
19
|
|
|
use Symfony\Component\Config\FileLocator; |
20
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
|
23
|
|
|
final class OpenIdConnectSource extends ActionableSource |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var SourceInterface[] |
27
|
|
|
*/ |
28
|
|
|
private $subSources; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* OpenIdConnectSource constructor. |
32
|
|
|
*/ |
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
$this->subSources = [ |
36
|
|
|
new UserinfoEndpointSource(), |
37
|
|
|
new IdTokenSource(), |
38
|
|
|
new AuthorizationEndpointIdTokenHintSource(), |
39
|
|
|
new PairwiseSubjectSource(), |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
protected function name(): string |
47
|
|
|
{ |
48
|
|
|
return 'openid_connect'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
55
|
|
|
{ |
56
|
|
|
foreach ($this->subSources as $source) { |
57
|
|
|
$source->load($path, $container, $config); |
58
|
|
|
} |
59
|
|
|
foreach (['claims_supported', 'claims_locales_supported'] as $k) { |
60
|
|
|
$container->setParameter($path.'.'.$k, $config[$k]); |
61
|
|
|
} |
62
|
|
|
$loader = new PhpConfigFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/openid_connect')); |
63
|
|
|
$loader->load('openid_connect.php'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function prepend(array $bundleConfig, string $path, ContainerBuilder $container) |
67
|
|
|
{ |
68
|
|
|
parent::prepend($bundleConfig, $path, $container); |
69
|
|
|
foreach ($this->subSources as $source) { |
70
|
|
|
$source->prepend($bundleConfig, $path.'['.$this->name().']', $container); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
protected function continueConfiguration(NodeDefinition $node) |
78
|
|
|
{ |
79
|
|
|
parent::continueConfiguration($node); |
80
|
|
|
$node |
|
|
|
|
81
|
|
|
->children() |
82
|
|
|
->arrayNode('claims_supported') |
83
|
|
|
->info('Supported claims.') |
84
|
|
|
->useAttributeAsKey('name') |
85
|
|
|
->prototype('scalar')->end() |
86
|
|
|
->treatNullLike([]) |
87
|
|
|
->end() |
88
|
|
|
->arrayNode('claims_locales_supported') |
89
|
|
|
->info('Supported claims locales.') |
90
|
|
|
->useAttributeAsKey('name') |
91
|
|
|
->prototype('scalar')->end() |
92
|
|
|
->treatNullLike([]) |
93
|
|
|
->end() |
94
|
|
|
->end(); |
95
|
|
|
foreach ($this->subSources as $source) { |
96
|
|
|
$source->addConfiguration($node); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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: