public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddDbContext <DataContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); }) .AddIdentity <IdentityUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequiredLength = 5; }) .AddEntityFrameworkStores <DataContext>(); services.AddIdentityServer(options => { options.UserInteraction.LoginUrl = "/Home/Login"; options.UserInteraction.LogoutUrl = "/Home/Logout"; }) .AddAspNetIdentity <IdentityUser>() .AddInMemoryApiResources(IdentityServerConfiguration.GetApiResources()) .AddInMemoryApiScopes(IdentityServerConfiguration.GetScopes()) .AddInMemoryClients(IdentityServerConfiguration.Clients()) .AddInMemoryIdentityResources(IdentityServerConfiguration.GetIdentityResources()) .AddDeveloperSigningCredential(); }
public void ConfigureServices(IServiceCollection services) { var connectionString = _configuration.GetConnectionString("DefaultConnection"); services.AddDbContext <AppDbContext>(config => { config.UseSqlServer(connectionString); }); services.AddTransient <IUserClaimsPrincipalFactory <ApplicationUser>, CustomUserClaimsPrincipalFactory>(); services.AddSingleton(_configuration.GetSection("EmailConfiguration").Get <EmailConfiguration>()); services.AddScoped <IEmailSenderService, EmailSenderService>(); services.Configure <FormOptions>(config => { config.ValueLengthLimit = int.MaxValue; config.MultipartBodyLengthLimit = int.MaxValue; config.MemoryBufferThreshold = int.MaxValue; }); services.AddIdentity <ApplicationUser, ApplicationRole>(config => { config.Password.RequiredLength = 6; config.Password.RequireDigit = false; config.Password.RequireNonAlphanumeric = false; config.Password.RequireUppercase = false; config.Password.RequireLowercase = false; config.User.RequireUniqueEmail = true; }) .AddEntityFrameworkStores <AppDbContext>() .AddDefaultTokenProviders(); services.ConfigureApplicationCookie(config => { config.Cookie.Name = "IdentitySever.Cookie"; config.LoginPath = "/Auth/Login"; config.LogoutPath = "/Auth/Logout"; }); var assembly = typeof(Startup).Assembly.GetName().Name; var filePath = Path.Combine(_env.ContentRootPath, _configuration["CertPath"].ToString()); var certificate = new X509Certificate2(filePath, _configuration["CertPassword"].ToString()); services.AddIdentityServer() .AddAspNetIdentity <ApplicationUser>() .AddInMemoryIdentityResources(IdentityServerConfiguration.GetIdentityResources()) .AddInMemoryApiResources(IdentityServerConfiguration.GetApis(_configuration)) .AddInMemoryApiScopes(IdentityServerConfiguration.GetScopes(_configuration)) .AddInMemoryClients(IdentityServerConfiguration.GetClients(_configuration)) //.AddConfigurationStore(options => //{ // options.ConfigureDbContext = b => b.UseSqlServer(connectionString, // sql => sql.MigrationsAssembly(assembly)); //}) //.AddOperationalStore(options => //{ // options.ConfigureDbContext = b => b.UseSqlServer(connectionString, // sql => sql.MigrationsAssembly(assembly)); //}) .AddProfileService <ProfileService>() .AddSigningCredential(certificate); services.AddCors(options => { options.AddPolicy("AllowOrigin", builder => { builder.WithOrigins(_configuration["AngularClientEntraAppURL"].ToString()) .AllowAnyHeader() .AllowAnyMethod(); }); }); services.AddControllersWithViews(); }