1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 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\JWKSetSource; |
15
|
|
|
|
16
|
|
|
use Jose\Bundle\JoseFramework\Controller\JWKSetController; |
17
|
|
|
use Jose\Bundle\JoseFramework\Controller\JWKSetControllerFactory; |
18
|
|
|
use Jose\Bundle\JoseFramework\DependencyInjection\Source\AbstractSource; |
19
|
|
|
use Jose\Bundle\JoseFramework\Routing\JWKSetLoader; |
20
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
23
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class AbstractJWKSetSource. |
27
|
|
|
*/ |
28
|
|
|
abstract class AbstractJWKSetSource extends AbstractSource implements JWKSetSourceInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function create(ContainerBuilder $container, string $type, string $name, array $config) |
34
|
|
|
{ |
35
|
|
|
parent::create($container, $type, $name, $config); |
36
|
|
|
|
37
|
|
|
if (null !== $config['path']) { |
38
|
|
|
$jwkset_id = sprintf('jose.key_set.%s', $name); |
39
|
|
|
$controller_definition = new Definition(JWKSetController::class); |
40
|
|
|
$controller_definition->setFactory([new Reference(JWKSetControllerFactory::class), 'create']); |
41
|
|
|
$controller_definition->setArguments([new Reference($jwkset_id), $config['max_age']]); |
42
|
|
|
$controller_id = sprintf('jose.controller.%s', $name); |
43
|
|
|
$container->setDefinition($controller_id, $controller_definition); |
44
|
|
|
|
45
|
|
|
$jwkset_loader_definition = $container->getDefinition(JWKSetLoader::class); |
46
|
|
|
$jwkset_loader_definition->addMethodCall('add', [$config['path'], $name]); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param NodeDefinition $node |
52
|
|
|
*/ |
53
|
|
|
public function addConfiguration(NodeDefinition $node) |
54
|
|
|
{ |
55
|
|
|
parent::addConfiguration($node); |
56
|
|
|
$node |
57
|
|
|
->children() |
58
|
|
|
->scalarNode('path') |
59
|
|
|
->info('To share the JWKSet, then set a valid path (e.g. "/jwkset.json").') |
60
|
|
|
->defaultNull() |
61
|
|
|
->end() |
62
|
|
|
->integerNode('max_age') |
63
|
|
|
->info('When share, this value indicates how many seconds the HTTP client should keep the key in cache. Default is 21600 = 6 hours.') |
64
|
|
|
->defaultValue(21600) |
65
|
|
|
->end() |
66
|
|
|
->end(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|