/// <summary> /// Generate default clients, identity and api resources /// </summary> private static async Task EnsureSeedIdentityServerData(SsoContext context, IConfiguration configuration) { if (!context.Clients.Any()) { foreach (var client in Clients.GetAdminClient(configuration).ToList()) { await context.Clients.AddAsync(client.ToEntity()); } await context.SaveChangesAsync(); } if (!context.IdentityResources.Any()) { var identityResources = ClientResources.GetIdentityResources().ToList(); foreach (var resource in identityResources) { await context.IdentityResources.AddAsync(resource.ToEntity()); } await context.SaveChangesAsync(); } if (!context.ApiResources.Any()) { foreach (var resource in ClientResources.GetApiResources().ToList()) { await context.ApiResources.AddAsync(resource.ToEntity()); } await context.SaveChangesAsync(); } }
/// <summary> /// Generate default clients, identity and api resources /// </summary> private static async Task EnsureSeedIdentityServerData(SsoContext context, IConfiguration configuration, IConfigurationOptions configOptions) { #region clients foreach (var client in Clients.GetAdminClient(configuration).ToList()) { if (context.Clients.FirstOrDefault(s => s.ClientId == client.ClientId) == null) { await context.Clients.AddAsync(client.ToEntity()); } } await context.SaveChangesAsync(); #endregion #region ClientResources var identityResources = ClientResources.GetIdentityResources().ToList(); foreach (var resource in identityResources) { if (context.IdentityResources.FirstOrDefault(s => s.Name == resource.Name) == null) { await context.IdentityResources.AddAsync(resource.ToEntity()); } } await context.SaveChangesAsync(); #endregion #region ApiResources foreach (var resource in ClientResources.GetApiResources(configOptions).ToList()) { if (context.ApiResources.FirstOrDefault(s => s.Name == resource.Name) == null) { await context.ApiResources.AddAsync(resource.ToEntity()); } } await context.SaveChangesAsync(); #endregion }