Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass TwoFactorTokenInterface to PreferredProviderInterface #212

Closed
danielburger1337 opened this issue Dec 31, 2023 · 1 comment
Closed

Comments

@danielburger1337
Copy link
Contributor

It would be helpful to pass the current token context to the PreferredProviderInterface::getPreferredTwoFactorProvider() method so that we can make decisions on what provider should be preferred when the preferred one is unavailable.

My use case is that I have a custom passkey provider and I also allow users to sign in with a passkey. Through a token attribute which I check in my TwoFactorProvider, I disable passkey support for users that originally authenticated with the passkey.

When passkey is the users preferred two factor provider and now the provider is blocked, the default provider order is used.

This is kinda suboptimal because "email" is before "totp" and will send an email on request. It would be better to then fallback to the TOTP provider so that a potentially unnecessary email is not sent.

An alternative would be to somehow allow to configure the order of providers, but that would require an extensive change to the codebase.

@scheb
Copy link
Owner

scheb commented Jan 6, 2024

Can't just change this, because it's a breaking change.

In my opinion, the interface should stay as simple as possible, since it's meant to be implemented in the user entity and return the user's preference. It's not really meant to contain a lot of complex business code.

The better solution would probably be to extract this piece of code

private function setPreferredProvider(TwoFactorTokenInterface $token, object $user): void
{
if (!($user instanceof PreferredProviderInterface)) {
return;
}
$preferredProvider = $user->getPreferredTwoFactorProvider();
if (!$preferredProvider) {
return;
}
try {
$token->preferTwoFactorProvider($preferredProvider);
} catch (UnknownTwoFactorProviderException) {
// Bad user input
}
}
}
into a service, which can be overwritten via config for the case when you'd need to inject your own custom logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants