2024-07-27 16:08:06 +02:00
|
|
|
using DotBased.ASP.Auth;
|
|
|
|
using DotBased.ASP.Auth.Domains.Auth;
|
|
|
|
using DotBased.ASP.Auth.Domains.Identity;
|
2024-06-16 21:09:49 +02:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-06-17 13:53:48 +02:00
|
|
|
using MudBlazor.Services;
|
2024-06-16 17:20:30 +02:00
|
|
|
using SharpRSS.Blazor.Components;
|
2024-06-16 21:09:49 +02:00
|
|
|
using SharpRSS.Business;
|
|
|
|
using SharpRSS.Data;
|
2024-07-13 16:29:27 +02:00
|
|
|
using SharpRSS.Data.Domains.Configuration;
|
2024-06-16 17:20:30 +02:00
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
2024-07-27 16:08:06 +02:00
|
|
|
builder.AddSRSS();
|
2024-07-06 00:02:02 +02:00
|
|
|
|
2024-07-27 16:08:06 +02:00
|
|
|
builder.Services.AddBasedServerAuth(options =>
|
|
|
|
{
|
|
|
|
options.AllowRegistration = false;
|
|
|
|
options.AuthenticationStateMaxAgeBeforeExpire = TimeSpan.FromDays(7);
|
|
|
|
options.LoginPath = "/auth/login";
|
|
|
|
options.LogoutPath = "/auth/logout";
|
2024-11-02 01:58:30 +01:00
|
|
|
options.LoggedOutPath = "/auth/loggedOut";
|
2024-07-27 16:08:06 +02:00
|
|
|
options.SeedData = service =>
|
|
|
|
{
|
2024-11-02 01:58:30 +01:00
|
|
|
service.CreateUserAsync(new UserModel() { UserName = "Admin", Name = "Administrator", FamilyName = "admin", Email = "admin@example.com", Enabled = true, PasswordHash = "password",
|
2024-11-04 15:46:47 +01:00
|
|
|
Roles = [new RoleModel { Name = "User", Description = "User role" }],
|
|
|
|
Groups = [new GroupModel() { Name = "Administrators", Description = "Administrators group",
|
|
|
|
Roles = [new RoleModel() { Name = "Admin", Description = "Administrator" },
|
|
|
|
new RoleModel() { Name = "Test", Description = "Test role" } ]
|
|
|
|
}]
|
2024-10-14 03:19:39 +02:00
|
|
|
});
|
|
|
|
service.CreateUserAsync(new UserModel() { UserName = "User", Email = "user@example.com", Enabled = true, PasswordHash = "password"});
|
2024-07-27 16:08:06 +02:00
|
|
|
};
|
2024-09-27 02:40:39 +02:00
|
|
|
options.SetDataRepositoryType<MemoryAuthDataRepository>();
|
2024-07-27 16:08:06 +02:00
|
|
|
});
|
|
|
|
|
2024-06-16 17:20:30 +02:00
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddRazorComponents()
|
|
|
|
.AddInteractiveServerComponents();
|
2024-06-17 13:53:48 +02:00
|
|
|
builder.Services.AddMudServices();
|
2024-07-03 20:17:44 +02:00
|
|
|
builder.Services.AddHttpContextAccessor(); // HttpContext accessor
|
2024-06-16 17:20:30 +02:00
|
|
|
|
2024-07-06 00:02:02 +02:00
|
|
|
/*
|
|
|
|
* HSTS config
|
|
|
|
*/
|
2024-07-13 16:29:27 +02:00
|
|
|
var hstsConfig = new HstsConfiguration();
|
|
|
|
var configSection = builder.Configuration.GetSection($"HTTP:{HstsConfiguration.Hsts}");
|
|
|
|
configSection.Bind(hstsConfig);
|
|
|
|
if (hstsConfig.EnableHsts)
|
2024-07-06 00:02:02 +02:00
|
|
|
{
|
2024-07-13 16:29:27 +02:00
|
|
|
builder.Services.AddHsts(options =>
|
|
|
|
{
|
|
|
|
options.Preload = hstsConfig.Preload;
|
|
|
|
options.IncludeSubDomains = hstsConfig.IncludeSubdomains;
|
|
|
|
options.MaxAge = TimeSpan.FromSeconds(hstsConfig.MaxAgeSeconds);
|
|
|
|
});
|
|
|
|
}
|
2024-07-06 00:02:02 +02:00
|
|
|
|
2024-06-16 17:20:30 +02:00
|
|
|
var app = builder.Build();
|
|
|
|
|
2024-07-13 16:29:27 +02:00
|
|
|
//TODO: Move to migrations
|
2024-06-16 21:09:49 +02:00
|
|
|
var contextFactory = app.Services.GetService<IDbContextFactory<SRSSContext>>();
|
|
|
|
if (contextFactory != null)
|
|
|
|
{
|
|
|
|
await using var context = await contextFactory.CreateDbContextAsync();
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
}
|
2024-07-06 00:02:02 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2024-06-16 21:09:49 +02:00
|
|
|
|
2024-06-16 17:20:30 +02:00
|
|
|
if (!app.Environment.IsDevelopment())
|
|
|
|
{
|
2024-07-13 16:29:27 +02:00
|
|
|
app.UseDeveloperExceptionPage();
|
2024-06-16 17:20:30 +02:00
|
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseAntiforgery();
|
2024-07-27 16:08:06 +02:00
|
|
|
app.UseBasedServerAuth();
|
2024-06-16 17:20:30 +02:00
|
|
|
|
|
|
|
app.MapRazorComponents<App>()
|
2024-10-14 15:31:04 +02:00
|
|
|
.AddInteractiveServerRenderMode()
|
|
|
|
.AllowAnonymous();
|
2024-06-16 17:20:30 +02:00
|
|
|
|
|
|
|
app.Run();
|