Persist auth keys across deployments

This commit is contained in:
2026-07-09 13:40:18 +09:00
parent 57ba5fd108
commit 03e822f8d5
2 changed files with 11 additions and 1 deletions
+2 -1
View File
@@ -95,7 +95,8 @@ public class LoginModel(AuthService authService) : PageModel
var properties = new AuthenticationProperties
{
IsPersistent = false,
IsPersistent = true,
ExpiresUtc = DateTimeOffset.UtcNow.AddHours(12),
RedirectUri = RedirectUrl
};
+9
View File
@@ -3,6 +3,7 @@ using System.Text;
using System.Text.Encodings.Web;
using System.Text.Unicode;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Authentication.OAuth;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.RateLimiting;
@@ -54,6 +55,14 @@ builder.Host.UseSerilog((context, config) =>
builder.Services.AddAuthorization();
builder.Services.AddProblemDetails();
builder.Services.AddHealthChecks();
var dataProtectionKeyPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".taxbaik",
"data-protection-keys");
Directory.CreateDirectory(dataProtectionKeyPath);
builder.Services.AddDataProtection()
.SetApplicationName("TaxBaik.Web")
.PersistKeysToFileSystem(new DirectoryInfo(dataProtectionKeyPath));
builder.Services.AddRateLimiter(options =>
{
options.RejectionStatusCode = StatusCodes.Status429TooManyRequests;