Esempio n. 1
0
        private async Task CleanupApiResourceAsync(ApiResource entity, CancellationToken cancellationToken = default(CancellationToken))
        {
            //Remove old identity claims
            var apiResourceClaims = await ApiClaims.Where(x => x.ApiResource.Id == entity.Id).ToListAsync();

            ApiClaims.RemoveRange(apiResourceClaims);

            //Remove old proprs
            var apiProps = await ApiProperties.Where(x => x.ApiResource.Id == entity.Id).ToListAsync();

            ApiProperties.RemoveRange(apiProps);

            //Remove old scopes
            var apiScopes = await ApiScopes.Where(x => x.ApiResource.Id == entity.Id).ToListAsync();

            ApiScopes.RemoveRange(apiScopes);

            //Remove old secrets
            var apiSecrets = await ApiSecrets.Where(x => x.ApiResource.Id == entity.Id).ToListAsync();

            ApiSecrets.RemoveRange(apiSecrets);
        }
Esempio n. 2
0
        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);
        }