|
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\RefreshToken; |
|
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 RefreshTokenSource implements Component |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function name(): string |
|
28
|
|
|
{ |
|
29
|
|
|
return 'refresh_token'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
if ($configs['grant']['refresh_token']['enabled']) { |
|
39
|
|
|
$container->setParameter('oauth2_server.grant.refresh_token.min_length', $configs['grant']['refresh_token']['min_length']); |
|
40
|
|
|
$container->setParameter('oauth2_server.grant.refresh_token.max_length', $configs['grant']['refresh_token']['max_length']); |
|
41
|
|
|
$container->setParameter('oauth2_server.grant.refresh_token.lifetime', $configs['grant']['refresh_token']['lifetime']); |
|
42
|
|
|
$container->setAlias('oauth2_server.grant.refresh_token.repository', $configs['grant']['refresh_token']['repository']); |
|
43
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../../Resources/config/grant')); |
|
44
|
|
|
$loader->load('refresh_token.php'); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
|
52
|
|
|
{ |
|
53
|
|
|
$node->children() |
|
54
|
|
|
->arrayNode('refresh_token') |
|
55
|
|
|
->canBeEnabled() |
|
56
|
|
|
->validate() |
|
57
|
|
|
->ifTrue(function ($config) { |
|
58
|
|
|
return true === $config['enabled'] && empty($config['repository']); |
|
59
|
|
|
}) |
|
60
|
|
|
->thenInvalid('The option "repository" must be set.') |
|
61
|
|
|
->end() |
|
62
|
|
|
->validate() |
|
63
|
|
|
->ifTrue(function ($config) { |
|
64
|
|
|
return true === $config['enabled'] && $config['max_length'] < $config['min_length']; |
|
65
|
|
|
}) |
|
66
|
|
|
->thenInvalid('The option "max_length" must be greater than "min_length".') |
|
67
|
|
|
->end() |
|
68
|
|
|
->children() |
|
69
|
|
|
->integerNode('min_length') |
|
70
|
|
|
->defaultValue(50) |
|
71
|
|
|
->min(0) |
|
72
|
|
|
->info('Minimum length of the randomly generated refresh tokens') |
|
73
|
|
|
->end() |
|
74
|
|
|
->integerNode('max_length') |
|
75
|
|
|
->defaultValue(100) |
|
76
|
|
|
->min(1) |
|
77
|
|
|
->info('Maximum length of the randomly generated refresh tokens') |
|
78
|
|
|
->end() |
|
79
|
|
|
->integerNode('lifetime') |
|
80
|
|
|
->defaultValue(60 * 60 * 24 * 7) |
|
81
|
|
|
->min(1) |
|
82
|
|
|
->info('The refresh token lifetime (in seconds)') |
|
83
|
|
|
->end() |
|
84
|
|
|
->scalarNode('repository') |
|
85
|
|
|
->defaultNull() |
|
86
|
|
|
->info('The refresh token repository') |
|
87
|
|
|
->end() |
|
88
|
|
|
->end() |
|
89
|
|
|
->end() |
|
90
|
|
|
->end(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* {@inheritdoc} |
|
95
|
|
|
*/ |
|
96
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
|
97
|
|
|
{ |
|
98
|
|
|
//Nothing to do |
|
99
|
|
|
return []; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|