|
4 | 4 |
|
5 | 5 | namespace League\Bundle\OAuth2ServerBundle\DependencyInjection\Security; |
6 | 6 |
|
| 7 | +use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator; |
7 | 8 | use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface; |
8 | | -use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; |
9 | | -use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension; |
10 | | - |
11 | | -if (interface_exists(SecurityFactoryInterface::class) && !interface_exists(AuthenticatorFactoryInterface::class)) { |
12 | | - /** |
13 | | - * Wires the "oauth" authenticator from user configuration. |
14 | | - * |
15 | | - * @author Mathias Arlaud <mathias.arlaud@gmail.com> |
16 | | - */ |
17 | | - class OAuth2Factory implements SecurityFactoryInterface |
| 9 | +use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
| 10 | +use Symfony\Component\DependencyInjection\ChildDefinition; |
| 11 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 12 | +use Symfony\Component\DependencyInjection\Reference; |
| 13 | + |
| 14 | +/** |
| 15 | + * Wires the "oauth" authenticator from user configuration. |
| 16 | + * |
| 17 | + * @author Mathias Arlaud <mathias.arlaud@gmail.com> |
| 18 | + */ |
| 19 | +class OAuth2Factory implements AuthenticatorFactoryInterface |
| 20 | +{ |
| 21 | + public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint): array |
| 22 | + { |
| 23 | + throw new \LogicException('OAuth2 is not supported when "security.enable_authenticator_manager" is not set to true.'); |
| 24 | + } |
| 25 | + |
| 26 | + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string |
18 | 27 | { |
19 | | - use OAuth2FactoryTrait; |
| 28 | + $authenticator = \sprintf('security.authenticator.oauth2.%s', $firewallName); |
| 29 | + |
| 30 | + $definition = new ChildDefinition(OAuth2Authenticator::class); |
| 31 | + $definition->replaceArgument(2, new Reference($userProviderId)); |
| 32 | + |
| 33 | + $container->setDefinition($authenticator, $definition); |
| 34 | + |
| 35 | + return $authenticator; |
20 | 36 | } |
21 | | -} elseif (!method_exists(SecurityExtension::class, 'addAuthenticatorFactory')) { |
22 | | - /** |
23 | | - * Wires the "oauth" authenticator from user configuration. |
24 | | - * |
25 | | - * @author Mathias Arlaud <mathias.arlaud@gmail.com> |
26 | | - */ |
27 | | - class OAuth2Factory implements AuthenticatorFactoryInterface, SecurityFactoryInterface |
| 37 | + |
| 38 | + public function getPosition(): string |
28 | 39 | { |
29 | | - use OAuth2FactoryTrait; |
| 40 | + return 'pre_auth'; |
30 | 41 | } |
31 | | -} else { |
32 | | - /** |
33 | | - * Wires the "oauth" authenticator from user configuration. |
34 | | - * |
35 | | - * @author Mathias Arlaud <mathias.arlaud@gmail.com> |
36 | | - */ |
37 | | - class OAuth2Factory implements AuthenticatorFactoryInterface |
| 42 | + |
| 43 | + public function getPriority(): int |
| 44 | + { |
| 45 | + return -10; |
| 46 | + } |
| 47 | + |
| 48 | + public function getKey(): string |
| 49 | + { |
| 50 | + return 'oauth2'; |
| 51 | + } |
| 52 | + |
| 53 | + public function addConfiguration(NodeDefinition $builder): void |
38 | 54 | { |
39 | | - use OAuth2FactoryTrait; |
40 | 55 | } |
41 | 56 | } |
0 commit comments