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 Jose\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement\JWKSource; |
15
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\DependencyInjection\Source\AbstractSource; |
17
|
|
|
use Jose\Component\KeyManagement\JWKFactory; |
18
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
21
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Secret. |
25
|
|
|
*/ |
26
|
|
|
final class Secret extends AbstractSource implements JWKSource |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function createDefinition(ContainerBuilder $container, array $config): Definition |
32
|
|
|
{ |
33
|
|
|
$definition = new Definition(JWK::class); |
34
|
|
|
$definition->setFactory([ |
35
|
|
|
new Reference(JWKFactory::class), |
36
|
|
|
'createFromSecret', |
37
|
|
|
]); |
38
|
|
|
$definition->setArguments([ |
39
|
|
|
$config['secret'], |
40
|
|
|
$config['additional_values'], |
41
|
|
|
]); |
42
|
|
|
$definition->addTag('jose.jwk'); |
43
|
|
|
|
44
|
|
|
return $definition; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function getKey(): string |
51
|
|
|
{ |
52
|
|
|
return 'secret'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function addConfiguration(NodeDefinition $node) |
59
|
|
|
{ |
60
|
|
|
parent::addConfiguration($node); |
61
|
|
|
$node |
62
|
|
|
->children() |
63
|
|
|
->scalarNode('secret') |
64
|
|
|
->info('The shared secret.') |
65
|
|
|
->isRequired() |
66
|
|
|
->end() |
67
|
|
|
->arrayNode('additional_values') |
68
|
|
|
->info('Additional values to be added to the key.') |
69
|
|
|
->defaultValue([]) |
70
|
|
|
->useAttributeAsKey('key') |
71
|
|
|
->prototype('variable')->end() |
72
|
|
|
->end() |
73
|
|
|
->end(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|