1
0
Fork 0
mirror of synced 2024-05-17 11:12:41 +12:00

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
commit 05dd17bd55
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

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);

View file

@ -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
])