public void ConfigureServices(IServiceCollection services) { privateConfig.MapToPocoInService(services); services.AddLogging(); services.AddTransient <IConfiguration>(provider => Configuration); services.AddDbContext <ApplicationContext>(options => options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL"))); services.AddDefaultIdentity <ApplicationUser>() .AddRoles <IdentityRole>() .AddEntityFrameworkStores <ApplicationContext>(); services.Configure <CertificatConfigModel>(Configuration.GetSection("Certificat")); var certificatConfigModel = services.GetOption <CertificatConfigModel>(); var apiOptions = services.GetOption <ApiSettingModel>(); var clientOptions = services.GetOption <ClientSettingModel>(); var identityOptions = services.GetOption <IdetitySettingModel>(); var identities = IdentityConfig.GetIdentities(identityOptions.Identities); var builder = services.AddIdentityServer() .AddInMemoryIdentityResources(identities) .AddInMemoryApiResources(ApiConfig.GetApis(apiOptions.Apies)) .AddInMemoryClients(ClientsConfig.GetClients(clientOptions)) .AddAspNetIdentity <ApplicationUser>() .AddCertificat(Environment.IsDevelopment(), certificatConfigModel); //.AddProfileService<CustomProfileService>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
// TODO: move the localhost address to single place and use that so that we don't need to write it to a million places // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { // add MVC services.AddMvc(); // CORS services.AddCors(); // setup IdentityServer to use the in memory configurations services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryIdentityResources(IdentityResourcesConfig.GetIdentityResources()) .AddInMemoryClients(ClientsConfig.GetClients()) .AddTestUsers(UsersConfig.GetUsers()); }
private void EnsureSeedData(ConfigurationDbContext configurationDbContext) { var isInit = false; if (configurationDbContext.Clients.Any() == false) { ClientsConfig.GetClients().ForEach(item => { configurationDbContext.Clients.Add(item.ToEntity()); }); isInit = true; } if (configurationDbContext.ApiResources.Any() == false) { ResourceConfig.GetApiResource().ForEach(item => { configurationDbContext.ApiResources.Add(item.ToEntity()); }); isInit = true; } if (configurationDbContext.IdentityResources.Any() == false) { ResourceConfig.GetIdentityResource().ForEach(item => { configurationDbContext.IdentityResources.Add(item.ToEntity()); }); isInit = true; } if (isInit) { configurationDbContext.SaveChanges(); } }