protected async Task SeedRoles(string source) { var seedRoles = SeedDataProvider.GetEntities <string>(source, Environment); foreach (var seedRole in seedRoles) { var exists = await RoleManager.RoleExistsAsync(seedRole); if (!exists) { await RoleManager.CreateAsync(new IdentityRole { Name = seedRole }); } } }
protected void AddOrUpdateCollection <TEntity>(string source) where TEntity : class { Logger.LogInformation("Seed {TEntity} from {source} for {environment}", typeof(TEntity).FullName, source, Environment); var items = SeedDataProvider.GetEntities <TEntity>(source, Environment); foreach (var item in items) { Context.Set <TEntity>().AddOrUpdate(item); } }
protected void SeedClients(string source) { var seedClients = SeedDataProvider.GetEntities <Client>(source, Environment); foreach (var seedClient in seedClients) { var currentDbClient = Clients.FirstOrDefault(c => c.ClientId == seedClient.ClientId); if (currentDbClient != null) { Clients.Remove(currentDbClient); } var secrets = seedClient.ClientSecrets.Where(c => c.Type == "SharedSecret"); foreach (var secret in secrets) { secret.Value = IdentityServer4.Models.HashExtensions.Sha256(secret.Value); } Clients.Add(seedClient); } }