|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License (MIT) |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
|
7
|
|
|
* |
|
8
|
|
|
* This software may be modified and distributed under the terms |
|
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSetSource; |
|
13
|
|
|
|
|
14
|
|
|
use SpomkyLabs\JoseBundle\DependencyInjection\Source\AbstractSource; |
|
15
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
19
|
|
|
|
|
20
|
|
|
abstract class AbstractJWKSetSource extends AbstractSource implements JWKSetSourceInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
public function create(ContainerBuilder $container, $type, $name, array $config) |
|
26
|
|
|
{ |
|
27
|
|
|
parent::create($container, $type, $name, $config); |
|
28
|
|
|
|
|
29
|
|
|
if (null !== $config['path']) { |
|
30
|
|
|
$jwkset_id = 'jose.key_set.'.$name; |
|
31
|
|
|
$controller_definition = new Definition('SpomkyLabs\JoseBundle\Controller\JWKSetController'); |
|
32
|
|
|
$controller_definition->setFactory([new Reference('jose.controller.jwkset_controllery_factory'), 'createJWKSetController']); |
|
33
|
|
|
$controller_definition->setArguments([new Reference($jwkset_id)]); |
|
34
|
|
|
$controller_id = 'jose.controller.'.$name; |
|
35
|
|
|
$container->setDefinition($controller_id, $controller_definition); |
|
36
|
|
|
|
|
37
|
|
|
$jwkset_loader_definition = $container->getDefinition('jose.routing.jwkset_loader'); |
|
38
|
|
|
$jwkset_loader_definition->addMethodCall('addJWKSetRoute', [$config['path'], $name]); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\NodeDefinition $node |
|
44
|
|
|
*/ |
|
45
|
|
|
public function addConfiguration(NodeDefinition $node) |
|
46
|
|
|
{ |
|
47
|
|
|
parent::addConfiguration($node); |
|
48
|
|
|
$node |
|
49
|
|
|
->children() |
|
50
|
|
|
->scalarNode('path') |
|
51
|
|
|
->info('To share the JWKSet, then set a valid path (e.g. "/jwkset.json").') |
|
52
|
|
|
->defaultNull() |
|
53
|
|
|
->end() |
|
54
|
|
|
->end(); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|