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