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\Endpoint; |
15
|
|
|
|
16
|
|
|
use Fluent\PhpConfigFileLoader; |
17
|
|
|
use OAuth2Framework\Bundle\DependencyInjection\Component\Component; |
18
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
19
|
|
|
use Symfony\Component\Config\FileLocator; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
|
22
|
|
|
final class MetadataEndpointSource implements Component |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* MetadataEndpointSource constructor. |
26
|
|
|
*/ |
27
|
|
|
public function __construct() |
28
|
|
|
{ |
29
|
|
|
$this->addSubSource(new SignedMetadataEndpointSource()); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
36
|
|
|
{ |
37
|
|
|
foreach (['path', 'custom_values', 'custom_routes'] as $key) { |
38
|
|
|
$container->setParameter($path.'.'.$key, $config[$key]); |
39
|
|
|
} |
40
|
|
|
$loader = new PhpConfigFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint')); |
41
|
|
|
$loader->load('metadata.php'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function name(): string |
48
|
|
|
{ |
49
|
|
|
return 'metadata'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
56
|
|
|
{ |
57
|
|
|
|
58
|
|
|
$node |
|
|
|
|
59
|
|
|
->validate() |
60
|
|
|
->ifTrue(function ($config) { |
61
|
|
|
return true === $config['enabled'] && empty($config['path']); |
62
|
|
|
}) |
63
|
|
|
->thenInvalid('The route name must be set.') |
64
|
|
|
->end() |
65
|
|
|
->children() |
66
|
|
|
->scalarNode('path')->defaultValue('/.well-known/openid-configuration')->end() |
67
|
|
|
->arrayNode('custom_routes') |
68
|
|
|
->info('Custom routes added to the metadata response.') |
69
|
|
|
->useAttributeAsKey('name') |
70
|
|
|
->prototype('array') |
71
|
|
|
->children() |
72
|
|
|
->scalarNode('route_name') |
73
|
|
|
->info('Route name.') |
74
|
|
|
->isRequired() |
75
|
|
|
->end() |
76
|
|
|
->arrayNode('route_parameters') |
77
|
|
|
->info('Parameters associated to the route (if needed).') |
78
|
|
|
->useAttributeAsKey('name') |
79
|
|
|
->prototype('variable')->end() |
80
|
|
|
->treatNullLike([]) |
81
|
|
|
->end() |
82
|
|
|
->end() |
83
|
|
|
->end() |
84
|
|
|
->treatNullLike([]) |
85
|
|
|
->end() |
86
|
|
|
->arrayNode('custom_values') |
87
|
|
|
->info('Custom values added to the metadata response.') |
88
|
|
|
->useAttributeAsKey('name') |
89
|
|
|
->prototype('variable')->end() |
90
|
|
|
->treatNullLike([]) |
91
|
|
|
->end() |
92
|
|
|
->end(); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|