public static IIdentityServerBuilder AddInMemoryConfiguration(this IIdentityServerBuilder builder, IConfigurationSection config) { return builder .AddInMemoryIdentityResources(InMemoryConfig.GetIds(config.GetSection("Ids"))) .AddInMemoryApiResources(InMemoryConfig.GetApis(config.GetSection("Apis"))) .AddInMemoryApiScopes(InMemoryConfig.GetApiScopes(config.GetSection("Apis"))) .AddInMemoryClients(InMemoryConfig.GetClients(config.GetSection("Clients"))); }
private static void InitializeConfigurationDbContext(IConfiguration seedDataConfig, IServiceScope serviceScope) { serviceScope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>().Database.Migrate(); var context = serviceScope.ServiceProvider.GetRequiredService <ConfigurationDbContext>(); context.Database.Migrate(); if (seedDataConfig == null) { return; } if (!context.Clients.Any()) { foreach (var client in InMemoryConfig.GetClients(seedDataConfig.GetSection("Clients"))) { context.Clients.Add(client.ToEntity()); } context.SaveChanges(); } if (!context.IdentityResources.Any()) { foreach (var resource in InMemoryConfig.GetIds(seedDataConfig.GetSection("Ids"))) { context.IdentityResources.Add(resource.ToEntity()); } context.SaveChanges(); } if (!context.ApiResources.Any()) { foreach (var resource in InMemoryConfig.GetApis(seedDataConfig.GetSection("Apis"))) { context.ApiResources.Add(resource.ToEntity()); } foreach (var resource in InMemoryConfig.GetApiScopes(seedDataConfig.GetSection("Apis"))) { context.ApiScopes.Add(resource.ToEntity()); } context.SaveChanges(); } }