mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 09:32:48 -05:00
[PM-1188] Server owner auth migration (#2825)
* [PM-1188] add sso project to auth * [PM-1188] move sso api models to auth * [PM-1188] fix sso api model namespace & imports * [PM-1188] move core files to auth * [PM-1188] fix core sso namespace & models * [PM-1188] move sso repository files to auth * [PM-1188] fix sso repo files namespace & imports * [PM-1188] move sso sql files to auth folder * [PM-1188] move sso test files to auth folders * [PM-1188] fix sso tests namespace & imports * [PM-1188] move auth api files to auth folder * [PM-1188] fix auth api files namespace & imports * [PM-1188] move auth core files to auth folder * [PM-1188] fix auth core files namespace & imports * [PM-1188] move auth email templates to auth folder * [PM-1188] move auth email folder back into shared directory * [PM-1188] fix auth email names * [PM-1188] move auth core models to auth folder * [PM-1188] fix auth model namespace & imports * [PM-1188] add entire Identity project to auth codeowners * [PM-1188] fix auth orm files namespace & imports * [PM-1188] move auth orm files to auth folder * [PM-1188] move auth sql files to auth folder * [PM-1188] move auth tests to auth folder * [PM-1188] fix auth test files namespace & imports * [PM-1188] move emergency access api files to auth folder * [PM-1188] fix emergencyaccess api files namespace & imports * [PM-1188] move emergency access core files to auth folder * [PM-1188] fix emergency access core files namespace & imports * [PM-1188] move emergency access orm files to auth folder * [PM-1188] fix emergency access orm files namespace & imports * [PM-1188] move emergency access sql files to auth folder * [PM-1188] move emergencyaccess test files to auth folder * [PM-1188] fix emergency access test files namespace & imports * [PM-1188] move captcha files to auth folder * [PM-1188] fix captcha files namespace & imports * [PM-1188] move auth admin files into auth folder * [PM-1188] fix admin auth files namespace & imports - configure mvc to look in auth folders for views * [PM-1188] remove extra imports and formatting * [PM-1188] fix ef auth model imports * [PM-1188] fix DatabaseContextModelSnapshot paths * [PM-1188] fix grant import in ef * [PM-1188] update sqlproj * [PM-1188] move missed sqlproj files * [PM-1188] move auth ef models out of auth folder * [PM-1188] fix auth ef models namespace * [PM-1188] remove auth ef models unused imports * [PM-1188] fix imports for auth ef models * [PM-1188] fix more ef model imports * [PM-1188] fix file encodings
This commit is contained in:
@ -1,41 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Api;
|
||||
|
||||
namespace Bit.Api.Models.Response;
|
||||
|
||||
public class AuthRequestResponseModel : ResponseModel
|
||||
{
|
||||
public AuthRequestResponseModel(AuthRequest authRequest, string vaultUri, string obj = "auth-request")
|
||||
: base(obj)
|
||||
{
|
||||
if (authRequest == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(authRequest));
|
||||
}
|
||||
|
||||
Id = authRequest.Id.ToString();
|
||||
PublicKey = authRequest.PublicKey;
|
||||
RequestDeviceType = authRequest.RequestDeviceType.GetType().GetMember(authRequest.RequestDeviceType.ToString())
|
||||
.FirstOrDefault()?.GetCustomAttribute<DisplayAttribute>()?.GetName();
|
||||
RequestIpAddress = authRequest.RequestIpAddress;
|
||||
Key = authRequest.Key;
|
||||
MasterPasswordHash = authRequest.MasterPasswordHash;
|
||||
CreationDate = authRequest.CreationDate;
|
||||
RequestApproved = authRequest.Approved ?? false;
|
||||
Origin = new Uri(vaultUri).Host;
|
||||
ResponseDate = authRequest.ResponseDate;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string PublicKey { get; set; }
|
||||
public string RequestDeviceType { get; set; }
|
||||
public string RequestIpAddress { get; set; }
|
||||
public string Key { get; set; }
|
||||
public string MasterPasswordHash { get; set; }
|
||||
public DateTime CreationDate { get; set; }
|
||||
public DateTime? ResponseDate { get; set; }
|
||||
public bool RequestApproved { get; set; }
|
||||
public string Origin { get; set; }
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
using Bit.Api.Vault.Models.Response;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Api;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Core.Vault.Models.Data;
|
||||
|
||||
namespace Bit.Api.Models.Response;
|
||||
|
||||
public class EmergencyAccessResponseModel : ResponseModel
|
||||
{
|
||||
public EmergencyAccessResponseModel(EmergencyAccess emergencyAccess, string obj = "emergencyAccess") : base(obj)
|
||||
{
|
||||
if (emergencyAccess == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(emergencyAccess));
|
||||
}
|
||||
|
||||
Id = emergencyAccess.Id.ToString();
|
||||
Status = emergencyAccess.Status;
|
||||
Type = emergencyAccess.Type;
|
||||
WaitTimeDays = emergencyAccess.WaitTimeDays;
|
||||
}
|
||||
|
||||
public EmergencyAccessResponseModel(EmergencyAccessDetails emergencyAccess, string obj = "emergencyAccess") : base(obj)
|
||||
{
|
||||
if (emergencyAccess == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(emergencyAccess));
|
||||
}
|
||||
|
||||
Id = emergencyAccess.Id.ToString();
|
||||
Status = emergencyAccess.Status;
|
||||
Type = emergencyAccess.Type;
|
||||
WaitTimeDays = emergencyAccess.WaitTimeDays;
|
||||
}
|
||||
|
||||
public string Id { get; private set; }
|
||||
public EmergencyAccessStatusType Status { get; private set; }
|
||||
public EmergencyAccessType Type { get; private set; }
|
||||
public int WaitTimeDays { get; private set; }
|
||||
}
|
||||
|
||||
public class EmergencyAccessGranteeDetailsResponseModel : EmergencyAccessResponseModel
|
||||
{
|
||||
public EmergencyAccessGranteeDetailsResponseModel(EmergencyAccessDetails emergencyAccess)
|
||||
: base(emergencyAccess, "emergencyAccessGranteeDetails")
|
||||
{
|
||||
if (emergencyAccess == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(emergencyAccess));
|
||||
}
|
||||
|
||||
GranteeId = emergencyAccess.GranteeId.ToString();
|
||||
Email = emergencyAccess.GranteeEmail;
|
||||
Name = emergencyAccess.GranteeName;
|
||||
AvatarColor = emergencyAccess.GranteeAvatarColor;
|
||||
}
|
||||
|
||||
public string GranteeId { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string Email { get; private set; }
|
||||
public string AvatarColor { get; private set; }
|
||||
}
|
||||
|
||||
public class EmergencyAccessGrantorDetailsResponseModel : EmergencyAccessResponseModel
|
||||
{
|
||||
public EmergencyAccessGrantorDetailsResponseModel(EmergencyAccessDetails emergencyAccess)
|
||||
: base(emergencyAccess, "emergencyAccessGrantorDetails")
|
||||
{
|
||||
if (emergencyAccess == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(emergencyAccess));
|
||||
}
|
||||
|
||||
GrantorId = emergencyAccess.GrantorId.ToString();
|
||||
Email = emergencyAccess.GrantorEmail;
|
||||
Name = emergencyAccess.GrantorName;
|
||||
AvatarColor = emergencyAccess.GrantorAvatarColor;
|
||||
}
|
||||
|
||||
public string GrantorId { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string Email { get; private set; }
|
||||
public string AvatarColor { get; private set; }
|
||||
}
|
||||
|
||||
public class EmergencyAccessTakeoverResponseModel : ResponseModel
|
||||
{
|
||||
public EmergencyAccessTakeoverResponseModel(EmergencyAccess emergencyAccess, User grantor, string obj = "emergencyAccessTakeover") : base(obj)
|
||||
{
|
||||
if (emergencyAccess == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(emergencyAccess));
|
||||
}
|
||||
|
||||
KeyEncrypted = emergencyAccess.KeyEncrypted;
|
||||
Kdf = grantor.Kdf;
|
||||
KdfIterations = grantor.KdfIterations;
|
||||
KdfMemory = grantor.KdfMemory;
|
||||
KdfParallelism = grantor.KdfParallelism;
|
||||
}
|
||||
|
||||
public int KdfIterations { get; private set; }
|
||||
public int? KdfMemory { get; private set; }
|
||||
public int? KdfParallelism { get; private set; }
|
||||
public KdfType Kdf { get; private set; }
|
||||
public string KeyEncrypted { get; private set; }
|
||||
}
|
||||
|
||||
public class EmergencyAccessViewResponseModel : ResponseModel
|
||||
{
|
||||
public EmergencyAccessViewResponseModel(
|
||||
IGlobalSettings globalSettings,
|
||||
EmergencyAccess emergencyAccess,
|
||||
IEnumerable<CipherDetails> ciphers)
|
||||
: base("emergencyAccessView")
|
||||
{
|
||||
KeyEncrypted = emergencyAccess.KeyEncrypted;
|
||||
Ciphers = ciphers.Select(c => new CipherResponseModel(c, globalSettings));
|
||||
}
|
||||
|
||||
public string KeyEncrypted { get; set; }
|
||||
public IEnumerable<CipherResponseModel> Ciphers { get; set; }
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Api;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Settings;
|
||||
|
||||
namespace Bit.Api.Models.Response.Organizations;
|
||||
|
||||
public class OrganizationSsoResponseModel : ResponseModel
|
||||
{
|
||||
public OrganizationSsoResponseModel(Organization organization, GlobalSettings globalSettings,
|
||||
SsoConfig config = null) : base("organizationSso")
|
||||
{
|
||||
if (config != null)
|
||||
{
|
||||
Enabled = config.Enabled;
|
||||
Data = config.GetData();
|
||||
}
|
||||
|
||||
Identifier = organization.Identifier;
|
||||
Urls = new SsoUrls(organization.Id.ToString(), globalSettings);
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public string Identifier { get; set; }
|
||||
public SsoConfigurationData Data { get; set; }
|
||||
public SsoUrls Urls { get; set; }
|
||||
}
|
||||
|
||||
public class SsoUrls
|
||||
{
|
||||
public SsoUrls(string organizationId, GlobalSettings globalSettings)
|
||||
{
|
||||
CallbackPath = SsoConfigurationData.BuildCallbackPath(globalSettings.BaseServiceUri.Sso);
|
||||
SignedOutCallbackPath = SsoConfigurationData.BuildSignedOutCallbackPath(globalSettings.BaseServiceUri.Sso);
|
||||
SpEntityId = SsoConfigurationData.BuildSaml2ModulePath(globalSettings.BaseServiceUri.Sso);
|
||||
SpMetadataUrl = SsoConfigurationData.BuildSaml2MetadataUrl(globalSettings.BaseServiceUri.Sso, organizationId);
|
||||
SpAcsUrl = SsoConfigurationData.BuildSaml2AcsUrl(globalSettings.BaseServiceUri.Sso, organizationId);
|
||||
}
|
||||
|
||||
public string CallbackPath { get; set; }
|
||||
public string SignedOutCallbackPath { get; set; }
|
||||
public string SpEntityId { get; set; }
|
||||
public string SpMetadataUrl { get; set; }
|
||||
public string SpAcsUrl { get; set; }
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Auth.Models.Data;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Enums.Provider;
|
||||
using Bit.Core.Models.Api;
|
||||
using Bit.Core.Models.Data;
|
||||
|
@ -1,34 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Api;
|
||||
using OtpNet;
|
||||
|
||||
namespace Bit.Api.Models.Response.TwoFactor;
|
||||
|
||||
public class TwoFactorAuthenticatorResponseModel : ResponseModel
|
||||
{
|
||||
public TwoFactorAuthenticatorResponseModel(User user)
|
||||
: base("twoFactorAuthenticator")
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Authenticator);
|
||||
if (provider?.MetaData?.ContainsKey("Key") ?? false)
|
||||
{
|
||||
Key = (string)provider.MetaData["Key"];
|
||||
Enabled = provider.Enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
var key = KeyGeneration.GenerateRandomKey(20);
|
||||
Key = Base32Encoding.ToString(key);
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public string Key { get; set; }
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models;
|
||||
using Bit.Core.Models.Api;
|
||||
|
||||
namespace Bit.Api.Models.Response.TwoFactor;
|
||||
|
||||
public class TwoFactorDuoResponseModel : ResponseModel
|
||||
{
|
||||
private const string ResponseObj = "twoFactorDuo";
|
||||
|
||||
public TwoFactorDuoResponseModel(User user)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (provider.MetaData.ContainsKey("Host"))
|
||||
{
|
||||
Host = (string)provider.MetaData["Host"];
|
||||
}
|
||||
if (provider.MetaData.ContainsKey("SKey"))
|
||||
{
|
||||
SecretKey = (string)provider.MetaData["SKey"];
|
||||
}
|
||||
if (provider.MetaData.ContainsKey("IKey"))
|
||||
{
|
||||
IntegrationKey = (string)provider.MetaData["IKey"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Api;
|
||||
|
||||
namespace Bit.Api.Models.Response.TwoFactor;
|
||||
|
||||
public class TwoFactorEmailResponseModel : ResponseModel
|
||||
{
|
||||
public TwoFactorEmailResponseModel(User user)
|
||||
: base("twoFactorEmail")
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.Email);
|
||||
if (provider?.MetaData?.ContainsKey("Email") ?? false)
|
||||
{
|
||||
Email = (string)provider.MetaData["Email"];
|
||||
Enabled = provider.Enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public string Email { get; set; }
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models;
|
||||
using Bit.Core.Models.Api;
|
||||
|
||||
namespace Bit.Api.Models.Response.TwoFactor;
|
||||
|
||||
public class TwoFactorProviderResponseModel : ResponseModel
|
||||
{
|
||||
private const string ResponseObj = "twoFactorProvider";
|
||||
|
||||
public TwoFactorProviderResponseModel(TwoFactorProviderType type, TwoFactorProvider provider)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if (provider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(provider));
|
||||
}
|
||||
|
||||
Enabled = provider.Enabled;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public TwoFactorProviderResponseModel(TwoFactorProviderType type, User user)
|
||||
: base(ResponseObj)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(type);
|
||||
Enabled = provider?.Enabled ?? false;
|
||||
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; }
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Api;
|
||||
|
||||
namespace Bit.Api.Models.Response.TwoFactor;
|
||||
|
||||
public class TwoFactorRecoverResponseModel : ResponseModel
|
||||
{
|
||||
public TwoFactorRecoverResponseModel(User user)
|
||||
: base("twoFactorRecover")
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
Code = user.TwoFactorRecoveryCode;
|
||||
}
|
||||
|
||||
public string Code { get; set; }
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models;
|
||||
using Bit.Core.Models.Api;
|
||||
|
||||
namespace Bit.Api.Models.Response.TwoFactor;
|
||||
|
||||
public class TwoFactorWebAuthnResponseModel : ResponseModel
|
||||
{
|
||||
public TwoFactorWebAuthnResponseModel(User user)
|
||||
: base("twoFactorWebAuthn")
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.WebAuthn);
|
||||
Enabled = provider?.Enabled ?? false;
|
||||
Keys = provider?.MetaData?
|
||||
.Where(k => k.Key.StartsWith("Key"))
|
||||
.Select(k => new KeyModel(k.Key, new TwoFactorProvider.WebAuthnData((dynamic)k.Value)));
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public IEnumerable<KeyModel> Keys { get; set; }
|
||||
|
||||
public class KeyModel
|
||||
{
|
||||
public KeyModel(string id, TwoFactorProvider.WebAuthnData data)
|
||||
{
|
||||
Name = data.Name;
|
||||
Id = Convert.ToInt32(id.Replace("Key", string.Empty));
|
||||
Migrated = data.Migrated;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
public bool Migrated { get; set; }
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Api;
|
||||
|
||||
namespace Bit.Api.Models.Response.TwoFactor;
|
||||
|
||||
public class TwoFactorYubiKeyResponseModel : ResponseModel
|
||||
{
|
||||
public TwoFactorYubiKeyResponseModel(User user)
|
||||
: base("twoFactorYubiKey")
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.YubiKey);
|
||||
if (provider?.MetaData != null && provider.MetaData.Count > 0)
|
||||
{
|
||||
Enabled = provider.Enabled;
|
||||
|
||||
if (provider.MetaData.ContainsKey("Key1"))
|
||||
{
|
||||
Key1 = (string)provider.MetaData["Key1"];
|
||||
}
|
||||
if (provider.MetaData.ContainsKey("Key2"))
|
||||
{
|
||||
Key2 = (string)provider.MetaData["Key2"];
|
||||
}
|
||||
if (provider.MetaData.ContainsKey("Key3"))
|
||||
{
|
||||
Key3 = (string)provider.MetaData["Key3"];
|
||||
}
|
||||
if (provider.MetaData.ContainsKey("Key4"))
|
||||
{
|
||||
Key4 = (string)provider.MetaData["Key4"];
|
||||
}
|
||||
if (provider.MetaData.ContainsKey("Key5"))
|
||||
{
|
||||
Key5 = (string)provider.MetaData["Key5"];
|
||||
}
|
||||
if (provider.MetaData.ContainsKey("Nfc"))
|
||||
{
|
||||
Nfc = (bool)provider.MetaData["Nfc"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
public string Key1 { get; set; }
|
||||
public string Key2 { get; set; }
|
||||
public string Key3 { get; set; }
|
||||
public string Key4 { get; set; }
|
||||
public string Key5 { get; set; }
|
||||
public bool Nfc { get; set; }
|
||||
}
|
Reference in New Issue
Block a user