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\AuthorizationCode; |
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 AuthorizationCodeSource implements Component |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function name(): string |
28
|
|
|
{ |
29
|
|
|
return 'authorization_code'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function load(array $configs, ContainerBuilder $container) |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
if ($configs['grant']['authorization_code']['enabled']) { |
39
|
|
|
$container->setParameter('oauth2_server.grant.authorization_code.min_length', $configs['grant']['authorization_code']['min_length']); |
40
|
|
|
$container->setParameter('oauth2_server.grant.authorization_code.max_length', $configs['grant']['authorization_code']['max_length']); |
41
|
|
|
$container->setParameter('oauth2_server.grant.authorization_code.lifetime', $configs['grant']['authorization_code']['lifetime']); |
42
|
|
|
$container->setParameter('oauth2_server.grant.authorization_code.enforce_pkce', $configs['grant']['authorization_code']['enforce_pkce']); |
43
|
|
|
$container->setAlias('oauth2_server.grant.authorization_code.repository', $configs['grant']['authorization_code']['repository']); |
44
|
|
|
|
45
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../../Resources/config/grant')); |
46
|
|
|
$loader->load('authorization_code.php'); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function getNodeDefinition(NodeDefinition $node) |
54
|
|
|
{ |
55
|
|
|
$node->children() |
56
|
|
|
->arrayNode('authorization_code') |
57
|
|
|
->validate() |
58
|
|
|
->ifTrue(function ($config) { |
59
|
|
|
return $config['max_length'] < $config['min_length']; |
60
|
|
|
}) |
61
|
|
|
->thenInvalid('The option "max_length" must be greater than "min_length".') |
62
|
|
|
->end() |
63
|
|
|
->canBeEnabled() |
64
|
|
|
->children() |
65
|
|
|
->integerNode('min_length') |
66
|
|
|
->defaultValue(50) |
67
|
|
|
->min(0) |
68
|
|
|
->info('Minimum length of the randomly generated authorization code') |
69
|
|
|
->end() |
70
|
|
|
->integerNode('max_length') |
71
|
|
|
->defaultValue(100) |
72
|
|
|
->min(1) |
73
|
|
|
->info('Maximum length of the randomly generated authorization code') |
74
|
|
|
->end() |
75
|
|
|
->integerNode('lifetime') |
76
|
|
|
->defaultValue(30) |
77
|
|
|
->min(1) |
78
|
|
|
->info('Authorization code lifetime (in seconds)') |
79
|
|
|
->end() |
80
|
|
|
->scalarNode('repository') |
81
|
|
|
->isRequired() |
82
|
|
|
->info('The authorization code repository') |
83
|
|
|
->end() |
84
|
|
|
->booleanNode('enforce_pkce') |
85
|
|
|
->defaultFalse() |
86
|
|
|
->info('If true, the PKCE is required for all requests including the ones from confidential clients') |
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
|
|
|
|