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\Scope; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\DependencyInjection\Component\Component; |
17
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
18
|
|
|
use Symfony\Component\Config\FileLocator; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
21
|
|
|
|
22
|
|
|
final class ScopeSource implements Component |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function name(): string |
28
|
|
|
{ |
29
|
|
|
return 'scope'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function load(array $configs, ContainerBuilder $container) |
36
|
|
|
{ |
37
|
|
|
if (!$configs['scope']['enabled']) { |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
$container->setAlias('oauth2_server.scope.repository', $configs['scope']['repository']); |
41
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/scope')); |
42
|
|
|
$loader->load('scope.php'); |
43
|
|
|
|
44
|
|
|
if (!$configs['scope']['policy']['enabled']) { |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
$container->setParameter('oauth2_server.scope.policy.by_default', $configs['scope']['policy']['by_default']); |
48
|
|
|
$loader->load('policy.php'); |
49
|
|
|
|
50
|
|
|
if ($configs['scope']['policy']['default']['enabled']) { |
51
|
|
|
$container->setParameter('oauth2_server.scope.policy.default.scope', $configs['scope']['policy']['default']['scope']); |
52
|
|
|
$loader->load('policy_default.php'); |
53
|
|
|
} |
54
|
|
|
if ($configs['scope']['policy']['error']['enabled']) { |
55
|
|
|
$loader->load('policy_error.php'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
63
|
|
|
{ |
64
|
|
|
$node->children() |
65
|
|
|
->arrayNode($this->name()) |
66
|
|
|
->canBeEnabled() |
67
|
|
|
->children() |
68
|
|
|
->scalarNode('repository') |
69
|
|
|
->info('Scope repository.') |
70
|
|
|
->defaultNull() |
71
|
|
|
->end() |
72
|
|
|
->arrayNode('policy') |
73
|
|
|
->canBeEnabled() |
74
|
|
|
->children() |
75
|
|
|
->scalarNode('by_default') |
76
|
|
|
->info('Default scope policy.') |
77
|
|
|
->defaultValue('none') |
78
|
|
|
->end() |
79
|
|
|
->arrayNode('error') |
80
|
|
|
->canBeEnabled() |
81
|
|
|
->info('When the error policy is used, requests without a scope are not allowed') |
82
|
|
|
->end() |
83
|
|
|
->arrayNode('default') |
84
|
|
|
->canBeEnabled() |
85
|
|
|
->children() |
86
|
|
|
->scalarNode('scope') |
87
|
|
|
->info('Scope added by default.') |
88
|
|
|
->isRequired() |
89
|
|
|
->end() |
90
|
|
|
->end() |
91
|
|
|
->end() |
92
|
|
|
->end() |
93
|
|
|
->end() |
94
|
|
|
->end() |
95
|
|
|
->end() |
96
|
|
|
->end(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
*/ |
102
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
103
|
|
|
{ |
104
|
|
|
//Nothing to do |
105
|
|
|
return []; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|