2022-06-29 19:46:41 -04:00
|
|
|
|
using Bit.Core.Entities;
|
2017-06-21 14:19:07 -04:00
|
|
|
|
using Bit.Core.Enums;
|
2021-12-14 15:05:07 +00:00
|
|
|
|
using Bit.Core.Models;
|
|
|
|
|
|
using Bit.Core.Models.Api;
|
2017-06-21 14:19:07 -04:00
|
|
|
|
|
2021-12-14 15:05:07 +00:00
|
|
|
|
namespace Bit.Api.Models.Response.TwoFactor;
|
2022-08-29 14:53:16 -04:00
|
|
|
|
|
2017-06-21 14:19:07 -04:00
|
|
|
|
public class TwoFactorDuoResponseModel : ResponseModel
|
|
|
|
|
|
{
|
2018-04-02 23:18:26 -04:00
|
|
|
|
private const string ResponseObj = "twoFactorDuo";
|
|
|
|
|
|
|
2017-06-21 14:19:07 -04:00
|
|
|
|
public TwoFactorDuoResponseModel(User user)
|
2018-04-02 23:18:26 -04:00
|
|
|
|
: base(ResponseObj)
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (user == null)
|
2017-06-21 14:19:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentNullException(nameof(user));
|
2018-04-02 23:18:26 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Duo);
|
|
|
|
|
|
Build(provider);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TwoFactorDuoResponseModel(Organization org)
|
|
|
|
|
|
: base(ResponseObj)
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2018-04-02 23:18:26 -04:00
|
|
|
|
if (org == null)
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2018-04-02 23:18:26 -04:00
|
|
|
|
throw new ArgumentNullException(nameof(org));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-21 14:19:07 -04:00
|
|
|
|
var provider = org.GetTwoFactorProvider(TwoFactorProviderType.OrganizationDuo);
|
2018-04-02 23:18:26 -04:00
|
|
|
|
Build(provider);
|
2022-08-29 14:53:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-02 23:18:26 -04:00
|
|
|
|
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)
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (provider?.MetaData != null && provider.MetaData.Count > 0)
|
2018-04-02 23:18:26 -04:00
|
|
|
|
{
|
2017-06-21 14:19:07 -04:00
|
|
|
|
Enabled = provider.Enabled;
|
|
|
|
|
|
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (provider.MetaData.ContainsKey("Host"))
|
2017-06-21 14:19:07 -04:00
|
|
|
|
{
|
2017-06-21 21:46:52 -04:00
|
|
|
|
Host = (string)provider.MetaData["Host"];
|
2017-06-21 14:19:07 -04:00
|
|
|
|
}
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (provider.MetaData.ContainsKey("SKey"))
|
2017-06-21 14:19:07 -04:00
|
|
|
|
{
|
2017-06-21 21:46:52 -04:00
|
|
|
|
SecretKey = (string)provider.MetaData["SKey"];
|
2017-06-21 14:19:07 -04:00
|
|
|
|
}
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (provider.MetaData.ContainsKey("IKey"))
|
2017-06-21 14:19:07 -04:00
|
|
|
|
{
|
|
|
|
|
|
IntegrationKey = (string)provider.MetaData["IKey"];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-08-29 14:53:16 -04:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-06-21 14:19:07 -04:00
|
|
|
|
Enabled = false;
|
2022-08-29 14:53:16 -04:00
|
|
|
|
}
|
2017-06-21 14:19:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|