Skip to content

Commit

Permalink
Merge pull request #1624 from stefannikolei/sn/fix/1616
Browse files Browse the repository at this point in the history
ClientConfigurationStore now uses IConfigurationDbContext
  • Loading branch information
josephdecock authored Dec 1, 2024
2 parents d1e1717 + fb9c8c0 commit df77918
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/Configuration.EntityFramework/ClientConfigurationStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


using Duende.IdentityServer.EntityFramework.DbContexts;
using Duende.IdentityServer.EntityFramework.Interfaces;
using Duende.IdentityServer.EntityFramework.Mappers;
using Duende.IdentityServer.Models;
using Duende.IdentityServer.Services;
Expand All @@ -19,7 +20,7 @@ public class ClientConfigurationStore : IClientConfigurationStore
/// <summary>
/// The DbContext.
/// </summary>
protected readonly ConfigurationDbContext DbContext;
protected readonly IConfigurationDbContext DbContext;

/// <summary>
/// The CancellationToken provider.
Expand All @@ -36,7 +37,7 @@ public class ClientConfigurationStore : IClientConfigurationStore
/// class.
/// </summary>
public ClientConfigurationStore(
ConfigurationDbContext dbContext,
IConfigurationDbContext dbContext,
ICancellationTokenProvider cancellationTokenProvider,
ILogger<ClientConfigurationStore> logger)
{
Expand All @@ -48,8 +49,8 @@ public ClientConfigurationStore(
/// <inheritdoc />
public async Task AddAsync(Client client)
{
Logger.LogDebug("Adding client {clientId} to configuration store", client.ClientId);
DbContext.Clients.Add(ClientMappers.ToEntity(client));
Logger.LogDebug("Adding client {ClientId} to configuration store", client.ClientId);
DbContext.Clients.Add(client.ToEntity());
await DbContext.SaveChangesAsync(CancellationTokenProvider.CancellationToken);
}
}
17 changes: 17 additions & 0 deletions src/EntityFramework.Storage/Interfaces/IConfigurationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#nullable enable

using System;
using System.Threading;
using System.Threading.Tasks;
using Duende.IdentityServer.EntityFramework.Entities;
using Microsoft.EntityFrameworkCore;

Expand Down Expand Up @@ -63,4 +65,19 @@ public interface IConfigurationDbContext : IDisposable
/// The identity providers.
/// </value>
DbSet<IdentityProvider> IdentityProviders { get; set; }

/// <summary>
/// Saves the changes.
/// </summary>
/// <returns></returns>
Task<int> SaveChangesAsync(CancellationToken cancellationToken);

// this is here only because of this: https://github.com/DuendeSoftware/IdentityServer/issues/472
// and because Microsoft implements the old API explicitly: https://github.com/dotnet/aspnetcore/blob/v6.0.0-rc.2.21480.10/src/Identity/ApiAuthorization.IdentityServer/src/Data/ApiAuthorizationDbContext.cs

/// <summary>
/// Saves the changes.
/// </summary>
/// <returns></returns>
Task<int> SaveChangesAsync() => SaveChangesAsync(CancellationToken.None);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.EntityFrameworkCore.Storage;
using Duende.IdentityServer.Services;
using Duende.IdentityServer.EntityFramework.Options;
using Duende.IdentityServer.EntityFramework.Storage;

namespace IntegrationTests.TestHosts;

Expand Down Expand Up @@ -39,8 +40,10 @@ private void ConfigureServices(IServiceCollection services, InMemoryDatabaseRoot
})
.AddClientConfigurationStore();
services.AddSingleton(new ConfigurationStoreOptions());
services.AddDbContext<ConfigurationDbContext>(opt =>
opt.UseInMemoryDatabase("configurationDb", databaseRoot));
services.AddConfigurationDbContext(options => {
options.ConfigureDbContext = b =>
b.UseInMemoryDatabase("configurationDb", databaseRoot);
});
}

private void Configure(WebApplication app)
Expand Down

0 comments on commit df77918

Please sign in to comment.