From 58ef5833b3f77f321c587dd86448c888029016ce Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Thu, 22 Dec 2022 14:44:26 +0100 Subject: feat: Many things - Working Login/Logout - Groundwork for web components - Loading web-components with version tag - Load temporal-polyfill globally --- code/api/Program.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'code/api/Program.cs') diff --git a/code/api/Program.cs b/code/api/Program.cs index e6281f7..5fde778 100644 --- a/code/api/Program.cs +++ b/code/api/Program.cs @@ -12,6 +12,7 @@ global using Microsoft.Extensions.Localization; global using I2R.Storage.Api.Statics; global using Microsoft.AspNetCore.Authorization; global using System.Security.Claims; +global using I2R.Storage.Api.Models; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Localization; @@ -21,11 +22,13 @@ builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationSc .AddCookie(o => { o.Cookie.Name = "storage_session"; o.Cookie.HttpOnly = true; + o.SlidingExpiration = true; + o.Events.OnRedirectToAccessDenied = + o.Events.OnRedirectToLogin = c => { + c.Response.StatusCode = StatusCodes.Status401Unauthorized; + return Task.FromResult(null); + }; }); -builder.Services.AddAuthorization(o => { - o.AddPolicy("least_privileged", b => { b.RequireRole("least_privileged"); }); - o.AddPolicy("admin", b => { b.RequireRole("admin"); }); -}); builder.Services.AddLocalization(); builder.Services.AddRequestLocalization(o => { o.DefaultRequestCulture = new RequestCulture("en"); }); builder.Services.AddScoped(); @@ -44,8 +47,8 @@ var app = builder.Build(); app.UseStaticFiles(); app.UseStatusCodePages(); app.UseRequestLocalization(); -app.UseAuthorization(); app.UseAuthentication(); +app.UseAuthorization(); app.MapRazorPages(); app.MapControllers(); app.Run(); \ No newline at end of file -- cgit v1.3