Skip to content

Commit

Permalink
Remove redundant token storage action
Browse files Browse the repository at this point in the history
  • Loading branch information
iisisrael committed Oct 28, 2021
1 parent 9807ac2 commit 5ea0f0e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 35 deletions.
5 changes: 2 additions & 3 deletions DependencyInjection/Security/Factory/OAuthFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ public function createAuthenticator(ContainerBuilder $container, string $id, arr
$container
->setDefinition($providerId, new ChildDefinition('fos_oauth_server.security.authentication.authenticator'))
->replaceArgument(0, new Reference('fos_oauth_server.server'))
->replaceArgument(1, new Reference('security.token_storage'))
->replaceArgument(2, new Reference('security.user_checker.'.$id))
->replaceArgument(3, new Reference($userProviderId))
->replaceArgument(1, new Reference('security.user_checker.'.$id))
->replaceArgument(2, new Reference($userProviderId))
;

return $providerId;
Expand Down
1 change: 0 additions & 1 deletion Resources/config/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<services>
<service id="fos_oauth_server.security.authentication.authenticator" class="%fos_oauth_server.security.authentication.authenticator.class%" public="false">
<argument type="service" id="fos_oauth_server.server" />
<argument type="service" id="security.token_storage"/>
<argument type="service" id="security.user_checker" />
<argument /> <!-- user provider -->
</service>
Expand Down
10 changes: 0 additions & 10 deletions Security/Authentication/Authenticator/OAuthAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use OAuth2\OAuth2ServerException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AccountStatusException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
Expand All @@ -45,11 +44,6 @@ class OAuthAuthenticator implements AuthenticatorInterface
*/
protected $serverService;

/**
* @var TokenStorageInterface
*/
private $tokenStorage;

/**
* @var UserCheckerInterface
*/
Expand All @@ -62,12 +56,10 @@ class OAuthAuthenticator implements AuthenticatorInterface

public function __construct(
OAuth2 $serverService,
TokenStorageInterface $tokenStorage,
UserCheckerInterface $userChecker,
UserProviderInterface $userProvider
) {
$this->serverService = $serverService;
$this->tokenStorage = $tokenStorage;
$this->userChecker = $userChecker;
$this->userProvider = $userProvider;
}
Expand Down Expand Up @@ -161,8 +153,6 @@ public function createAuthenticatedToken(PassportInterface $passport, string $fi
$token->setToken($credentials->getTokenString());
$token->setUser($user);

$this->tokenStorage->setToken($token);

return $token;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function testCreateAuthenticator(): void
;

$definition
->expects($this->exactly(4))
->expects($this->exactly(3))
->method('replaceArgument')
->withConsecutive(
[
Expand All @@ -151,19 +151,14 @@ public function testCreateAuthenticator(): void
],
[
1,
new Reference('security.token_storage'),
],
[
2,
new Reference('security.user_checker.'.$id),
],
[
3,
2,
new Reference($userProviderId),
]
)
->willReturnOnConsecutiveCalls(
$definition,
$definition,
$definition,
$definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use OAuth2\OAuth2AuthenticateException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
use Symfony\Component\Security\Core\Exception\DisabledException;
Expand All @@ -44,11 +43,6 @@ class OAuthAuthenticatorTest extends \PHPUnit\Framework\TestCase
*/
protected $serverService;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|TokenStorageInterface
*/
protected $tokenStorage;

/**
* @var \PHPUnit\Framework\MockObject\MockObject|User
*/
Expand All @@ -75,7 +69,6 @@ public function setUp(): void
])
->getMock()
;
$this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->disableOriginalConstructor()->getMock();
$this->userChecker = $this->getMockBuilder(UserCheckerInterface::class)->disableOriginalConstructor()->getMock();
$this->userProvider = $this->getMockBuilder(UserProviderInterface::class)->disableOriginalConstructor()->getMock();

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

$this->authenticator = new OAuthAuthenticator(
$this->serverService,
$this->tokenStorage,
$this->userChecker,
$this->userProvider
);
Expand Down Expand Up @@ -263,12 +255,6 @@ public function testCreateAuthenticatedTokenWithValidPassport(): void
->will($this->returnValue(['ROLE_USER']))
;

// expect a new authenticated token to be stored
$this->tokenStorage->expects($this->once())
->method('setToken')
->with($this->isInstanceOf(OAuthToken::class))
;

// configure the passport
$passport = new Passport(
new UserBadge('test_user'),
Expand Down

0 comments on commit 5ea0f0e

Please sign in to comment.