diff --git a/src/Infrastructure.EntityFramework/Auth/Repositories/OpaqueKeyExchangeCredentialRepository.cs b/src/Infrastructure.EntityFramework/Auth/Repositories/OpaqueKeyExchangeCredentialRepository.cs index 51ba304e3e..994654e8a8 100644 --- a/src/Infrastructure.EntityFramework/Auth/Repositories/OpaqueKeyExchangeCredentialRepository.cs +++ b/src/Infrastructure.EntityFramework/Auth/Repositories/OpaqueKeyExchangeCredentialRepository.cs @@ -3,19 +3,25 @@ using Bit.Core.Auth.Entities; using Bit.Core.Auth.Models.Data; using Bit.Core.Auth.Repositories; using Bit.Core.KeyManagement.UserKey; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; namespace Bit.Infrastructure.EntityFramework.Repositories; public class OpaqueKeyExchangeCredentialRepository : Repository, IOpaqueKeyExchangeCredentialRepository { - public OpaqueKeyExchangeCredentialRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => null) + public OpaqueKeyExchangeCredentialRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OpaqueKeyExchangeCredentials) { } - public Task GetByUserIdAsync(Guid userId) + public async Task GetByUserIdAsync(Guid userId) { - return null; + using (var scope = ServiceScopeFactory.CreateScope()) + { + var dbContext = GetDatabaseContext(scope); + var opaqueConfig = await GetDbSet(dbContext).SingleOrDefaultAsync(sc => sc.UserId == userId); + return Mapper.Map(opaqueConfig); + } } public UpdateEncryptedDataForKeyRotation UpdateKeysForRotationAsync(Guid userId, IEnumerable credentials) { diff --git a/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs b/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs index dd1b97b4f2..61e69a7f19 100644 --- a/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs +++ b/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs @@ -51,6 +51,7 @@ public class DatabaseContext : DbContext public DbSet Groups { get; set; } public DbSet GroupUsers { get; set; } public DbSet Installations { get; set; } + public DbSet OpaqueKeyExchangeCredentials { get; set; } public DbSet Organizations { get; set; } public DbSet OrganizationApiKeys { get; set; } public DbSet OrganizationSponsorships { get; set; } @@ -106,6 +107,7 @@ public class DatabaseContext : DbContext var eSsoConfig = builder.Entity(); var eTaxRate = builder.Entity(); var eUser = builder.Entity(); + var eOpaqueCredential = builder.Entity(); var eOrganizationApiKey = builder.Entity(); var eOrganizationConnection = builder.Entity(); var eOrganizationDomain = builder.Entity(); @@ -122,6 +124,7 @@ public class DatabaseContext : DbContext eProvider.Property(c => c.Id).ValueGeneratedNever(); eProviderUser.Property(c => c.Id).ValueGeneratedNever(); eProviderOrganization.Property(c => c.Id).ValueGeneratedNever(); + eOpaqueCredential.Property(c => c.Id).ValueGeneratedNever(); eOrganizationApiKey.Property(c => c.Id).ValueGeneratedNever(); eOrganizationConnection.Property(c => c.Id).ValueGeneratedNever(); eOrganizationDomain.Property(ar => ar.Id).ValueGeneratedNever(); @@ -162,6 +165,7 @@ public class DatabaseContext : DbContext eProviderOrganization.ToTable(nameof(ProviderOrganization)); eSsoConfig.ToTable(nameof(SsoConfig)); eTaxRate.ToTable(nameof(TaxRate)); + eOpaqueCredential.ToTable(nameof(Core.Auth.Entities.OpaqueKeyExchangeCredential)); eOrganizationApiKey.ToTable(nameof(OrganizationApiKey)); eOrganizationConnection.ToTable(nameof(OrganizationConnection)); eOrganizationDomain.ToTable(nameof(OrganizationDomain));