1
0
mirror of https://github.com/bitwarden/server synced 2025-12-20 02:03:46 +00:00

organization 2fa apis

This commit is contained in:
Kyle Spearrin
2018-04-02 23:18:26 -04:00
parent a790c37fcc
commit 0d4ea5ce5b
7 changed files with 219 additions and 13 deletions

View File

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