diff --git a/Security/Common/Interfaces/ICacheService.cs b/Security/Common/Interfaces/ICacheService.cs index c2a419b..c2cb1e3 100644 --- a/Security/Common/Interfaces/ICacheService.cs +++ b/Security/Common/Interfaces/ICacheService.cs @@ -6,7 +6,11 @@ namespace Mirea.Api.Security.Common.Interfaces; public interface ICacheService { - Task SetAsync(string key, T value, TimeSpan? absoluteExpirationRelativeToNow = null, CancellationToken cancellationToken = default); + Task SetAsync(string key, T value, + TimeSpan? absoluteExpirationRelativeToNow = null, + TimeSpan? slidingExpiration = null, + CancellationToken cancellationToken = default); + Task GetAsync(string key, CancellationToken cancellationToken = default); Task RemoveAsync(string key, CancellationToken cancellationToken = default); } diff --git a/Security/Services/PreAuthService.cs b/Security/Services/PreAuthService.cs index 1a0443e..948b997 100644 --- a/Security/Services/PreAuthService.cs +++ b/Security/Services/PreAuthService.cs @@ -14,7 +14,7 @@ public class PreAuthService(ICacheService cache) { public TimeSpan Lifetime { private get; init; } - private static string GeneratePreAuthToken() => Guid.NewGuid().ToString().Replace("-", "") + + private static string GeneratePreAuthToken() => Guid.NewGuid().ToString().Replace("-", "") + GeneratorKey.GenerateString(16); private static string GetPreAuthCacheKey(string fingerprint) => $"{fingerprint}_pre_auth_token"; @@ -35,8 +35,8 @@ public class PreAuthService(ICacheService cache) await cache.SetAsync( GetPreAuthCacheKey(request.Fingerprint), JsonSerializer.SerializeToUtf8Bytes(preAuthTokenStruct), - Lifetime, - cancellation); + absoluteExpirationRelativeToNow: Lifetime, + cancellationToken: cancellation); return new PreAuthTokenResponse {