Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/apps/api
diff options
context:
space:
mode:
authorLeitwolf2026-10-16 07:18:36 +0300
committerGitHub2026-10-16 07:18:36 +0300
commit8f58831373b72dc5b60bad649a961acd0bb94aa4 (patch)
treec76322adffc6f0a794cfe7391de8d32ece8b57ae /apps/api
parente140d6587a1a74efc205b29582dfbe9942e0f3dc (diff)
parent235874b4e2bbf75acf2fd09ec37c3dfd480c01b7 (diff)
downloadprogmaweb-8f58831373b72dc5b60bad649a961acd0bb94aa4.tar.gz
Merge pull request #39 from Progmasoft/feature/thirty-day-sessions
Keep account sessions for 30 days
Diffstat (limited to 'apps/api')
-rw-r--r--apps/api/Accounts/SessionService.cs11
-rw-r--r--apps/api/appsettings.json2
2 files changed, 9 insertions, 4 deletions
diff --git a/apps/api/Accounts/SessionService.cs b/apps/api/Accounts/SessionService.cs
index d6d04b0..24a81d0 100644
--- a/apps/api/Accounts/SessionService.cs
+++ b/apps/api/Accounts/SessionService.cs
@@ -11,8 +11,13 @@ internal sealed class AccountSessionOptions
{
/// <summary>Name of the configuration section.</summary>
public const string SectionName = "AccountSessions";
- /// <summary>Hours a session stays valid. Values outside 1 to 168 are clamped to that range.</summary>
- public int LifetimeHours { get; init; } = 12;
+ /// <summary>The longest a session may stay valid: 30 days.</summary>
+ public const int MaximumLifetimeHours = 30 * 24;
+ /// <summary>
+ /// Hours a session stays valid, 30 days unless configured. Values outside 1 to
+ /// <see cref="MaximumLifetimeHours"/> are clamped to that range.
+ /// </summary>
+ public int LifetimeHours { get; init; } = MaximumLifetimeHours;
/// <summary>Name of the session cookie. The <c>__Host-</c> prefix binds it to this host over HTTPS.</summary>
public string CookieName { get; init; } = "__Host-ProgmasoftSession";
}
@@ -46,7 +51,7 @@ internal sealed class SessionService(
.TrimEnd('=');
byte[] digest = SHA256.HashData(System.Text.Encoding.ASCII.GetBytes(token));
DateTimeOffset createdAt = timeProvider.GetUtcNow();
- DateTimeOffset expiresAt = createdAt.AddHours(Math.Clamp(settings.LifetimeHours, 1, 168));
+ DateTimeOffset expiresAt = createdAt.AddHours(Math.Clamp(settings.LifetimeHours, 1, AccountSessionOptions.MaximumLifetimeHours));
await store.StoreSessionAsync(new SessionRecord(digest, account.Id, createdAt, expiresAt), cancellationToken);
return new AuthenticatedAccount(account, token, expiresAt);
diff --git a/apps/api/appsettings.json b/apps/api/appsettings.json
index 5644334..e6b208a 100644
--- a/apps/api/appsettings.json
+++ b/apps/api/appsettings.json
@@ -7,7 +7,7 @@
},
"AllowedHosts": "localhost;127.0.0.1;progmasoft.com;account.progmasoft.com;www.progmasoft.com",
"AccountSessions": {
- "LifetimeHours": 12,
+ "LifetimeHours": 720,
"CookieName": "__Host-ProgmasoftSession"
}
}