Skip to content

Commit 5ea0f0e

Browse files
committed
Remove redundant token storage action
1 parent 9807ac2 commit 5ea0f0e

File tree

5 files changed

+4
-35
lines changed

5 files changed

+4
-35
lines changed

DependencyInjection/Security/Factory/OAuthFactory.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ public function createAuthenticator(ContainerBuilder $container, string $id, arr
3636
$container
3737
->setDefinition($providerId, new ChildDefinition('fos_oauth_server.security.authentication.authenticator'))
3838
->replaceArgument(0, new Reference('fos_oauth_server.server'))
39-
->replaceArgument(1, new Reference('security.token_storage'))
40-
->replaceArgument(2, new Reference('security.user_checker.'.$id))
41-
->replaceArgument(3, new Reference($userProviderId))
39+
->replaceArgument(1, new Reference('security.user_checker.'.$id))
40+
->replaceArgument(2, new Reference($userProviderId))
4241
;
4342

4443
return $providerId;

Resources/config/security.xml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<services>
1515
<service id="fos_oauth_server.security.authentication.authenticator" class="%fos_oauth_server.security.authentication.authenticator.class%" public="false">
1616
<argument type="service" id="fos_oauth_server.server" />
17-
<argument type="service" id="security.token_storage"/>
1817
<argument type="service" id="security.user_checker" />
1918
<argument /> <!-- user provider -->
2019
</service>

Security/Authentication/Authenticator/OAuthAuthenticator.php

-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use OAuth2\OAuth2ServerException;
2121
use Symfony\Component\HttpFoundation\Request;
2222
use Symfony\Component\HttpFoundation\Response;
23-
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
2423
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2524
use Symfony\Component\Security\Core\Exception\AccountStatusException;
2625
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@@ -45,11 +44,6 @@ class OAuthAuthenticator implements AuthenticatorInterface
4544
*/
4645
protected $serverService;
4746

48-
/**
49-
* @var TokenStorageInterface
50-
*/
51-
private $tokenStorage;
52-
5347
/**
5448
* @var UserCheckerInterface
5549
*/
@@ -62,12 +56,10 @@ class OAuthAuthenticator implements AuthenticatorInterface
6256

6357
public function __construct(
6458
OAuth2 $serverService,
65-
TokenStorageInterface $tokenStorage,
6659
UserCheckerInterface $userChecker,
6760
UserProviderInterface $userProvider
6861
) {
6962
$this->serverService = $serverService;
70-
$this->tokenStorage = $tokenStorage;
7163
$this->userChecker = $userChecker;
7264
$this->userProvider = $userProvider;
7365
}
@@ -161,8 +153,6 @@ public function createAuthenticatedToken(PassportInterface $passport, string $fi
161153
$token->setToken($credentials->getTokenString());
162154
$token->setUser($user);
163155

164-
$this->tokenStorage->setToken($token);
165-
166156
return $token;
167157
}
168158

Tests/DependencyInjection/Security/Factory/OAuthFactoryTest.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testCreateAuthenticator(): void
142142
;
143143

144144
$definition
145-
->expects($this->exactly(4))
145+
->expects($this->exactly(3))
146146
->method('replaceArgument')
147147
->withConsecutive(
148148
[
@@ -151,19 +151,14 @@ public function testCreateAuthenticator(): void
151151
],
152152
[
153153
1,
154-
new Reference('security.token_storage'),
155-
],
156-
[
157-
2,
158154
new Reference('security.user_checker.'.$id),
159155
],
160156
[
161-
3,
157+
2,
162158
new Reference($userProviderId),
163159
]
164160
)
165161
->willReturnOnConsecutiveCalls(
166-
$definition,
167162
$definition,
168163
$definition,
169164
$definition

Tests/Security/Authentication/Authenticator/OAuthAuthenticatorTest.php

-14
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use OAuth2\OAuth2AuthenticateException;
2222
use Symfony\Component\HttpFoundation\Request;
2323
use Symfony\Component\HttpFoundation\Response;
24-
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
2524
use Symfony\Component\Security\Core\Exception\AuthenticationException;
2625
use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
2726
use Symfony\Component\Security\Core\Exception\DisabledException;
@@ -44,11 +43,6 @@ class OAuthAuthenticatorTest extends \PHPUnit\Framework\TestCase
4443
*/
4544
protected $serverService;
4645

47-
/**
48-
* @var \PHPUnit\Framework\MockObject\MockObject|TokenStorageInterface
49-
*/
50-
protected $tokenStorage;
51-
5246
/**
5347
* @var \PHPUnit\Framework\MockObject\MockObject|User
5448
*/
@@ -75,7 +69,6 @@ public function setUp(): void
7569
])
7670
->getMock()
7771
;
78-
$this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->disableOriginalConstructor()->getMock();
7972
$this->userChecker = $this->getMockBuilder(UserCheckerInterface::class)->disableOriginalConstructor()->getMock();
8073
$this->userProvider = $this->getMockBuilder(UserProviderInterface::class)->disableOriginalConstructor()->getMock();
8174

@@ -85,7 +78,6 @@ public function setUp(): void
8578

8679
$this->authenticator = new OAuthAuthenticator(
8780
$this->serverService,
88-
$this->tokenStorage,
8981
$this->userChecker,
9082
$this->userProvider
9183
);
@@ -263,12 +255,6 @@ public function testCreateAuthenticatedTokenWithValidPassport(): void
263255
->will($this->returnValue(['ROLE_USER']))
264256
;
265257

266-
// expect a new authenticated token to be stored
267-
$this->tokenStorage->expects($this->once())
268-
->method('setToken')
269-
->with($this->isInstanceOf(OAuthToken::class))
270-
;
271-
272258
// configure the passport
273259
$passport = new Passport(
274260
new UserBadge('test_user'),

0 commit comments

Comments
 (0)