Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ public function getKey(): string

public function getPriority(): int
{
return 0;
return -50;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ public function beginTwoFactorAuthentication(AuthenticationContextInterface $con
if ($activeTwoFactorProviders) {
$twoFactorToken = $this->twoFactorTokenFactory->create($authenticatedToken, $context->getFirewallName(), $activeTwoFactorProviders);

// Mark all providers which do *not* need to be prepared, to `prepared` so the preparation process is skipped.
// This way these providers can be used to verify the second factor immediately
foreach ($activeTwoFactorProviders as $providerName) {
$provider = $this->providerRegistry->getProvider($providerName);

if ($provider->needsPreparation()) {
continue;
}

$twoFactorToken->setTwoFactorProviderPrepared($providerName);
}

$preferredProvider = $this->twoFactorProviderDecider->getPreferredTwoFactorProvider($activeTwoFactorProviders, $twoFactorToken, $context);

if (null !== $preferredProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ interface TwoFactorProviderInterface
*/
public function beginAuthentication(AuthenticationContextInterface $context): bool;

/**
* Determine whether this Provider needs to be prepared (if the prepareAuthentication method needs to be called).
*/
public function needsPreparation(): bool;

/**
* Do all steps necessary to prepare authentication, e.g. generate & send a code.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public function beginAuthentication(AuthenticationContextInterface $context): bo
return $user instanceof TwoFactorInterface && $user->isEmailAuthEnabled();
}

public function needsPreparation(): bool
{
return true;
}

public function prepareAuthentication(object $user): void
{
if (!($user instanceof TwoFactorInterface)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public function beginAuthentication(AuthenticationContextInterface $context): bo
return true;
}

public function needsPreparation(): bool
{
return false;
}

public function prepareAuthentication(object $user): void
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function beginAuthentication(AuthenticationContextInterface $context): bo
return true;
}

public function needsPreparation(): bool
{
return false;
}

public function prepareAuthentication(object $user): void
{
}
Expand Down