🐛 Fix bugs

This commit is contained in:
2025-06-17 00:40:05 +08:00
parent b868d0c153
commit 1a5d0bbfc0
5 changed files with 108 additions and 48 deletions

View File

@ -35,6 +35,7 @@ using Quartz;
using StackExchange.Redis;
using tusdotnet;
using tusdotnet.Stores;
using Microsoft.AspNetCore.DataProtection;
var builder = WebApplication.CreateBuilder(args);
@ -90,12 +91,41 @@ builder.Services.AddSingleton<ICacheService, CacheServiceRedis>();
builder.Services.AddHttpClient();
// Configure Data Protection for persistent session keys
var keysDirectory = Path.Combine(builder.Environment.ContentRootPath, "DataProtection-Keys");
Directory.CreateDirectory(keysDirectory);
builder.Services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(keysDirectory))
.SetApplicationName("DysonNetwork.Sphere");
// Configure cookie policy to be essential for session
builder.Services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = _ => false; // Required for session to work without consent
options.MinimumSameSitePolicy = SameSiteMode.Lax;
});
// Add session with consistent cookie settings
builder.Services.AddSession(options =>
{
options.Cookie.Name = "_dynses";
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
options.IdleTimeout = TimeSpan.FromMinutes(30);
});
// Register OIDC services
builder.Services.AddScoped<OidcService, GoogleOidcService>();
builder.Services.AddScoped<OidcService, AppleOidcService>();
builder.Services.AddScoped<OidcService, GitHubOidcService>();
builder.Services.AddScoped<OidcService, MicrosoftOidcService>();
builder.Services.AddScoped<OidcService, DiscordOidcService>();
builder.Services.AddScoped<GoogleOidcService>();
builder.Services.AddScoped<AppleOidcService>();
builder.Services.AddScoped<GitHubOidcService>();
builder.Services.AddScoped<MicrosoftOidcService>();
builder.Services.AddScoped<DiscordOidcService>();
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower;