/// <summary> /// Update identity resource /// </summary> /// <returns>This method return new identity resource id</returns> public async Task <IdentityResourceDTO> UpdateIdentityResourceAsync(IdentityResourceDTO dto) { var entity = dto.ToEntity(); var canInsert = await CanInsertIdentityResourceAsync(entity); if (!canInsert) { throw new Exception(Constants.Errors.CantInsert); } IdentityResources.Attach(entity); await CleanupIdentityResourceAsync(entity); IdentityResources.Update(entity); await Context.SaveChangesAsync(); return(entity.ToDTO()); }
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 AddIdentityResource(IdentityResource entity) { await IdentityResources.InsertOneAsync(entity); }
/// <summary> /// this retrieves the displayname of the identity resource at id "#" /// </summary> /// <param name="id"></param> /// <returns>"#".displayname</returns> public string FetchName(int id) { IdentityResources Name = _context.IdentityResources.Find(id); return(Name.DisplayName); }
public async Task <IEnumerable <IdentityResource> > FindIdentityResourcesByScopeAsync(IEnumerable <string> scopeNames) => await Task.FromResult(IdentityResources.Where(e => scopeNames.Contains(e.Name)));