Skip to content

Commit

Permalink
Support authentication manager
Browse files Browse the repository at this point in the history
  • Loading branch information
iisisrael committed Oct 26, 2021
1 parent 5940472 commit 1b6c861
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
19 changes: 18 additions & 1 deletion DependencyInjection/Security/Factory/OAuthFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace FOS\OAuthServerBundle\DependencyInjection\Security\Factory;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ChildDefinition;
Expand All @@ -24,8 +25,24 @@
*
* @author Arnaud Le Blanc <[email protected]>
*/
class OAuthFactory implements SecurityFactoryInterface
class OAuthFactory implements AuthenticatorFactoryInterface, SecurityFactoryInterface
{
/**
* {@inheritdoc}
*/
public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId)
{
$providerId = 'fos_oauth_server.security.authentication.provider.'.$id;
$container
->setDefinition($providerId, new ChildDefinition('fos_oauth_server.security.authentication.provider'))
->replaceArgument(0, new Reference($userProviderId))
->replaceArgument(1, new Reference('security.user_checker.'.$id))
->replaceArgument(2, $id)
;

return $providerId;
}

/**
* {@inheritdoc}
*/
Expand Down
58 changes: 58 additions & 0 deletions Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,64 @@ public function testCreate(): void
], $this->instance->create($container, $id, $config, $userProvider, $defaultEntryPoint));
}

public function testCreateAuthenticator(): void
{
$container = $this->getMockBuilder(ContainerBuilder::class)
->disableOriginalConstructor()
->setMethods([
'setDefinition',
])
->getMock()
;
$id = '12';
$config = [];
$userProvider = 'mock.user.provider.service';

$definition = $this->getMockBuilder(Definition::class)
->disableOriginalConstructor()
->getMock()
;

$container
->expects($this->once())
->method('setDefinition')
->with(
'fos_oauth_server.security.authentication.provider.'.$id,
new ChildDefinition('fos_oauth_server.security.authentication.provider')
)
->will($this->returnValue($definition))
;

$definition
->expects($this->exactly(3))
->method('replaceArgument')
->withConsecutive(
[
0,
new Reference($userProvider),
],
[
1,
new Reference('security.user_checker.'.$id),
],
[
2,
$id,
]
)
->willReturnOnConsecutiveCalls(
$definition,
$definition,
$definition
)
;

$this->assertSame(
'fos_oauth_server.security.authentication.provider.'.$id,
$this->instance->createAuthenticator($container, $id, $config, $userProvider)
);
}

public function testAddConfigurationDoesNothing(): void
{
$nodeDefinition = $this->getMockBuilder(NodeDefinition::class)
Expand Down

0 comments on commit 1b6c861

Please sign in to comment.