mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-11 17:03:33 -04:00
Refactor (#1347)
This commit is contained in:
@@ -135,7 +135,7 @@ const AppContent: React.FC<{
|
||||
}}
|
||||
>
|
||||
{message && (
|
||||
<div className="p-4 pt-0">
|
||||
<div className="px-4 pt-0">
|
||||
<p className="text-red-500 dark:text-red-400 text-sm">{message}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -56,6 +56,17 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
|
||||
/// </summary>
|
||||
private const int MobileLoginTimeoutMinutes = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Access token validity in minutes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is the time period for which the access token is valid.
|
||||
/// It is used to authenticate the user for a limited time
|
||||
/// and is short-lived by design. With the separate refresh token, the user can request a new access token
|
||||
/// when this access token expires.
|
||||
/// </remarks>
|
||||
private const int AccessTokenValiditySeconds = 600;
|
||||
|
||||
/// <summary>
|
||||
/// Semaphore to prevent concurrent access to the database when generating new tokens for a user.
|
||||
/// </summary>
|
||||
@@ -969,7 +980,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
|
||||
issuer: configuration["Jwt:Issuer"] ?? string.Empty,
|
||||
audience: configuration["Jwt:Issuer"] ?? string.Empty,
|
||||
claims: claims,
|
||||
expires: timeProvider.UtcNow.AddMinutes(10),
|
||||
expires: timeProvider.UtcNow.AddSeconds(AccessTokenValiditySeconds),
|
||||
signingCredentials: credentials);
|
||||
|
||||
return new JwtSecurityTokenHandler().WriteToken(token);
|
||||
|
||||
@@ -91,9 +91,12 @@ public static class AuthHelper
|
||||
{
|
||||
var userAgent = request.Headers.UserAgent.ToString();
|
||||
var acceptLanguage = request.Headers.AcceptLanguage.ToString();
|
||||
var client = request.Headers["X-AliasVault-Client"].ToString();
|
||||
|
||||
var rawIdentifier = $"{client}|{userAgent}|{acceptLanguage}";
|
||||
// Client header is usually formatted like "[client name]-[version]" e.g. "chrome-0.25.0", take only "chrome"
|
||||
var clientHeader = request.Headers["X-AliasVault-Client"].ToString();
|
||||
var clientName = clientHeader?.Split('-')[0] ?? "unknown";
|
||||
|
||||
var rawIdentifier = $"{clientName}|{userAgent}|{acceptLanguage}";
|
||||
return rawIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user