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