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\TokenEndpointAuthMethod; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\DependencyInjection\Component\Component; |
17
|
|
|
use OAuth2Framework\Component\TokenEndpoint\AuthenticationMethod\AuthenticationMethod; |
18
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
19
|
|
|
use Symfony\Component\Config\FileLocator; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
22
|
|
|
|
23
|
|
|
final class TokenEndpointAuthMethodSource implements Component |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
public function name(): string |
29
|
|
|
{ |
30
|
|
|
return 'token_endpoint_auth_method'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function load(array $configs, ContainerBuilder $container) |
37
|
|
|
{ |
38
|
|
|
$container->registerForAutoconfiguration(AuthenticationMethod::class)->addTag('oauth2_server_token_endpoint_auth_method'); |
39
|
|
|
|
40
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/token_endpoint_auth_method')); |
41
|
|
|
$loader->load('token_endpoint_auth_method.php'); |
42
|
|
|
|
43
|
|
|
if ($configs['token_endpoint_auth_method']['none']['enabled']) { |
44
|
|
|
$loader->load('none.php'); |
45
|
|
|
} |
46
|
|
|
if ($configs['token_endpoint_auth_method']['client_secret_basic']['enabled']) { |
47
|
|
|
$container->setParameter('oauth2_server.token_endpoint_auth_method.client_secret_basic.realm', $configs['token_endpoint_auth_method']['client_secret_basic']['realm']); |
48
|
|
|
$container->setParameter('oauth2_server.token_endpoint_auth_method.client_secret_basic.secret_lifetime', $configs['token_endpoint_auth_method']['client_secret_basic']['secret_lifetime']); |
49
|
|
|
$loader->load('client_secret_basic.php'); |
50
|
|
|
} |
51
|
|
|
if ($configs['token_endpoint_auth_method']['client_secret_post']['enabled']) { |
52
|
|
|
$container->setParameter('oauth2_server.token_endpoint_auth_method.client_secret_post.secret_lifetime', $configs['token_endpoint_auth_method']['client_secret_post']['secret_lifetime']); |
53
|
|
|
$loader->load('client_secret_post.php'); |
54
|
|
|
} |
55
|
|
|
if ($configs['token_endpoint_auth_method']['client_assertion_jwt']['enabled']) { |
56
|
|
|
$container->setParameter('oauth2_server.token_endpoint_auth_method.client_assertion_jwt.secret_lifetime', $configs['token_endpoint_auth_method']['client_assertion_jwt']['secret_lifetime']); |
57
|
|
|
$container->setParameter('oauth2_server.token_endpoint_auth_method.client_assertion_jwt.signature_algorithms', $configs['token_endpoint_auth_method']['client_assertion_jwt']['signature_algorithms']); |
58
|
|
|
$container->setParameter('oauth2_server.token_endpoint_auth_method.client_assertion_jwt.claim_checkers', $configs['token_endpoint_auth_method']['client_assertion_jwt']['claim_checkers']); |
59
|
|
|
$container->setParameter('oauth2_server.token_endpoint_auth_method.client_assertion_jwt.header_checkers', $configs['token_endpoint_auth_method']['client_assertion_jwt']['header_checkers']); |
60
|
|
|
$loader->load('client_assertion_jwt.php'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
68
|
|
|
{ |
69
|
|
|
$node->children() |
70
|
|
|
->arrayNode($this->name()) |
71
|
|
|
->addDefaultsIfNotSet() |
72
|
|
|
->children() |
73
|
|
|
->arrayNode('none') |
74
|
|
|
->info('The "none" authentication method is designed for public clients') |
75
|
|
|
->canBeEnabled() |
76
|
|
|
->end() |
77
|
|
|
->arrayNode('client_secret_basic') |
78
|
|
|
->canBeEnabled() |
79
|
|
|
->children() |
80
|
|
|
->scalarNode('realm') |
81
|
|
|
->isRequired() |
82
|
|
|
->info('The realm displayed in the authentication header') |
83
|
|
|
->end() |
84
|
|
|
->integerNode('secret_lifetime') |
85
|
|
|
->defaultValue(60 * 60 * 24 * 14) |
86
|
|
|
->min(0) |
87
|
|
|
->info('Secret lifetime (in seconds; 0 = unlimited)') |
88
|
|
|
->end() |
89
|
|
|
->end() |
90
|
|
|
->end() |
91
|
|
|
->arrayNode('client_secret_post') |
92
|
|
|
->canBeEnabled() |
93
|
|
|
->children() |
94
|
|
|
->integerNode('secret_lifetime') |
95
|
|
|
->defaultValue(60 * 60 * 24 * 14) |
96
|
|
|
->min(0) |
97
|
|
|
->info('Secret lifetime (in seconds; 0 = unlimited)') |
98
|
|
|
->end() |
99
|
|
|
->end() |
100
|
|
|
->end() |
101
|
|
|
->arrayNode('client_assertion_jwt') |
102
|
|
|
->canBeEnabled() |
103
|
|
|
->info('This method comprises the "client_secret_jwt" and the "private_key_jwt" authentication methods') |
104
|
|
|
->validate() |
105
|
|
|
->ifTrue(function ($config) { |
106
|
|
|
return true === $config['enabled'] && empty($config['signature_algorithms']); |
107
|
|
|
}) |
108
|
|
|
->thenInvalid('At least one signature algorithm must be set.') |
109
|
|
|
->end() |
110
|
|
|
->children() |
111
|
|
|
->integerNode('secret_lifetime') |
112
|
|
|
->info('Secret lifetime (in seconds; 0 = unlimited) applicable to the "client_secret_jwt" authentication method') |
113
|
|
|
->defaultValue(60 * 60 * 24 * 14) |
114
|
|
|
->min(0) |
115
|
|
|
->end() |
116
|
|
|
->arrayNode('signature_algorithms') |
117
|
|
|
->info('Supported signature algorithms.') |
118
|
|
|
->useAttributeAsKey('name') |
119
|
|
|
->prototype('scalar')->end() |
120
|
|
|
->treatNullLike([]) |
121
|
|
|
->end() |
122
|
|
|
->arrayNode('claim_checkers') |
123
|
|
|
->info('Claim checkers for incoming assertions.') |
124
|
|
|
->useAttributeAsKey('name') |
125
|
|
|
->prototype('scalar')->end() |
126
|
|
|
->treatNullLike([]) |
127
|
|
|
->end() |
128
|
|
|
->arrayNode('header_checkers') |
129
|
|
|
->info('Header checkers for incoming assertions.') |
130
|
|
|
->useAttributeAsKey('name') |
131
|
|
|
->prototype('scalar')->end() |
132
|
|
|
->treatNullLike([]) |
133
|
|
|
->end() |
134
|
|
|
->arrayNode('encryption') |
135
|
|
|
->canBeEnabled() |
136
|
|
|
->validate() |
137
|
|
|
->ifTrue(function ($config) { |
138
|
|
|
return true === $config['enabled'] && empty($config['key_encryption_algorithms']); |
139
|
|
|
}) |
140
|
|
|
->thenInvalid('At least one key encryption algorithm must be set.') |
141
|
|
|
->end() |
142
|
|
|
->validate() |
143
|
|
|
->ifTrue(function ($config) { |
144
|
|
|
return true === $config['enabled'] && empty($config['content_encryption_algorithms']); |
145
|
|
|
}) |
146
|
|
|
->thenInvalid('At least one content encryption algorithm must be set.') |
147
|
|
|
->end() |
148
|
|
|
->children() |
149
|
|
|
->booleanNode('required') |
150
|
|
|
->info('When true, all incoming assertions must be encrypted.') |
151
|
|
|
->defaultFalse() |
152
|
|
|
->end() |
153
|
|
|
->arrayNode('key_encryption_algorithms') |
154
|
|
|
->info('Supported key encryption algorithms.') |
155
|
|
|
->useAttributeAsKey('name') |
156
|
|
|
->prototype('scalar')->end() |
157
|
|
|
->treatNullLike([]) |
158
|
|
|
->end() |
159
|
|
|
->arrayNode('content_encryption_algorithms') |
160
|
|
|
->info('Supported content encryption algorithms.') |
161
|
|
|
->useAttributeAsKey('name') |
162
|
|
|
->prototype('scalar')->end() |
163
|
|
|
->treatNullLike([]) |
164
|
|
|
->end() |
165
|
|
|
->end() |
166
|
|
|
->end() |
167
|
|
|
->end() |
168
|
|
|
->end() |
169
|
|
|
->end() |
170
|
|
|
->end() |
171
|
|
|
->end(); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* {@inheritdoc} |
176
|
|
|
*/ |
177
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
178
|
|
|
{ |
179
|
|
|
//Nothing to do |
180
|
|
|
return []; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|