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()); } } }
public Task <Client> FindClientByIdAsync(string clientId) { // TECH DEBT : CosmosDB currently does not support first FirstOrDefault //var client = _context.Clients(clientId).FirstOrDefault(x => x.ClientId == clientId); var clients = _context.Clients(clientId).ToList(); var model = clients?.FirstOrDefault().ToModel(); _logger.LogDebug($"{clientId} found in database: {model != null}"); return(Task.FromResult(model)); }
public Task <bool> IsOriginAllowedAsync(string origin) { // If we use SelectMany directly, we got a Unsupported Exception inside CosmosDb. var clients = _context.Clients().ToList(); var distinctOrigins = clients.Where(x => x != null) .SelectMany(x => x.AllowedCorsOrigins.Select(y => y.Origin)) .Distinct() .ToList(); var isAllowed = distinctOrigins.Contains(origin, StringComparer.OrdinalIgnoreCase); _logger.LogDebug("Origin {origin} is allowed: {originAllowed}", origin, isAllowed); return(Task.FromResult(isAllowed)); }