|
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\Endpoint\ClientRegistration; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\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
|
|
|
class InitialAccessTokenSource implements Component |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @return string |
|
26
|
|
|
*/ |
|
27
|
|
|
public function name(): string |
|
28
|
|
|
{ |
|
29
|
|
|
return 'initial_access_token'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
36
|
|
|
{ |
|
37
|
|
|
if (!$configs['endpoint']['client_registration']['initial_access_token']['enabled']) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
$container->setParameter('oauth2_server.endpoint.client_registration.initial_access_token.required', $configs['endpoint']['client_registration']['initial_access_token']['required']); |
|
41
|
|
|
$container->setParameter('oauth2_server.endpoint.client_registration.initial_access_token.realm', $configs['endpoint']['client_registration']['initial_access_token']['realm']); |
|
42
|
|
|
$container->setParameter('oauth2_server.endpoint.client_registration.initial_access_token.authorization_header', $configs['endpoint']['client_registration']['initial_access_token']['authorization_header']); |
|
43
|
|
|
$container->setParameter('oauth2_server.endpoint.client_registration.initial_access_token.query_string', $configs['endpoint']['client_registration']['initial_access_token']['query_string']); |
|
44
|
|
|
$container->setParameter('oauth2_server.endpoint.client_registration.initial_access_token.request_body', $configs['endpoint']['client_registration']['initial_access_token']['request_body']); |
|
45
|
|
|
$container->setParameter('oauth2_server.endpoint.client_registration.initial_access_token.min_length', $configs['endpoint']['client_registration']['initial_access_token']['min_length']); |
|
46
|
|
|
$container->setParameter('oauth2_server.endpoint.client_registration.initial_access_token.max_length', $configs['endpoint']['client_registration']['initial_access_token']['max_length']); |
|
47
|
|
|
$container->setAlias('oauth2_server.endpoint.client_registration.initial_access_token.repository', $configs['endpoint']['client_registration']['initial_access_token']['repository']); |
|
48
|
|
|
|
|
49
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/client_registration')); |
|
50
|
|
|
$loader->load('initial_access_token.php'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
|
57
|
|
|
{ |
|
58
|
|
|
$node->children() |
|
59
|
|
|
->arrayNode($this->name()) |
|
60
|
|
|
->addDefaultsIfNotSet() |
|
61
|
|
|
->canBeEnabled() |
|
62
|
|
|
->validate() |
|
63
|
|
|
->ifTrue(function ($config) { |
|
64
|
|
|
return true === $config['enabled'] && empty($config['realm']); |
|
65
|
|
|
}) |
|
66
|
|
|
->thenInvalid('The option "realm" must be set.') |
|
67
|
|
|
->end() |
|
68
|
|
|
->validate() |
|
69
|
|
|
->ifTrue(function ($config) { |
|
70
|
|
|
return true === $config['enabled'] && empty($config['repository']); |
|
71
|
|
|
}) |
|
72
|
|
|
->thenInvalid('The option "repository" must be set.') |
|
73
|
|
|
->end() |
|
74
|
|
|
->validate() |
|
75
|
|
|
->ifTrue(function ($config) { |
|
76
|
|
|
return true === $config['enabled'] && $config['max_length'] < $config['min_length']; |
|
77
|
|
|
}) |
|
78
|
|
|
->thenInvalid('The option "max_length" must be greater than "min_length".') |
|
79
|
|
|
->end() |
|
80
|
|
|
->children() |
|
81
|
|
|
->booleanNode('required') |
|
82
|
|
|
->defaultFalse() |
|
83
|
|
|
->end() |
|
84
|
|
|
->scalarNode('realm') |
|
85
|
|
|
->defaultNull() |
|
86
|
|
|
->end() |
|
87
|
|
|
->booleanNode('authorization_header') |
|
88
|
|
|
->defaultTrue() |
|
89
|
|
|
->end() |
|
90
|
|
|
->booleanNode('query_string') |
|
91
|
|
|
->defaultFalse() |
|
92
|
|
|
->end() |
|
93
|
|
|
->booleanNode('request_body') |
|
94
|
|
|
->defaultFalse() |
|
95
|
|
|
->end() |
|
96
|
|
|
->integerNode('min_length') |
|
97
|
|
|
->defaultValue(50) |
|
98
|
|
|
->min(0) |
|
99
|
|
|
->end() |
|
100
|
|
|
->integerNode('max_length') |
|
101
|
|
|
->defaultValue(100) |
|
102
|
|
|
->min(1) |
|
103
|
|
|
->end() |
|
104
|
|
|
->scalarNode('repository') |
|
105
|
|
|
->defaultNull() |
|
106
|
|
|
->end() |
|
107
|
|
|
->end(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* {@inheritdoc} |
|
112
|
|
|
*/ |
|
113
|
|
|
public function build(ContainerBuilder $container) |
|
114
|
|
|
{ |
|
115
|
|
|
//Nothing to do |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* {@inheritdoc} |
|
120
|
|
|
*/ |
|
121
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
|
122
|
|
|
{ |
|
123
|
|
|
return []; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|