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\Component\ClientAuthentication; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\Component\Component; |
17
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
18
|
|
|
use Symfony\Component\Config\FileLocator; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
21
|
|
|
|
22
|
|
|
class ClientAssertionJwtSource implements Component |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @return string |
26
|
|
|
*/ |
27
|
|
|
public function name(): string |
28
|
|
|
{ |
29
|
|
|
return 'client_assertion_jwt'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function load(array $configs, ContainerBuilder $container) |
36
|
|
|
{ |
37
|
|
|
if ($configs['client_authentication']['client_assertion_jwt']['enabled']) { |
38
|
|
|
$container->setParameter('oauth2_server.client_authentication.client_assertion_jwt.secret_lifetime', $configs['client_authentication']['client_assertion_jwt']['secret_lifetime']); |
39
|
|
|
$container->setParameter('oauth2_server.client_authentication.client_assertion_jwt.signature_algorithms', $configs['client_authentication']['client_assertion_jwt']['signature_algorithms']); |
40
|
|
|
$container->setParameter('oauth2_server.client_authentication.client_assertion_jwt.claim_checkers', $configs['client_authentication']['client_assertion_jwt']['claim_checkers']); |
41
|
|
|
$container->setParameter('oauth2_server.client_authentication.client_assertion_jwt.header_checkers', $configs['client_authentication']['client_assertion_jwt']['header_checkers']); |
42
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config/client_authentication')); |
43
|
|
|
$loader->load('client_assertion_jwt.php'); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
51
|
|
|
{ |
52
|
|
|
$node->children() |
53
|
|
|
->arrayNode($this->name()) |
54
|
|
|
->addDefaultsIfNotSet() |
55
|
|
|
->canBeEnabled() |
56
|
|
|
->info('This method comprises the "client_secret_jwt" and the "private_key_jwt" authentication methods') |
57
|
|
|
->validate() |
58
|
|
|
->ifTrue(function ($config) { |
59
|
|
|
return $config['enabled'] && empty($config['signature_algorithms']); |
60
|
|
|
}) |
61
|
|
|
->thenInvalid('At least one signature algorithm must be set.') |
62
|
|
|
->end() |
63
|
|
|
->children() |
64
|
|
|
->integerNode('secret_lifetime') |
65
|
|
|
->info('Secret lifetime (in seconds; 0 = unlimited) applicable to the "client_secret_jwt" authentication method') |
66
|
|
|
->defaultValue(60 * 60 * 24 * 14) |
67
|
|
|
->min(0) |
68
|
|
|
->end() |
69
|
|
|
->arrayNode('signature_algorithms') |
70
|
|
|
->info('Supported signature algorithms.') |
71
|
|
|
->useAttributeAsKey('name') |
72
|
|
|
->prototype('scalar')->end() |
73
|
|
|
->treatNullLike([]) |
74
|
|
|
->end() |
75
|
|
|
->arrayNode('claim_checkers') |
76
|
|
|
->info('Claim checkers for incoming assertions.') |
77
|
|
|
->useAttributeAsKey('name') |
78
|
|
|
->prototype('scalar')->end() |
79
|
|
|
->treatNullLike([]) |
80
|
|
|
->end() |
81
|
|
|
->arrayNode('header_checkers') |
82
|
|
|
->info('Header checkers for incoming assertions.') |
83
|
|
|
->useAttributeAsKey('name') |
84
|
|
|
->prototype('scalar')->end() |
85
|
|
|
->treatNullLike([]) |
86
|
|
|
->end() |
87
|
|
|
->arrayNode('encryption') |
88
|
|
|
->canBeEnabled() |
89
|
|
|
->validate() |
90
|
|
|
->ifTrue(function ($config) { |
91
|
|
|
return true === $config['enabled'] && empty($config['key_encryption_algorithms']); |
92
|
|
|
}) |
93
|
|
|
->thenInvalid('At least one key encryption algorithm must be set.') |
94
|
|
|
->end() |
95
|
|
|
->validate() |
96
|
|
|
->ifTrue(function ($config) { |
97
|
|
|
return true === $config['enabled'] && empty($config['content_encryption_algorithms']); |
98
|
|
|
}) |
99
|
|
|
->thenInvalid('At least one content encryption algorithm must be set.') |
100
|
|
|
->end() |
101
|
|
|
->children() |
102
|
|
|
->booleanNode('required') |
103
|
|
|
->info('When true, all incoming assertions must be encrypted.') |
104
|
|
|
->defaultFalse() |
105
|
|
|
->end() |
106
|
|
|
->arrayNode('key_encryption_algorithms') |
107
|
|
|
->info('Supported key encryption algorithms.') |
108
|
|
|
->useAttributeAsKey('name') |
109
|
|
|
->prototype('scalar')->end() |
110
|
|
|
->treatNullLike([]) |
111
|
|
|
->end() |
112
|
|
|
->arrayNode('content_encryption_algorithms') |
113
|
|
|
->info('Supported content encryption algorithms.') |
114
|
|
|
->useAttributeAsKey('name') |
115
|
|
|
->prototype('scalar')->end() |
116
|
|
|
->treatNullLike([]) |
117
|
|
|
->end() |
118
|
|
|
->end() |
119
|
|
|
->end() |
120
|
|
|
->end() |
121
|
|
|
->end() |
122
|
|
|
->end(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* {@inheritdoc} |
127
|
|
|
*/ |
128
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
129
|
|
|
{ |
130
|
|
|
return []; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* {@inheritdoc} |
135
|
|
|
*/ |
136
|
|
|
public function build(ContainerBuilder $container) |
137
|
|
|
{ |
138
|
|
|
//Nothing to do |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|