mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
Require 2FA token in order to disiable 2FA. Added 2FA recovery code to data/domain model and exposed recover and regenerate 2FA APIs
This commit is contained in:
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class RecoverTwoFactorRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
[StringLength(32)]
|
||||
public string RecoveryCode { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class RegenerateTwoFactorRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
public string Token { get; set; }
|
||||
}
|
||||
}
|
@ -3,21 +3,14 @@ using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Models
|
||||
{
|
||||
public class UpdateTwoFactorRequestModel : IValidatableObject
|
||||
public class UpdateTwoFactorRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string MasterPasswordHash { get; set; }
|
||||
[Required]
|
||||
public bool? Enabled { get; set; }
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
public string Token { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(Enabled.HasValue && Enabled.Value && string.IsNullOrWhiteSpace(Token))
|
||||
{
|
||||
yield return new ValidationResult("Token is required.", new[] { "Token" });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,12 @@ namespace Bit.Api.Models
|
||||
TwoFactorEnabled = user.TwoFactorEnabled;
|
||||
AuthenticatorKey = user.AuthenticatorKey;
|
||||
TwoFactorProvider = user.TwoFactorProvider;
|
||||
TwoFactorRecoveryCode = user.TwoFactorRecoveryCode;
|
||||
}
|
||||
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
public TwoFactorProvider? TwoFactorProvider { get; set; }
|
||||
public string AuthenticatorKey { get; set; }
|
||||
public string TwoFactorRecoveryCode { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user