vendor/hwi/oauth-bundle/src/HWIOAuthBundle.php line 29

  1. <?php
  2. /*
  3.  * This file is part of the HWIOAuthBundle package.
  4.  *
  5.  * (c) Hardware Info <opensource@hardware.info>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace HWI\Bundle\OAuthBundle;
  11. use HWI\Bundle\OAuthBundle\DependencyInjection\CompilerPass\EnableRefreshOAuthTokenListenerCompilerPass;
  12. use HWI\Bundle\OAuthBundle\DependencyInjection\CompilerPass\RefreshOAuthTokenCompilerPass;
  13. use HWI\Bundle\OAuthBundle\DependencyInjection\CompilerPass\ResourceOwnerMapCompilerPass;
  14. use HWI\Bundle\OAuthBundle\DependencyInjection\Security\Factory\OAuthAuthenticatorFactory;
  15. use HWI\Bundle\OAuthBundle\DependencyInjection\Security\Factory\OAuthFactory;
  16. use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
  17. use Symfony\Component\DependencyInjection\ContainerBuilder;
  18. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  19. use Symfony\Component\HttpKernel\Bundle\Bundle;
  20. use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
  21. /**
  22.  * @author Geoffrey Bachelet <geoffrey.bachelet@gmail.com>
  23.  * @author Alexander <geoffrey.bachelet@gmail.com>
  24.  */
  25. class HWIOAuthBundle extends Bundle
  26. {
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public function build(ContainerBuilder $container)
  31.     {
  32.         parent::build($container);
  33.         /** @var SecurityExtension $extension */
  34.         $extension $container->getExtension('security');
  35.         $firewallNames $this->extension->getFirewallNames();
  36.         if (method_exists($extension'addAuthenticatorFactory')) {
  37.             $extension->addAuthenticatorFactory(new OAuthAuthenticatorFactory($firewallNames));
  38.         } elseif (interface_exists(AuthenticationProviderInterface::class)) {
  39.             // @phpstan-ignore-next-line Symfony 4.4 BC layer
  40.             $extension->addSecurityListenerFactory(new OAuthFactory($firewallNames));
  41.             $container->addCompilerPass(new RefreshOAuthTokenCompilerPass());
  42.         } else {
  43.             // @phpstan-ignore-next-line Symfony < 5.4 BC layer
  44.             $extension->addSecurityListenerFactory(new OAuthAuthenticatorFactory($firewallNames));
  45.         }
  46.         $container->addCompilerPass(new ResourceOwnerMapCompilerPass());
  47.         $container->addCompilerPass(new EnableRefreshOAuthTokenListenerCompilerPass());
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function getContainerExtension(): ?ExtensionInterface
  53.     {
  54.         // return the right extension instead of "auto-registering" it. Now the
  55.         // alias can be hwi_oauth instead of hwi_o_auth.
  56.         return $this->extension ?: $this->extension $this->createContainerExtension();
  57.     }
  58. }