Skip to content

Commit b669962

Browse files
committed
Support authentication manager
1 parent dc8ff34 commit b669962

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

DependencyInjection/Security/Factory/OAuthFactory.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace FOS\OAuthServerBundle\DependencyInjection\Security\Factory;
1515

16+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
1617
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
1718
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
1819
use Symfony\Component\DependencyInjection\ChildDefinition;
@@ -24,8 +25,24 @@
2425
*
2526
* @author Arnaud Le Blanc <[email protected]>
2627
*/
27-
class OAuthFactory implements SecurityFactoryInterface
28+
class OAuthFactory implements AuthenticatorFactoryInterface, SecurityFactoryInterface
2829
{
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId)
34+
{
35+
$providerId = 'fos_oauth_server.security.authentication.provider.'.$id;
36+
$container
37+
->setDefinition($providerId, new ChildDefinition('fos_oauth_server.security.authentication.provider'))
38+
->replaceArgument(0, new Reference($userProviderId))
39+
->replaceArgument(1, new Reference('security.user_checker.'.$id))
40+
->replaceArgument(2, $id)
41+
;
42+
43+
return $providerId;
44+
}
45+
2946
/**
3047
* {@inheritdoc}
3148
*/

Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,64 @@ public function testCreate(): void
113113
], $this->instance->create($container, $id, $config, $userProvider, $defaultEntryPoint));
114114
}
115115

116+
public function testCreateAuthenticator(): void
117+
{
118+
$container = $this->getMockBuilder(ContainerBuilder::class)
119+
->disableOriginalConstructor()
120+
->setMethods([
121+
'setDefinition',
122+
])
123+
->getMock()
124+
;
125+
$id = '12';
126+
$config = [];
127+
$userProvider = 'mock.user.provider.service';
128+
129+
$definition = $this->getMockBuilder(Definition::class)
130+
->disableOriginalConstructor()
131+
->getMock()
132+
;
133+
134+
$container
135+
->expects($this->once())
136+
->method('setDefinition')
137+
->with(
138+
'fos_oauth_server.security.authentication.provider.'.$id,
139+
new ChildDefinition('fos_oauth_server.security.authentication.provider')
140+
)
141+
->will($this->returnValue($definition))
142+
;
143+
144+
$definition
145+
->expects($this->exactly(3))
146+
->method('replaceArgument')
147+
->withConsecutive(
148+
[
149+
0,
150+
new Reference($userProvider),
151+
],
152+
[
153+
1,
154+
new Reference('security.user_checker.'.$id),
155+
],
156+
[
157+
2,
158+
$id,
159+
]
160+
)
161+
->willReturnOnConsecutiveCalls(
162+
$definition,
163+
$definition,
164+
$definition
165+
)
166+
;
167+
168+
$this->assertSame(
169+
'fos_oauth_server.security.authentication.provider.'.$id,
170+
$this->instance->createAuthenticator($container, $id, $config, $userProvider)
171+
);
172+
}
173+
116174
public function testAddConfigurationDoesNothing(): void
117175
{
118176
$nodeDefinition = $this->getMockBuilder(NodeDefinition::class)

0 commit comments

Comments
 (0)