Merge pull request #7949 from appwrite/fix-factors-recovery-code

Add recovery code to List factors
This commit is contained in:
Eldad A. Fux
2024-04-15 10:48:16 +02:00
committed by GitHub
2 changed files with 14 additions and 4 deletions
+5 -1
View File
@@ -3521,12 +3521,16 @@ App::get('/v1/account/mfa/factors')
->inject('user')
->action(function (Response $response, Document $user) {
$mfaRecoveryCodes = $user->getAttribute('mfaRecoveryCodes', []);
$recoveryCodeEnabled = \is_array($mfaRecoveryCodes) && \count($mfaRecoveryCodes) > 0;
$totp = TOTP::getAuthenticatorFromUser($user);
$factors = new Document([
Type::TOTP => $totp !== null && $totp->getAttribute('verified', false),
Type::EMAIL => $user->getAttribute('email', false) && $user->getAttribute('emailVerification', false),
Type::PHONE => $user->getAttribute('phone', false) && $user->getAttribute('phoneVerification', false)
Type::PHONE => $user->getAttribute('phone', false) && $user->getAttribute('phoneVerification', false),
Type::RECOVERY_CODE => $recoveryCodeEnabled
]);
$response->dynamic($factors, Response::MODEL_MFA_FACTORS);
@@ -13,19 +13,25 @@ class MFAFactors extends Model
$this
->addRule(Type::TOTP, [
'type' => self::TYPE_BOOLEAN,
'description' => 'TOTP',
'description' => 'Can TOTP be used for MFA challenge for this account.',
'default' => false,
'example' => true
])
->addRule(Type::PHONE, [
'type' => self::TYPE_BOOLEAN,
'description' => 'Phone',
'description' => 'Can phone (SMS) be used for MFA challenge for this account.',
'default' => false,
'example' => true
])
->addRule(Type::EMAIL, [
'type' => self::TYPE_BOOLEAN,
'description' => 'Email',
'description' => 'Can email be used for MFA challenge for this account.',
'default' => false,
'example' => true
])
->addRule(Type::RECOVERY_CODE, [
'type' => self::TYPE_BOOLEAN,
'description' => 'Can recovery code be used for MFA challenge for this account.',
'default' => false,
'example' => true
])