public Task <IEnumerable <ApiResource> > FindApiResourcesByScopeAsync(IEnumerable <string> scopeNames)
        {
            var names = scopeNames.ToArray();

            var apis = from api in _context.ApiResources().ToList()
                       where api.Scopes.Any(x => names.Contains(x.Name))
                       select api;

            var results = apis.ToArray();
            var models  = results.Select(x => x.ToModel()).ToArray();

            _logger.LogDebug("Found {scopes} API scopes in database",
                             models.SelectMany(x => x.Scopes).Select(x => x.Name));

            return(Task.FromResult(models.AsEnumerable()));
        }
示例#2
0
        private static void EnsureSeedData(IConfigurationDbContext context)
        {
            foreach (var client in Clients.Get().ToList())
            {
                var dbRecords = context.Clients(client.ClientId).ToList();
                if (dbRecords.Count == 0)
                {
                    context.AddClient(client.ToEntity());
                }
            }

            foreach (var resource in Resources.GetIdentityResources().ToList())
            {
                var dbRecords = context.IdentityResources(resource.Name).ToList();
                if (dbRecords.Count == 0)
                {
                    context.AddIdentityResource(resource.ToEntity());
                }
            }

            foreach (var resource in Resources.GetApiResources().ToList())
            {
                var dbRecords = context.ApiResources(resource.Name).ToList();
                if (dbRecords.Count == 0)
                {
                    context.AddApiResource(resource.ToEntity());
                }
            }
        }