|
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 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 ClientAssertionJwtTokenEndpointAuthMethodSource implements Component |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* ClientAssertionJwtTokenEndpointAuthMethodSource constructor. |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->addSubSource(new ClientAssertionJwtTokenEndpointAuthMethodEncryptionSupportSource()); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
|
38
|
|
|
{ |
|
39
|
|
|
$container->setParameter($path.'.signature_algorithms', $config['signature_algorithms']); |
|
40
|
|
|
$container->setParameter($path.'.claim_checkers', $config['claim_checkers']); |
|
41
|
|
|
$container->setParameter($path.'.header_checkers', $config['header_checkers']); |
|
42
|
|
|
$container->setParameter($path.'.secret_lifetime', $config['secret_lifetime']); |
|
43
|
|
|
|
|
44
|
|
|
$loader = new PhpConfigFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/token_endpoint_auth_method')); |
|
45
|
|
|
$loader->load('client_assertion_jwt.php'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function name(): string |
|
52
|
|
|
{ |
|
53
|
|
|
return 'client_assertion_jwt'; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
|
60
|
|
|
{ |
|
61
|
|
|
|
|
62
|
|
|
$node |
|
|
|
|
|
|
63
|
|
|
->validate() |
|
64
|
|
|
->ifTrue(function ($config) { |
|
65
|
|
|
return true === $config['enabled'] && empty($config['signature_algorithms']); |
|
66
|
|
|
}) |
|
67
|
|
|
->thenInvalid('At least one signature algorithm must be set.') |
|
68
|
|
|
->end() |
|
69
|
|
|
->children() |
|
70
|
|
|
->integerNode('secret_lifetime')->defaultValue(60 * 60 * 24 * 14)->min(0)->end() |
|
71
|
|
|
->arrayNode('signature_algorithms') |
|
72
|
|
|
->info('Supported signature algorithms.') |
|
73
|
|
|
->useAttributeAsKey('name') |
|
74
|
|
|
->prototype('scalar')->end() |
|
75
|
|
|
->treatNullLike([]) |
|
76
|
|
|
->end() |
|
77
|
|
|
->arrayNode('claim_checkers') |
|
78
|
|
|
->info('Claim checkers for incoming assertions.') |
|
79
|
|
|
->useAttributeAsKey('name') |
|
80
|
|
|
->prototype('scalar')->end() |
|
81
|
|
|
->treatNullLike([]) |
|
82
|
|
|
->end() |
|
83
|
|
|
->arrayNode('header_checkers') |
|
84
|
|
|
->info('Header checkers for incoming assertions.') |
|
85
|
|
|
->useAttributeAsKey('name') |
|
86
|
|
|
->prototype('scalar')->end() |
|
87
|
|
|
->treatNullLike([]) |
|
88
|
|
|
->end() |
|
89
|
|
|
->end(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
|
|
public function prepend(array $bundleConfig, string $path, ContainerBuilder $container) |
|
96
|
|
|
{ |
|
97
|
|
|
parent::prepend($bundleConfig, $path, $container); |
|
98
|
|
|
$currentPath = $path.'['.$this->name().']'; |
|
99
|
|
|
$accessor = PropertyAccess::createPropertyAccessor(); |
|
100
|
|
|
$sourceConfig = $accessor->getValue($bundleConfig, $currentPath); |
|
101
|
|
|
if (true === $sourceConfig['enabled']) { |
|
102
|
|
|
$this->updateJoseBundleConfigurationForVerifier($container, $sourceConfig); |
|
103
|
|
|
$this->updateJoseBundleConfigurationForDecrypter($container, $sourceConfig); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param ContainerBuilder $container |
|
109
|
|
|
* @param array $sourceConfig |
|
110
|
|
|
*/ |
|
111
|
|
|
private function updateJoseBundleConfigurationForVerifier(ContainerBuilder $container, array $sourceConfig) |
|
112
|
|
|
{ |
|
113
|
|
|
ConfigurationHelper::addJWSLoader($container, $this->name(), $sourceConfig['signature_algorithms'], [], ['jws_compact'], false); |
|
|
|
|
|
|
114
|
|
|
ConfigurationHelper::addClaimChecker($container, $this->name(), [], false); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param ContainerBuilder $container |
|
119
|
|
|
* @param array $sourceConfig |
|
120
|
|
|
*/ |
|
121
|
|
|
private function updateJoseBundleConfigurationForDecrypter(ContainerBuilder $container, array $sourceConfig) |
|
122
|
|
|
{ |
|
123
|
|
|
if (true === $sourceConfig['encryption']['enabled']) { |
|
124
|
|
|
ConfigurationHelper::addJWELoader($container, $this->name(), $sourceConfig['encryption']['key_encryption_algorithms'], $sourceConfig['encryption']['content_encryption_algorithms'], ['DEF'], [], ['jwe_compact'], false); |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|