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

Open in your IDE?
  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\ResourceOwnerCompilerPass;
  13. use HWI\Bundle\OAuthBundle\DependencyInjection\Security\Factory\OAuthAuthenticatorFactory;
  14. use RuntimeException;
  15. use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  18. use Symfony\Component\HttpKernel\Bundle\Bundle;
  19. /**
  20. * @author Geoffrey Bachelet <geoffrey.bachelet@gmail.com>
  21. * @author Alexander <geoffrey.bachelet@gmail.com>
  22. */
  23. class HWIOAuthBundle extends Bundle
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function build(ContainerBuilder $container): void
  29. {
  30. parent::build($container);
  31. /** @var SecurityExtension $extension */
  32. $extension = $container->getExtension('security');
  33. $firewallNames = $this->extension->getFirewallNames();
  34. if (method_exists($extension, 'addAuthenticatorFactory')) {
  35. $extension->addAuthenticatorFactory(new OAuthAuthenticatorFactory($firewallNames));
  36. } elseif (method_exists($extension, 'addSecurityListenerFactory')) {
  37. // Symfony < 5.4 BC layer
  38. $extension->addSecurityListenerFactory(new OAuthAuthenticatorFactory($firewallNames));
  39. } else {
  40. throw new RuntimeException('Unsupported Symfony Security component version');
  41. }
  42. $container->addCompilerPass(new ResourceOwnerCompilerPass());
  43. $container->addCompilerPass(new EnableRefreshOAuthTokenListenerCompilerPass());
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function getContainerExtension(): ?ExtensionInterface
  49. {
  50. // return the right extension instead of "auto-registering" it. Now the
  51. // alias can be hwi_oauth instead of hwi_o_auth.
  52. return $this->extension ?: $this->extension = $this->createContainerExtension();
  53. }
  54. }