|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2018 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\DependencyInjection\Component\OpenIdConnect; |
|
15
|
|
|
|
|
16
|
|
|
use Fluent\PhpConfigFileLoader; |
|
17
|
|
|
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper; |
|
18
|
|
|
use OAuth2Framework\Bundle\DependencyInjection\Component\Component; |
|
19
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
20
|
|
|
use Symfony\Component\Config\FileLocator; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
22
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
|
23
|
|
|
|
|
24
|
|
|
final class IdTokenSource implements Component |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* UserinfoSource constructor. |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->addSubSource(new IdTokenResponseTypeSource()); |
|
|
|
|
|
|
32
|
|
|
$this->addSubSource(new IdTokenEncryptionSource()); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function prepend(array $bundleConfig, string $path, ContainerBuilder $container) |
|
39
|
|
|
{ |
|
40
|
|
|
parent::prepend($bundleConfig, $path, $container); |
|
41
|
|
|
$currentPath = $path.'['.$this->name().']'; |
|
42
|
|
|
$accessor = PropertyAccess::createPropertyAccessor(); |
|
43
|
|
|
$sourceConfig = $accessor->getValue($bundleConfig, $currentPath); |
|
44
|
|
|
ConfigurationHelper::addJWSBuilder($container, $this->name(), $sourceConfig['signature_algorithms'], false); |
|
45
|
|
|
ConfigurationHelper::addJWSLoader($container, $this->name(), $sourceConfig['signature_algorithms'], [], ['jws_compact'], false); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
Assertion::keyExists($bundleConfig['key_set'], 'signature', 'The signature key set must be enabled.'); |
|
48
|
|
|
//ConfigurationHelper::addKeyset($container, 'id_token.key_set.signature', 'jwkset', ['value' => $bundleConfig['key_set']['signature']]); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
|
55
|
|
|
{ |
|
56
|
|
|
foreach (['lifetime', 'default_signature_algorithm', 'signature_algorithms', 'claim_checkers', 'header_checkers'] as $k) { |
|
57
|
|
|
$container->setParameter($path.'.'.$k, $config[$k]); |
|
58
|
|
|
} |
|
59
|
|
|
//$container->setAlias($path.'.key_set', 'jose.key_set.id_token.key_set.signature'); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$loader = new PhpConfigFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/openid_connect')); |
|
62
|
|
|
$loader->load('userinfo_scope_support.php'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
public function name(): string |
|
69
|
|
|
{ |
|
70
|
|
|
return 'id_token'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
|
74
|
|
|
{ |
|
75
|
|
|
|
|
76
|
|
|
$node |
|
77
|
|
|
->validate() |
|
78
|
|
|
->ifTrue(function ($config) { |
|
79
|
|
|
return empty($config['default_signature_algorithm']); |
|
80
|
|
|
}) |
|
81
|
|
|
->thenInvalid('The option "default_signature_algorithm" must be set.') |
|
82
|
|
|
->end() |
|
83
|
|
|
->validate() |
|
84
|
|
|
->ifTrue(function ($config) { |
|
85
|
|
|
return empty($config['signature_algorithms']); |
|
86
|
|
|
}) |
|
87
|
|
|
->thenInvalid('The option "signature_algorithm" must contain at least one signature algorithm.') |
|
88
|
|
|
->end() |
|
89
|
|
|
->validate() |
|
90
|
|
|
->ifTrue(function ($config) { |
|
91
|
|
|
return !in_array($config['default_signature_algorithm'], $config['signature_algorithms']); |
|
92
|
|
|
}) |
|
93
|
|
|
->thenInvalid('The default signature algorithm must be in the supported signature algorithms.') |
|
94
|
|
|
->end() |
|
95
|
|
|
->children() |
|
96
|
|
|
->scalarNode('default_signature_algorithm') |
|
97
|
|
|
->info('Signature algorithm used if the client has not defined a preferred one. Recommended value is "RS256".') |
|
98
|
|
|
->end() |
|
99
|
|
|
->arrayNode('signature_algorithms') |
|
100
|
|
|
->info('Signature algorithm used to sign the ID Tokens.') |
|
101
|
|
|
->useAttributeAsKey('name') |
|
102
|
|
|
->prototype('scalar')->end() |
|
103
|
|
|
->treatNullLike([]) |
|
104
|
|
|
->end() |
|
105
|
|
|
->arrayNode('claim_checkers') |
|
106
|
|
|
->info('Checkers will verify the JWT claims.') |
|
107
|
|
|
->useAttributeAsKey('name') |
|
108
|
|
|
->prototype('scalar')->end() |
|
109
|
|
|
->treatNullLike(['exp', 'iat', 'nbf']) |
|
110
|
|
|
->end() |
|
111
|
|
|
->arrayNode('header_checkers') |
|
112
|
|
|
->info('Checkers will verify the JWT headers.') |
|
113
|
|
|
->useAttributeAsKey('name') |
|
114
|
|
|
->prototype('scalar')->end() |
|
115
|
|
|
->treatNullLike(['crit']) |
|
116
|
|
|
->end() |
|
117
|
|
|
->integerNode('lifetime') |
|
118
|
|
|
->info('Lifetime of the ID Tokens (in seconds). If an access token is issued with the ID Token, the lifetime of the access token is used instead of this value.') |
|
119
|
|
|
->defaultValue(3600) |
|
120
|
|
|
->min(1) |
|
121
|
|
|
->end() |
|
122
|
|
|
->end(); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|