aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/Program.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-12-22 14:44:26 +0100
committerivarlovlie <git@ivarlovlie.no>2022-12-22 14:44:26 +0100
commit58ef5833b3f77f321c587dd86448c888029016ce (patch)
treefe5e6f47781573cc1fb5938f9b8cd8b51022946a /code/api/Program.cs
parent82ade3c31fb17b662feec59e9e654ceb66edbb7a (diff)
downloadstorage-58ef5833b3f77f321c587dd86448c888029016ce.tar.xz
storage-58ef5833b3f77f321c587dd86448c888029016ce.zip
feat: Many things
- Working Login/Logout - Groundwork for web components - Loading web-components with version tag - Load temporal-polyfill globally
Diffstat (limited to 'code/api/Program.cs')
-rw-r--r--code/api/Program.cs13
1 files changed, 8 insertions, 5 deletions
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<object>(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<UserService>();
@@ -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