1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 01:22:50 -05:00

equivalent domains APIs and data models

This commit is contained in:
Kyle Spearrin
2017-01-09 22:20:34 -05:00
parent 90607f6d93
commit 7abde8c771
18 changed files with 138 additions and 29 deletions

View File

@ -15,9 +15,11 @@ namespace Bit.Core.Domains
public string Culture { get; set; } = "en-US";
public string SecurityStamp { get; set; }
public bool TwoFactorEnabled { get; set; }
public TwoFactorProvider? TwoFactorProvider { get; set; }
public TwoFactorProviderType? TwoFactorProvider { get; set; }
public string AuthenticatorKey { get; set; }
public string TwoFactorRecoveryCode { get; set; }
public string EquivalentDomains { get; set; }
public string ExcludedGlobalEquivalentDomains { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;

View File

@ -1,6 +1,6 @@
namespace Bit.Core.Enums
{
public enum CipherType : short
public enum CipherType : byte
{
Folder = 0,
Login = 1

View File

@ -1,6 +1,6 @@
namespace Bit.Core.Enums
{
public enum DeviceType : short
public enum DeviceType : byte
{
Android = 0,
iOS = 1

View File

@ -0,0 +1,8 @@
namespace Bit.Core.Enums
{
public enum GlobalEquivalentDomainsType : byte
{
Google = 0,
Apple = 1
}
}

View File

@ -1,6 +1,6 @@
namespace Bit.Core.Enums
{
public enum PushType : short
public enum PushType : byte
{
SyncCipherUpdate = 0,
SyncCipherCreate = 1,

View File

@ -1,6 +1,6 @@
namespace Bit.Core.Enums
{
public enum TwoFactorProvider
public enum TwoFactorProviderType : byte
{
Authenticator = 0
}

View File

@ -14,7 +14,7 @@ namespace Bit.Core.Identity
{
var canGenerate = user.TwoFactorEnabled
&& user.TwoFactorProvider.HasValue
&& user.TwoFactorProvider.Value == TwoFactorProvider.Authenticator
&& user.TwoFactorProvider.Value == TwoFactorProviderType.Authenticator
&& !string.IsNullOrWhiteSpace(user.AuthenticatorKey);
return Task.FromResult(canGenerate);

View File

@ -16,7 +16,7 @@ namespace Bit.Core.Services
Task<IdentityResult> ChangeEmailAsync(User user, string masterPassword, string newEmail, string newMasterPassword, string token, IEnumerable<Cipher> ciphers);
Task<IdentityResult> ChangePasswordAsync(User user, string currentMasterPasswordHash, string newMasterPasswordHash, IEnumerable<Cipher> ciphers);
Task<IdentityResult> RefreshSecurityStampAsync(User user, string masterPasswordHash);
Task GetTwoFactorAsync(User user, Enums.TwoFactorProvider provider);
Task GetTwoFactorAsync(User user, Enums.TwoFactorProviderType provider);
Task<bool> RecoverTwoFactorAsync(string email, string masterPassword, string recoveryCode);
Task<IdentityResult> DeleteAsync(User user);
}

View File

@ -216,13 +216,13 @@ namespace Bit.Core.Services
return IdentityResult.Failed(_identityErrorDescriber.PasswordMismatch());
}
public async Task GetTwoFactorAsync(User user, Enums.TwoFactorProvider provider)
public async Task GetTwoFactorAsync(User user, Enums.TwoFactorProviderType provider)
{
if(user.TwoFactorEnabled && user.TwoFactorProvider.HasValue && user.TwoFactorProvider.Value == provider)
{
switch(provider)
{
case Enums.TwoFactorProvider.Authenticator:
case Enums.TwoFactorProviderType.Authenticator:
if(!string.IsNullOrWhiteSpace(user.AuthenticatorKey))
{
return;
@ -239,7 +239,7 @@ namespace Bit.Core.Services
switch(provider)
{
case Enums.TwoFactorProvider.Authenticator:
case Enums.TwoFactorProviderType.Authenticator:
var key = KeyGeneration.GenerateRandomKey(20);
user.AuthenticatorKey = Base32Encoder.Encode(key);
break;
@ -269,7 +269,7 @@ namespace Bit.Core.Services
return false;
}
user.TwoFactorProvider = TwoFactorProvider.Authenticator;
user.TwoFactorProvider = TwoFactorProviderType.Authenticator;
user.TwoFactorEnabled = false;
user.TwoFactorRecoveryCode = null;
await SaveUserAsync(user);

View File

@ -0,0 +1,19 @@
using Bit.Core.Enums;
using System.Collections.Generic;
namespace Bit.Core.Utilities
{
public class EquivalentDomains
{
static EquivalentDomains()
{
Global = new Dictionary<GlobalEquivalentDomainsType, IEnumerable<string>>();
Global.Add(GlobalEquivalentDomainsType.Apple, new List<string>() { "apple.com", "icloud.com" });
Global.Add(GlobalEquivalentDomainsType.Google, new List<string> { "google.com", "youtube.com", "gmail.com" });
}
public static IDictionary<GlobalEquivalentDomainsType, IEnumerable<string>> Global { get; set; }
}
}