From 6c9af942f4ef8bdda573f23162b71104561179b4 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 2 Nov 2024 00:51:27 +0300 Subject: [PATCH] refactor: change token to instance token --- Security/Services/AuthService.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Security/Services/AuthService.cs b/Security/Services/AuthService.cs index afc03e8..5c71a9f 100644 --- a/Security/Services/AuthService.cs +++ b/Security/Services/AuthService.cs @@ -82,7 +82,7 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I }; await SetAuthTokenDataToCache(authToken, cancellation); - cookieOptions.SetCookie(context, CookieNames.AccessToken, token, expireIn); + cookieOptions.SetCookie(context, CookieNames.AccessToken, authToken.AccessToken, expireIn); cookieOptions.SetCookie(context, CookieNames.RefreshToken, authToken.RefreshToken, DateTime.UtcNow.Add(Lifetime)); logger.LogInformation( @@ -100,9 +100,9 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I var firstTokenAuth = await cache.GetAsync(GetFirstAuthCacheKey(requestContext.Fingerprint), cancellationToken: cancellation) ?? throw new SecurityException("The session time has expired"); - switch (firstTokenAuth.SecondFactor) + switch (firstTokenAuth.TwoFactorAuthenticator) { - case SecondFactor.Totp: + case TwoFactorAuthenticator.Totp: { if (string.IsNullOrEmpty(firstTokenAuth.Secret)) throw new InvalidOperationException("The user's secrets for data processing were not transferred."); @@ -127,7 +127,7 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I await VerifyUserOrThrowError(requestContext, user, password, cancellation); - if (user.SecondFactor == SecondFactor.None) + if (user.TwoFactorAuthenticator == TwoFactorAuthenticator.None) { await GenerateAuthTokensAsync(cookieOptions, context, requestContext, user.Id.ToString(), cancellation); return true; @@ -137,7 +137,7 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I { UserId = user.Id.ToString(), Secret = user.SecondFactorToken, - SecondFactor = user.SecondFactor + TwoFactorAuthenticator = user.TwoFactorAuthenticator }; await cache.SetAsync(GetFirstAuthCacheKey(requestContext.Fingerprint), firstAuthToken, absoluteExpirationRelativeToNow: LifetimeFirstAuth, cancellationToken: cancellation); @@ -181,7 +181,7 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I authToken.RefreshToken = newRefreshToken; await SetAuthTokenDataToCache(authToken, cancellation); - cookieOptions.SetCookie(context, CookieNames.AccessToken, token, expireIn); + cookieOptions.SetCookie(context, CookieNames.AccessToken, authToken.AccessToken, expireIn); cookieOptions.SetCookie(context, CookieNames.RefreshToken, authToken.RefreshToken, DateTime.UtcNow.Add(Lifetime)); }