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\Endpoint\TokenRevocation; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Bundle\Component\Component; |
17
|
|
|
use OAuth2Framework\Bundle\Component\Endpoint\TokenRevocation\Compiler\TokenRevocationRouteCompilerPass; |
18
|
|
|
use OAuth2Framework\Bundle\Component\Endpoint\TokenRevocation\Compiler\TokenTypeHintCompilerPass; |
19
|
|
|
use OAuth2Framework\Component\TokenRevocationEndpoint\TokenTypeHint; |
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 TokenRevocationEndpointSource implements Component |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
|
|
public function name(): string |
31
|
|
|
{ |
32
|
|
|
return 'token_revocation'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function load(array $configs, ContainerBuilder $container) |
39
|
|
|
{ |
40
|
|
|
$config = $configs['endpoint']['token_revocation']; |
41
|
|
|
$container->setParameter('oauth2_server.endpoint.token_revocation.enabled', $config['enabled']); |
42
|
|
|
if (!$config['enabled']) { |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
$container->registerForAutoconfiguration(TokenTypeHint::class)->addTag('oauth2_server_revocation_type_hint'); |
46
|
|
|
$container->setParameter('oauth2_server.endpoint.token_revocation.path', $config['path']); |
47
|
|
|
$container->setParameter('oauth2_server.endpoint.token_revocation.host', $config['host']); |
48
|
|
|
$container->setParameter('oauth2_server.endpoint.token_revocation.allow_callback', $config['allow_callback']); |
49
|
|
|
|
50
|
|
|
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/endpoint/token_revocation')); |
51
|
|
|
$loader->load('revocation.php'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function getNodeDefinition(ArrayNodeDefinition $node, ArrayNodeDefinition $rootNode) |
58
|
|
|
{ |
59
|
|
|
$node->children() |
60
|
|
|
->arrayNode($this->name()) |
61
|
|
|
->canBeEnabled() |
62
|
|
|
->children() |
63
|
|
|
->scalarNode('path') |
64
|
|
|
->info('The token revocation endpoint path') |
65
|
|
|
->defaultValue('/token/revocation') |
66
|
|
|
->end() |
67
|
|
|
->scalarNode('host') |
68
|
|
|
->info('If set, the route will be limited to that host') |
69
|
|
|
->defaultValue('') |
70
|
|
|
->treatNullLike('') |
71
|
|
|
->treatFalseLike('') |
72
|
|
|
->end() |
73
|
|
|
->booleanNode('allow_callback') |
74
|
|
|
->info('If true, GET request with "callback" parameter are allowed.') |
75
|
|
|
->defaultFalse() |
76
|
|
|
->end() |
77
|
|
|
->end() |
78
|
|
|
->end() |
79
|
|
|
->end(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function build(ContainerBuilder $container) |
86
|
|
|
{ |
87
|
|
|
$container->addCompilerPass(new TokenTypeHintCompilerPass()); |
88
|
|
|
$container->addCompilerPass(new TokenRevocationRouteCompilerPass()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function prepend(ContainerBuilder $container, array $config): array |
95
|
|
|
{ |
96
|
|
|
return []; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|