Add persisted runtime settings page with cookie login
This commit is contained in:
1 parent
b561924efa
commit
37987a394a
43 files changed
+1346
-61
No files matched your search
@@ -1,16 +1,36 @@
|
||||
using Flypaper.Core;
|
||||
using Flypaper.Http;
|
||||
using Flypaper.Storage;
|
||||
using Flypaper.Web.Auth;
|
||||
using Flypaper.Web.Components;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.WebHost.ConfigureKestrel(options => options.AddServerHeader = false);
|
||||
|
||||
builder.AddFlypaperStorage();
|
||||
builder.Services.AddRazorComponents();
|
||||
builder.Services.AddFlypaperCore(builder.Configuration);
|
||||
builder.Services.AddFlypaperHttp(builder.Configuration);
|
||||
builder.Services.AddFlypaperStorage(builder.Configuration.GetConnectionString("Flypaper") ?? "Data Source=flypaper.db");
|
||||
|
||||
builder.Services.Configure<AdminOptions>(builder.Configuration.GetSection(AdminOptions.SectionName));
|
||||
builder.Services.AddSingleton<AdminAuthenticator>();
|
||||
builder.Services
|
||||
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||
.AddCookie(options =>
|
||||
{
|
||||
options.LoginPath = "/login";
|
||||
options.AccessDeniedPath = "/login";
|
||||
options.Cookie.Name = "flypaper.auth";
|
||||
options.Cookie.HttpOnly = true;
|
||||
options.Cookie.SameSite = SameSiteMode.Strict;
|
||||
options.ExpireTimeSpan = TimeSpan.FromHours(8);
|
||||
options.SlidingExpiration = true;
|
||||
});
|
||||
builder.Services.AddAuthorizationBuilder()
|
||||
.SetFallbackPolicy(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build());
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
@@ -24,9 +44,12 @@ if (!app.Environment.IsDevelopment())
|
||||
}
|
||||
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseAntiforgery();
|
||||
|
||||
app.MapStaticAssets();
|
||||
app.MapStaticAssets().AllowAnonymous();
|
||||
app.MapAuthEndpoints();
|
||||
app.MapRazorComponents<App>();
|
||||
|
||||
await app.RunAsync();
|
||||
Reference in new issue
Block a user