From aebaea128badaedded231b4e77f216372139821c Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 11 Jun 2024 11:40:37 +0200 Subject: [PATCH] Implement 'enableTwoFactorViaEmail' using 'enableTwoFactor' --- src/Auth.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Auth.php b/src/Auth.php index 8272e7a..9ac3266 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -1960,6 +1960,26 @@ final class Auth extends UserManager { return $this->enableTwoFactor(self::TWO_FACTOR_MECHANISM_SMS, $otpValue); } + /** + * Completes the previously started setup of two-factor authentification with one-time passwords sent via email + * + * Initially providing a valid one-time password here once is what proves that the setup was successful on the client side + * + * In order to let the user set up their email address for OTPs via email, call {@see prepareTwoFactorViaEmail} as a first step + * + * @param string $otpValue a one-time password (OTP) that has just been entered by the user + * @return string[] a few recovery codes that can be used instead of one-time passwords from emails in case the user loses access to their email (address) + * @throws InvalidOneTimePasswordException if the one-time password provided by the user is not valid + * @throws TwoFactorMechanismNotInitializedException if this method of two-factor authentification has not been initialized before or if the initialization has expired + * @throws TwoFactorMechanismAlreadyEnabledException if this method of two-factor authentification has already been enabled + * @throws NotLoggedInException if the user is not currently signed in + * @throws TooManyRequestsException if the number of allowed attempts/requests has been exceeded + * @throws AuthError if an internal problem occurred (do *not* catch) + */ + public function enableTwoFactorViaEmail($otpValue) { + return $this->enableTwoFactor(self::TWO_FACTOR_MECHANISM_EMAIL, $otpValue); + } + /** * Completes the previously started setup of two-factor authentification via a specified mechanism *