From 0ff92ce870b54c1a61b454b00d0239971ee28ed7 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 4 Apr 2024 19:34:24 +0200 Subject: [PATCH] Re-implement 'prepareTwoFactorViaTotp' using 'prepareTwoFactor' --- src/Auth.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Auth.php b/src/Auth.php index 7c9365a..bf0b715 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -1746,6 +1746,26 @@ final class Auth extends UserManager { } } + /** + * Prepares the setup of two-factor authentification via time-based one-time passwords (TOTP) + * + * After performing this step, the user will be able to add the service or application to their authenticator application + * + * When the user has entered a one-time password from their authenticator application afterwards, call {@see enableTwoFactorViaTotp} with that one-time password + * + * @param string|null $serviceName (optional) the name of the service or application that the user interacts with, often the domain name or application title + * @return string[] an array with the key URI (which can be encoded as a QR code) at index zero and the secret string (for manual input) 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 prepareTwoFactorViaTotp($serviceName = null) { + $serviceName = !empty($serviceName) ? (string) $serviceName : (!empty($_SERVER['SERVER_NAME']) ? (string) $_SERVER['SERVER_NAME'] : (string) $_SERVER['SERVER_ADDR']); + + return $this->prepareTwoFactor(self::TWO_FACTOR_MECHANISM_TOTP, $serviceName, null); + } + /** * Prepares the setup of two-factor authentification via a specified mechanism *