From b0965525de28fd231be14f4c9e3b4b3997a5f079 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 4 Apr 2024 19:42:23 +0200 Subject: [PATCH] Implement 'prepareTwoFactorViaEmail' using 'prepareTwoFactor' --- src/Auth.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Auth.php b/src/Auth.php index cdeaa70..264a55d 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -1794,6 +1794,26 @@ final class Auth extends UserManager { return [ $phoneNumber, $otpValue ]; } + /** + * Prepares the setup of two-factor authentification with one-time passwords sent via email + * + * After performing this step, a one-time password will have to be delivered to the user via email and then be requested from the user for verification + * + * When the user has entered the one-time password from the email afterwards, call {@see enableTwoFactorViaEmail} with that one-time password + * + * @return string[] an array with the email address at index zero and the one-time password to be sent (but not otherwise displayed to the user) at index one + * @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 prepareTwoFactorViaEmail() { + $this->prepareTwoFactor(self::TWO_FACTOR_MECHANISM_EMAIL, null, null); + $otpValue = $this->generateAndStoreRandomOneTimePassword($this->getUserId(), self::TWO_FACTOR_MECHANISM_EMAIL); + + return [ $this->getEmail(), $otpValue ]; + } + /** * Prepares the setup of two-factor authentification via a specified mechanism *