Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

Commit

Permalink
Use TwoFactorTokenInterface to keep it compatible with custom token i…
Browse files Browse the repository at this point in the history
…mplementations
  • Loading branch information
scheb committed Sep 2, 2019
1 parent 15bad1e commit 170895e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function authenticate(TokenInterface $token)
return $token;
}

// AnonymousToken and TwoFactorToken can be ignored
// AnonymousToken and TwoFactorTokenInterface can be ignored
// in case of Guard, it can return null due to having multiple guard authenticators
if ($token instanceof AnonymousToken || $token instanceof TwoFactorTokenInterface || null === $token) {
return $token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function authenticate(TokenInterface $token)
throw new AuthenticationException('The token is not supported by this authentication provider.');
}

// Keep unauthenticated TwoFactorToken with no credentials given
// Keep unauthenticated TwoFactorTokenInterface with no credentials given
if (null === $token->getCredentials()) {
return $token;
}
Expand Down
2 changes: 1 addition & 1 deletion Security/Http/Firewall/TwoFactorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private function onSuccess(Request $request, TokenInterface $token): Response
$this->tokenStorage->setToken($token);
$this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::SUCCESS, $request, $token);

// When it's still a TwoFactorToken, keep showing the auth form
// When it's still a TwoFactorTokenInterface, keep showing the auth form
if ($token instanceof TwoFactorTokenInterface) {
$this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::REQUIRE, $request, $token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Scheb\TwoFactorBundle\Security\TwoFactor\Provider;

use Psr\Log\LoggerInterface;
use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorToken;
use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Event\TwoFactorAuthenticationEvent;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
Expand All @@ -24,7 +24,7 @@ class TwoFactorProviderPreparationListener
private $preparationRecorder;

/**
* @var TwoFactorToken|null
* @var TwoFactorTokenInterface|null
*/
private $twoFactorToken;

Expand Down Expand Up @@ -69,7 +69,7 @@ public function onLogin(AuthenticationEvent $event): void
{
$token = $event->getAuthenticationToken();
if ($this->prepareOnLogin && $this->supports($token)) {
// After login, when the token is a TwoFactorToken, execute preparation
// After login, when the token is a TwoFactorTokenInterface, execute preparation
$this->twoFactorToken = $token;
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public function onKernelFinishRequest(FinishRequestEvent $event): void
if (!$event->isMasterRequest()) {
return;
}
if (!($this->twoFactorToken instanceof TwoFactorToken)) {
if (!($this->twoFactorToken instanceof TwoFactorTokenInterface)) {
return;
}

Expand All @@ -122,6 +122,6 @@ public function onKernelFinishRequest(FinishRequestEvent $event): void

private function supports(TokenInterface $token): bool
{
return $token instanceof TwoFactorToken && $token->getProviderKey() === $this->firewallName;
return $token instanceof TwoFactorTokenInterface && $token->getProviderKey() === $this->firewallName;
}
}

0 comments on commit 170895e

Please sign in to comment.