mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-08-03 22:57:27 +02:00
Implement 'prepareTwoFactorViaSms' using 'prepareTwoFactor'
This commit is contained in:
28
src/Auth.php
28
src/Auth.php
@@ -1766,6 +1766,34 @@ final class Auth extends UserManager {
|
|||||||
return $this->prepareTwoFactor(self::TWO_FACTOR_MECHANISM_TOTP, $serviceName, null);
|
return $this->prepareTwoFactor(self::TWO_FACTOR_MECHANISM_TOTP, $serviceName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares the setup of two-factor authentification with one-time passwords sent via SMS
|
||||||
|
*
|
||||||
|
* After performing this step, a one-time password will have to be delivered to the user via SMS and then be requested from the user for verification
|
||||||
|
*
|
||||||
|
* When the user has entered the one-time password from the text message afterwards, call {@see enableTwoFactorViaSms} with that one-time password
|
||||||
|
*
|
||||||
|
* @param string $phoneNumber the phone number to send the one-time passwords to
|
||||||
|
* @return string[] an array with the phone number at index zero and the one-time password to be sent (but not otherwise displayed to the user) at index one
|
||||||
|
* @throws InvalidPhoneNumberException if no valid phone number has been provided
|
||||||
|
* @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 prepareTwoFactorViaSms($phoneNumber) {
|
||||||
|
$phoneNumber = !empty($phoneNumber) ? \trim((string) $phoneNumber) : '';
|
||||||
|
|
||||||
|
if (\strlen($phoneNumber) < 3) {
|
||||||
|
throw new InvalidPhoneNumberException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->prepareTwoFactor(self::TWO_FACTOR_MECHANISM_SMS, null, $phoneNumber);
|
||||||
|
$otpValue = $this->generateAndStoreRandomOneTimePassword($this->getUserId(), self::TWO_FACTOR_MECHANISM_SMS);
|
||||||
|
|
||||||
|
return [ $phoneNumber, $otpValue ];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the setup of two-factor authentification via a specified mechanism
|
* Prepares the setup of two-factor authentification via a specified mechanism
|
||||||
*
|
*
|
||||||
|
11
src/InvalidPhoneNumberException.php
Normal file
11
src/InvalidPhoneNumberException.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PHP-Auth (https://github.com/delight-im/PHP-Auth)
|
||||||
|
* Copyright (c) delight.im (https://www.delight.im/)
|
||||||
|
* Licensed under the MIT License (https://opensource.org/licenses/MIT)
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Delight\Auth;
|
||||||
|
|
||||||
|
class InvalidPhoneNumberException extends AuthException {}
|
Reference in New Issue
Block a user