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\Component\ClientAuthentication; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\Component\Component; |
17
|
|
|
use OAuth2Framework\Bundle\Component\ComponentWithCompilerPasses; |
18
|
|
|
use OAuth2Framework\Component\ClientAuthentication\AuthenticationMethod; |
19
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
20
|
|
|
use Symfony\Component\Config\FileLocator; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
23
|
|
|
|
24
|
|
|
class ClientAuthenticationSource implements Component |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var Component[] |
28
|
|
|
*/ |
29
|
|
|
private $subComponents = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* EndpointSource constructor. |
33
|
|
|
*/ |
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
$this->subComponents = [ |
37
|
|
|
new NoneSource(), |
38
|
|
|
new ClientSecretBasicSource(), |
39
|
|
|
new ClientSecretPostSource(), |
40
|
|
|
new ClientAssertionJwtSource(), |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function name(): string |
48
|
|
|
{ |
49
|
|
|
return 'client_authentication'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function load(array $configs, ContainerBuilder $container) |
56
|
|
|
{ |
57
|
|
|
$container->registerForAutoconfiguration(AuthenticationMethod::class)->addTag('oauth2_server_client_authentication'); |
58
|
|
|
|
59
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config/client_authentication')); |
60
|
|
|
$loader->load('client_authentication.php'); |
61
|
|
|
|
62
|
|
|
foreach ($this->subComponents as $subComponent) { |
63
|
|
|
$subComponent->load($configs, $container); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
71
|
|
|
{ |
72
|
|
|
$childNode = $node->children() |
73
|
|
|
->arrayNode($this->name()) |
74
|
|
|
->addDefaultsIfNotSet(); |
75
|
|
|
|
76
|
|
|
foreach ($this->subComponents as $subComponent) { |
77
|
|
|
$subComponent->getNodeDefinition($childNode); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
85
|
|
|
{ |
86
|
|
|
$updatedConfig = []; |
87
|
|
|
foreach ($this->subComponents as $subComponent) { |
88
|
|
|
$updatedConfig = array_merge( |
89
|
|
|
$updatedConfig, |
90
|
|
|
$subComponent->prepend($container, $config) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $updatedConfig; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function build(ContainerBuilder $container) |
101
|
|
|
{ |
102
|
|
|
foreach ($this->subComponents as $component) { |
103
|
|
|
$component->build($container); |
104
|
|
|
}; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|