Add simple auth

This commit is contained in:
2025-11-11 14:41:51 -05:00
parent 307c6e103f
commit d188d4fbd1
26 changed files with 121 additions and 17 deletions
+21 -1
View File
@@ -7,6 +7,7 @@ using WebApp.Components;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
@@ -25,6 +26,16 @@ builder.Services.AddScoped<ClipboardService>();
builder.Services.AddScoped<StateContainer>(); // Server- side
builder.Services.AddSingleton<StateContainer>();//Client-side
// Add authentication options
builder.Services.AddAuthentication("Auth")
.AddCookie("Auth", options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
options.SlidingExpiration = true;
options.LoginPath = "/login";
});
builder.Services.AddCascadingAuthenticationState();
var app = builder.Build();
// Configure the HTTP request pipeline.
@@ -36,7 +47,11 @@ if (!app.Environment.IsDevelopment())
app.UseMigrationsEndPoint();
}
app.UseHttpsRedirection();
//app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseStaticFiles();
app.UseAntiforgery();
@@ -44,4 +59,9 @@ app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("default", "{controller}/{action}");
});
app.Run();