mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
organization 2fa apis
This commit is contained in:
@ -2,7 +2,6 @@
|
||||
using Bit.Core.Models.Table;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
@ -76,6 +75,32 @@ namespace Bit.Core.Models.Api
|
||||
return extistingUser;
|
||||
}
|
||||
|
||||
public Organization ToOrganization(Organization extistingOrg)
|
||||
{
|
||||
var providers = extistingOrg.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.OrganizationDuo))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.OrganizationDuo);
|
||||
}
|
||||
|
||||
providers.Add(TwoFactorProviderType.OrganizationDuo, new TwoFactorProvider
|
||||
{
|
||||
MetaData = new Dictionary<string, object>
|
||||
{
|
||||
["SKey"] = SecretKey,
|
||||
["IKey"] = IntegrationKey,
|
||||
["Host"] = Host
|
||||
},
|
||||
Enabled = true
|
||||
});
|
||||
extistingOrg.SetTwoFactorProviders(providers);
|
||||
return extistingOrg;
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Host.StartsWith("api-") || !Host.EndsWith(".duosecurity.com") || Host.Count(s => s == '.') != 2)
|
||||
@ -214,7 +239,7 @@ namespace Bit.Core.Models.Api
|
||||
public class TwoFactorProviderRequestModel : TwoFactorRequestModel
|
||||
{
|
||||
[Required]
|
||||
public Enums.TwoFactorProviderType? Type { get; set; }
|
||||
public TwoFactorProviderType? Type { get; set; }
|
||||
}
|
||||
|
||||
public class TwoFactorRequestModel
|
||||
|
@ -6,8 +6,10 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class TwoFactorDuoResponseModel : ResponseModel
|
||||
{
|
||||
private const string ResponseObj = "twoFactorDuo";
|
||||
|
||||
public TwoFactorDuoResponseModel(User user)
|
||||
: base("twoFactorDuo")
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
@ -15,6 +17,28 @@ namespace Bit.Core.Models.Api
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Duo);
|
||||
Build(provider);
|
||||
}
|
||||
|
||||
public TwoFactorDuoResponseModel(Organization org)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(org == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(org));
|
||||
}
|
||||
|
||||
var provider = org.GetTwoFactorProvider(TwoFactorProviderType.OrganizationDuo);
|
||||
Build(provider);
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public string Host { get; set; }
|
||||
public string SecretKey { get; set; }
|
||||
public string IntegrationKey { get; set; }
|
||||
|
||||
private void Build(TwoFactorProvider provider)
|
||||
{
|
||||
if(provider?.MetaData != null && provider.MetaData.Count > 0)
|
||||
{
|
||||
Enabled = provider.Enabled;
|
||||
@ -37,10 +61,5 @@ namespace Bit.Core.Models.Api
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public string Host { get; set; }
|
||||
public string SecretKey { get; set; }
|
||||
public string IntegrationKey { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,10 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class TwoFactorProviderResponseModel : ResponseModel
|
||||
{
|
||||
private const string ResponseObj = "twoFactorProvider";
|
||||
|
||||
public TwoFactorProviderResponseModel(TwoFactorProviderType type, TwoFactorProvider provider)
|
||||
: base("twoFactorProvider")
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(provider == null)
|
||||
{
|
||||
@ -19,7 +21,7 @@ namespace Bit.Core.Models.Api
|
||||
}
|
||||
|
||||
public TwoFactorProviderResponseModel(TwoFactorProviderType type, User user)
|
||||
: base("twoFactorProvider")
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
@ -31,6 +33,19 @@ namespace Bit.Core.Models.Api
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public TwoFactorProviderResponseModel(TwoFactorProviderType type, Organization organization)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if(organization == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(organization));
|
||||
}
|
||||
|
||||
var provider = organization.GetTwoFactorProvider(type);
|
||||
Enabled = provider?.Enabled ?? false;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public TwoFactorProviderType Type { get; set; }
|
||||
}
|
||||
|
Reference in New Issue
Block a user