|
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\ServerBundle\Component\Grant\RefreshToken; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\RefreshTokenGrant\RefreshTokenIdGenerator; |
|
17
|
|
|
use OAuth2Framework\Component\RefreshTokenGrant\RefreshTokenRepository; |
|
18
|
|
|
use OAuth2Framework\ServerBundle\Component\Component; |
|
19
|
|
|
use OAuth2Framework\ServerBundle\Service\RandomRefreshTokenIdGenerator; |
|
20
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
21
|
|
|
use Symfony\Component\Config\FileLocator; |
|
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
23
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
|
24
|
|
|
|
|
25
|
|
|
class RefreshTokenSource implements Component |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function name(): string |
|
31
|
|
|
{ |
|
32
|
|
|
return 'refresh_token'; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
39
|
|
|
{ |
|
40
|
|
|
if ($configs['grant']['refresh_token']['enabled']) { |
|
41
|
|
|
$container->setParameter('oauth2_server.grant.refresh_token.lifetime', $configs['grant']['refresh_token']['lifetime']); |
|
42
|
|
|
$container->setAlias(RefreshTokenRepository::class, $configs['grant']['refresh_token']['repository']); |
|
43
|
|
|
$container->setAlias(RefreshTokenIdGenerator::class, $configs['grant']['refresh_token']['id_generator']); |
|
44
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/grant')); |
|
45
|
|
|
$loader->load('refresh_token.php'); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode) |
|
53
|
|
|
{ |
|
54
|
|
|
$node->children() |
|
55
|
|
|
->arrayNode('refresh_token') |
|
56
|
|
|
->canBeEnabled() |
|
57
|
|
|
->children() |
|
58
|
|
|
->integerNode('lifetime') |
|
59
|
|
|
->defaultValue(60 * 60 * 24 * 7) |
|
60
|
|
|
->min(1) |
|
61
|
|
|
->info('The refresh token lifetime (in seconds)') |
|
62
|
|
|
->end() |
|
63
|
|
|
->scalarNode('repository') |
|
64
|
|
|
->isRequired() |
|
65
|
|
|
->info('The refresh token repository') |
|
66
|
|
|
->end() |
|
67
|
|
|
->scalarNode('id_generator') |
|
68
|
|
|
->info('The refresh token ID generator service') |
|
69
|
|
|
->defaultValue(RandomRefreshTokenIdGenerator::class) |
|
70
|
|
|
->end() |
|
71
|
|
|
->end() |
|
72
|
|
|
->end() |
|
73
|
|
|
->end(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
|
|
public function build(ContainerBuilder $container) |
|
80
|
|
|
{ |
|
81
|
|
|
//Nothing to do |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
*/ |
|
87
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
|
88
|
|
|
{ |
|
89
|
|
|
//Nothing to do |
|
90
|
|
|
return []; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|