private async Task <bool> CanInsertIdentityResourceAsync(IdentityResource entity) { if (entity.Id == 0) { var existsWithSameName = await IdentityResources.Where(x => x.Name == entity.Name).SingleOrDefaultAsync(); return(existsWithSameName == null); } else { var existsWithSameName = await IdentityResources.Where(x => x.Name == entity.Name && x.Id != entity.Id).SingleOrDefaultAsync(); return(existsWithSameName == null); } }
public static int Seed(ConfigurationDbContext context) { var missingClients = Clients.Where(x => !context.Clients.Any(y => y.ClientId == x.ClientId)); context.Clients.AddRange(missingClients.Select(x => x.ToEntity())); var missingApiResources = ApiResources.Where(x => !context.ApiResources.Any(y => y.Name == x.Name)); context.ApiResources.AddRange(missingApiResources.Select(x => x.ToEntity())); var missingApiScopes = ApiScopes.Where(x => !context.ApiScopes.Any(y => y.Name == x.Name)); context.ApiScopes.AddRange(missingApiScopes.Select(x => x.ToEntity())); var missingIdentityResources = IdentityResources.Where(x => !context.IdentityResources.Any(y => y.Name == x.Name)); foreach (var idr in missingIdentityResources) { var idrToEntity = idr.ToEntity(); if (idrToEntity.Name == IdentityServerConstants.StandardScopes.OpenId || idrToEntity.Name == IdentityServerConstants.StandardScopes.Profile) { idrToEntity.NonEditable = true; } context.IdentityResources.Add(idrToEntity); } try { context.SaveChanges(); } catch (Exception) { return(1); } return(0); }
public async Task <IEnumerable <IdentityResource> > FindIdentityResourcesByScopeAsync(IEnumerable <string> scopeNames) => await Task.FromResult(IdentityResources.Where(e => scopeNames.Contains(e.Name)));