|
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 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 AuthorizationCodeSource implements Component |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function continueLoading(string $path, ContainerBuilder $container, array $config) |
|
28
|
|
|
{ |
|
29
|
|
|
foreach (['min_length', 'max_length', 'lifetime', 'enforce_pkce'] as $k) { |
|
30
|
|
|
$container->setParameter($path.'.'.$k, $config[$k]); |
|
31
|
|
|
} |
|
32
|
|
|
$container->setAlias($path.'.event_store', $config['event_store']); |
|
33
|
|
|
|
|
34
|
|
|
$loader = new PhpConfigFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/grant')); |
|
35
|
|
|
$loader->load('authorization_code.php'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function name(): string |
|
42
|
|
|
{ |
|
43
|
|
|
return 'authorization_code'; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
|
50
|
|
|
{ |
|
51
|
|
|
|
|
52
|
|
|
$node |
|
53
|
|
|
->validate() |
|
54
|
|
|
->ifTrue(function ($config) { |
|
55
|
|
|
return true === $config['enabled'] && empty($config['event_store']); |
|
56
|
|
|
}) |
|
57
|
|
|
->thenInvalid('The option "event_store" must be set.') |
|
58
|
|
|
->end() |
|
59
|
|
|
->validate() |
|
60
|
|
|
->ifTrue(function ($config) { |
|
61
|
|
|
return true === $config['enabled'] && $config['max_length'] < $config['min_length']; |
|
62
|
|
|
}) |
|
63
|
|
|
->thenInvalid('The option "max_length" must be greater than "min_length".') |
|
64
|
|
|
->end() |
|
65
|
|
|
->children() |
|
66
|
|
|
->integerNode('min_length')->defaultValue(50)->min(0)->end() |
|
67
|
|
|
->integerNode('max_length')->defaultValue(100)->min(1)->end() |
|
68
|
|
|
->integerNode('lifetime')->defaultValue(30)->min(1)->end() |
|
69
|
|
|
->scalarNode('event_store')->defaultNull()->end() |
|
70
|
|
|
->booleanNode('enforce_pkce')->defaultFalse()->end() |
|
71
|
|
|
->end(); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|