Add simple auth
This commit is contained in:
+21
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user