private static void EnsureSeedData(ConfigurationDbContext context)
        {
            if (!context.Clients.Any())
            {
                foreach (var client in IdentityServerConfiguration.GetClientScope().ToList())
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
            }


            if (!context.IdentityResources.Any())
            {
                foreach (var resource in IdentityServerConfiguration.GetIdentityResources().ToList())
                {
                    context.IdentityResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in IdentityServerConfiguration.GetApiResources().ToList())
                {
                    context.ApiResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }
        }
示例#2
0
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc();
     services.AddIdentityServer()
     .AddDeveloperSigningCredential()
     .AddInMemoryClients(IdentityServerConfiguration.GetClientScope())
     .AddInMemoryApiResources(IdentityServerConfiguration.GetApiResources())
     .AddInMemoryIdentityResources(IdentityServerConfiguration.GetIdentityResources())
     .AddTestUsers(IdentityServerConfiguration.GetUsers().ToList());
 }