Fix MFA flows and docs

This commit is contained in:
Matej Bačo
2024-03-01 16:22:51 +00:00
parent fa8d132402
commit 5cefca1c22
20 changed files with 169 additions and 48 deletions
+3 -2
View File
@@ -12,6 +12,7 @@ abstract class Type
public const TOTP = 'totp';
public const EMAIL = 'email';
public const PHONE = 'phone';
public const RECOVERY_CODE = 'recoveryCode';
public function setLabel(string $label): self
{
@@ -47,12 +48,12 @@ abstract class Type
return $this->instance->getProvisioningUri();
}
public static function generateBackupCodes(int $length = 6, int $total = 6): array
public static function generateBackupCodes(int $length = 10, int $total = 6): array
{
$backups = [];
for ($i = 0; $i < $total; $i++) {
$backups[] = Auth::codeGenerator($length);
$backups[] = Auth::tokenGenerator($length);
}
return $backups;
+1
View File
@@ -89,6 +89,7 @@ class Exception extends \Exception
public const USER_MISSING_ID = 'user_missing_id';
public const USER_MORE_FACTORS_REQUIRED = 'user_more_factors_required';
public const USER_INVALID_CHALLENGE = 'user_invalid_challenge';
public const USER_RECOVERY_CODES_ALREADY_EXISTS = 'user_recovery_codes_already_exists';
public const USER_OAUTH2_BAD_REQUEST = 'user_oauth2_bad_request';
public const USER_OAUTH2_UNAUTHORIZED = 'user_oauth2_unauthorized';
public const USER_OAUTH2_PROVIDER_ERROR = 'user_oauth2_provider_error';
+3
View File
@@ -82,6 +82,7 @@ use Appwrite\Utopia\Response\Model\MetricBreakdown;
use Appwrite\Utopia\Response\Model\Provider;
use Appwrite\Utopia\Response\Model\Message;
use Appwrite\Utopia\Response\Model\MFAFactors;
use Appwrite\Utopia\Response\Model\MFARecoveryCodes;
use Appwrite\Utopia\Response\Model\MFAType;
use Appwrite\Utopia\Response\Model\Subscriber;
use Appwrite\Utopia\Response\Model\Topic;
@@ -174,6 +175,7 @@ class Response extends SwooleResponse
public const MODEL_MFA_FACTORS = 'mfaFactors';
public const MODEL_MFA_OTP = 'mfaTotp';
public const MODEL_MFA_CHALLENGE = 'mfaChallenge';
public const MODEL_MFA_RECOVERY_CODES = 'mfaRecoveryCodes';
// Users password algos
public const MODEL_ALGO_MD5 = 'algoMd5';
@@ -443,6 +445,7 @@ class Response extends SwooleResponse
->setModel(new TemplateEmail())
->setModel(new ConsoleVariables())
->setModel(new MFAChallenge())
->setModel(new MFARecoveryCodes())
->setModel(new MFAType())
->setModel(new MFAFactors())
->setModel(new Provider())
@@ -13,6 +13,7 @@ class Account extends User
$this
->removeRule('password')
->removeRule('hash')
->removeRule('mfaRecoveryCodes')
->removeRule('hashOptions');
}
@@ -0,0 +1,42 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class MFARecoveryCodes extends Model
{
public function __construct()
{
$this
->addRule('recoveryCodes', [
'type' => self::TYPE_STRING,
'description' => 'Recovery codes.',
'array' => true,
'default' => [],
'example' => ['a3kf0-s0cl2', 's0co1-as98s']
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName(): string
{
return 'MFA Recovery Codes';
}
/**
* Get Type
*
* @return string
*/
public function getType(): string
{
return Response::MODEL_MFA_RECOVERY_CODES;
}
}
@@ -10,13 +10,6 @@ class MFAType extends Model
public function __construct()
{
$this
->addRule('backups', [
'type' => self::TYPE_STRING,
'description' => 'Backup codes.',
'array' => true,
'default' => [],
'example' => true
])
->addRule('secret', [
'type' => self::TYPE_STRING,
'description' => 'Secret token used for TOTP factor.',