. */ namespace vierbergenlars\AuthserverOAuthAccountBundle\DependencyInjection; use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; use vierbergenlars\AuthserverOAuthAccountBundle\ResourceOwner\ResourceOwnerConfig; class AuthserverOAuthAccountExtension extends Extension implements PrependExtensionInterface { const RESOURCE_OWNER_MAP_SERVICE = 'vierbergenlars.authserver_oauth_account.resource_owner_map'; const USER_PROVIDER_SERVICE = 'vierbergenlars.authserver_oauth_account.user_provider'; public function prepend(ContainerBuilder $container) { $container->prependExtensionConfig('hwi_oauth', [ 'firewall_names' => ['public'], 'connect' => [ 'account_connector' => self::USER_PROVIDER_SERVICE, ] ]); $configs = $container->getExtensionConfig($this->getAlias()); $processor = new Processor(); $config = $processor->processConfiguration(new Configuration(), $configs); $container->prependExtensionConfig('hwi_oauth', [ 'resource_owners' => array_map(function($resource_owner) { return (new ResourceOwnerConfig($resource_owner))->getHwiConfig(); }, $config['resource_owners']), ]); $container->loadFromExtension('security', [ 'firewalls' => [ 'public' => [ 'oauth' => [ 'resource_owners' => array_combine(array_keys($config['resource_owners']), array_map(function($roName) { return '/login/oauth/'.$roName; }, array_keys($config['resource_owners']))), 'login_path' => 'app_login', 'failure_path' => 'app_login', 'oauth_user_provider' => [ 'service' => self::USER_PROVIDER_SERVICE, ], ], ] ], ]); } public function load(array $configs, ContainerBuilder $container) { $servicesDirectory = __DIR__.'/../Resources/config'; $fileLocator = new FileLocator($servicesDirectory); $xmlLoader = new Loader\XmlFileLoader($container, $fileLocator); $xmlLoader->load('services.xml'); $processor = new Processor(); $config = $processor->processConfiguration(new Configuration(), $configs); $container->getDefinition(self::RESOURCE_OWNER_MAP_SERVICE) ->setArgument(0, $config['resource_owners']); } public function getAlias() { return 'oauth'; } }