|
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\SecurityBundle\Security\Factory; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ChildDefinition; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
20
|
|
|
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; |
|
21
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
22
|
|
|
|
|
23
|
|
|
final class OAuth2SecurityFactory implements SecurityFactoryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) |
|
29
|
|
|
{ |
|
30
|
|
|
$providerId = 'security.authentication.provider.oauth2.'.$id; |
|
31
|
|
|
$container |
|
32
|
|
|
->setDefinition($providerId, new ChildDefinition('oauth2_security.provider')) |
|
33
|
|
|
->setAutowired(true) |
|
34
|
|
|
; |
|
35
|
|
|
|
|
36
|
|
|
$listenerId = 'security.authentication.listener.oauth2.'.$id; |
|
37
|
|
|
$container |
|
38
|
|
|
->setDefinition($listenerId, new ChildDefinition('oauth2_security.listener')) |
|
39
|
|
|
->setArguments([ |
|
40
|
|
|
new Reference(TokenStorageInterface::class), |
|
41
|
|
|
new Reference('security.authentication.manager'), |
|
42
|
|
|
new Reference('oauth2_security.token_type_manager'), |
|
43
|
|
|
new Reference('oauth2_security.access_token_handler_manager'), |
|
44
|
|
|
]) |
|
45
|
|
|
; |
|
46
|
|
|
|
|
47
|
|
|
return [$providerId, $listenerId, 'oauth2_security.entry_point']; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getPosition() |
|
54
|
|
|
{ |
|
55
|
|
|
return 'pre_auth'; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritdoc} |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getKey() |
|
62
|
|
|
{ |
|
63
|
|
|
return 'oauth2'; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function addConfiguration(NodeDefinition $node) |
|
70
|
|
|
{ |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|