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 Assert\Assertion; |
17
|
|
|
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper; |
18
|
|
|
use OAuth2Framework\Bundle\Server\DependencyInjection\Source\ActionableSource; |
19
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
22
|
|
|
|
23
|
|
|
final class UserinfoEndpointSignatureSource extends ActionableSource |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected function name(): string |
29
|
|
|
{ |
30
|
|
|
return 'signature'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
37
|
|
|
{ |
38
|
|
|
$container->setParameter($path.'.signature_algorithms', $config['signature_algorithms']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
protected function continueConfiguration(NodeDefinition $node) |
45
|
|
|
{ |
46
|
|
|
parent::continueConfiguration($node); |
47
|
|
|
$node |
|
|
|
|
48
|
|
|
->validate() |
49
|
|
|
->ifTrue(function ($config) { |
50
|
|
|
return true === $config['enabled'] && empty($config['signature_algorithms']); |
51
|
|
|
}) |
52
|
|
|
->thenInvalid('You must set at least one signature algorithm.') |
53
|
|
|
->end() |
54
|
|
|
->children() |
55
|
|
|
->arrayNode('signature_algorithms') |
56
|
|
|
->info('Signature algorithm used to sign the user information.') |
57
|
|
|
->useAttributeAsKey('name') |
58
|
|
|
->prototype('scalar')->end() |
59
|
|
|
->treatNullLike([]) |
60
|
|
|
->end() |
61
|
|
|
->end(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function prepend(array $bundleConfig, string $path, ContainerBuilder $container) |
68
|
|
|
{ |
69
|
|
|
parent::prepend($bundleConfig, $path, $container); |
70
|
|
|
Assertion::keyExists($bundleConfig['key_set'], 'signature', 'The signature key set must be enabled.'); |
71
|
|
|
$currentPath = $path.'['.$this->name().']'; |
72
|
|
|
$accessor = PropertyAccess::createPropertyAccessor(); |
73
|
|
|
$sourceConfig = $accessor->getValue($bundleConfig, $currentPath); |
74
|
|
|
|
75
|
|
|
ConfigurationHelper::addJWSBuilder($container, 'oauth2_server.userinfo', $sourceConfig['signature_algorithms'], false); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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: