public void ConfigureProductionServices(IServiceCollection services) { ConfigureServices(services); ApplicationServices.RegisterProduction(services); }
private void ConfigureServices(IServiceCollection services) { services.Configure <SmtpSenderConfiguration>(Configuration.GetSection("SMTP")); services.Configure <AzureBlobStoreConfiguration>(Configuration.GetSection("AzureBlobStore")); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); ConfigureDatabase(services); services.AddIdentity <IdentityUser, IdentityRole>() .AddRoleManager <RoleManager <IdentityRole> >() .AddDefaultUI() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.Configure <IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequireLowercase = true; options.Password.RequireNonAlphanumeric = true; options.Password.RequireUppercase = true; options.Password.RequiredLength = 6; options.Password.RequiredUniqueChars = 1; // Lockout settings. options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5); options.Lockout.MaxFailedAccessAttempts = 5; options.Lockout.AllowedForNewUsers = true; // User settings. options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+"; options.User.RequireUniqueEmail = false; }); services.ConfigureApplicationCookie(options => { // Cookie settings options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromDays(30); options.LoginPath = "/Identity/Account/Login"; options.AccessDeniedPath = "/Identity/Account/AccessDenied"; options.SlidingExpiration = true; options.Cookie.Name = GlobalConstants.AuthCookieName; }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddMicrosoftAccount(options => { options.ClientId = Configuration["Authentication:Microsoft:ClientId"]; options.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"]; }) .AddJwtBearer("JwtBearer", jwtBearerOptions => { jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration[nameof(TokenConfiguration.TokenSecurityKey)])), ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = true, //validate the expiration and not before values in the token ClockSkew = TimeSpan.FromMinutes(5) //5 minute tolerance for the expiration date }; }); services.AddAuthorization(options => { options.AddPolicy(PolicyNames.RequireTauchbold, policy => policy.RequireRole(Rolenames.Tauchbold)); options.AddPolicy(PolicyNames.RequireAdministrator, policy => policy.RequireRole(Rolenames.Administrator)); options.AddPolicy(PolicyNames.RequireTauchboldeOrAdmin, policy => policy.RequireRole(Rolenames.Administrator, Rolenames.Tauchbold)); }); services.Configure <RequestLocalizationOptions>(options => { options.DefaultRequestCulture = new RequestCulture("de-CH"); options.SupportedCultures = new List <CultureInfo> { new CultureInfo("de-CH") }; options.RequestCultureProviders = new List <IRequestCultureProvider>(); options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider( async context => await Task.FromResult(new ProviderCultureResult("de")) )); }); services.AddMvc(options => { options.Filters.Add(typeof(BuildNumberFilter)); options.Filters.Add(typeof(CurrentUserInformationFilter)); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddJsonOptions( options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ); services.AddApplicationInsightsTelemetry(); services.AddTransient <IEmailSender, IdentityMessageSender>(); ApplicationServices.Register(services, Configuration, hostingEnvironment); }
public void ConfigureDevelopmentServices(IServiceCollection services) { ConfigureServices(services); ApplicationServices.RegisterDevelopment(services); }