refactor: move arguments to a new line

This commit is contained in:
Polianin Nikita 2024-12-25 05:54:27 +03:00
parent 5fa545e981
commit 269d976ad4

View File

@ -12,7 +12,8 @@ using System.Threading.Tasks;
namespace Mirea.Api.Security.Services; namespace Mirea.Api.Security.Services;
public class AuthService(ICacheService cache, IAccessToken accessTokenService, IRevokedToken revokedToken, ILogger<AuthService> logger, PasswordHashService passwordService) public class AuthService(ICacheService cache, IAccessToken accessTokenService, IRevokedToken revokedToken, ILogger<AuthService> logger,
PasswordHashService passwordService)
{ {
public TimeSpan Lifetime { private get; init; } public TimeSpan Lifetime { private get; init; }
public TimeSpan LifetimeFirstAuth { private get; init; } public TimeSpan LifetimeFirstAuth { private get; init; }
@ -93,7 +94,8 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I
throw new SecurityException("Authentication failed. Please check your credentials."); throw new SecurityException("Authentication failed. Please check your credentials.");
} }
private async Task GenerateAuthTokensAsync(CookieOptionsParameters cookieOptions, HttpContext context, RequestContextInfo requestContext, string userId, CancellationToken cancellation = default) private async Task GenerateAuthTokensAsync(CookieOptionsParameters cookieOptions, HttpContext context,
RequestContextInfo requestContext, string userId, CancellationToken cancellation = default)
{ {
var refreshToken = GenerateRefreshToken(); var refreshToken = GenerateRefreshToken();
var (token, expireIn) = GenerateAccessToken(userId); var (token, expireIn) = GenerateAccessToken(userId);
@ -116,7 +118,8 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I
authToken.Fingerprint); authToken.Fingerprint);
} }
public async Task<TwoFactorAuthenticator> LoginOAuthAsync(CookieOptionsParameters cookieOptions, HttpContext context, User user, CancellationToken cancellation = default) public async Task<TwoFactorAuthenticator> LoginOAuthAsync(CookieOptionsParameters cookieOptions, HttpContext context, User user,
CancellationToken cancellation = default)
{ {
var requestContext = new RequestContextInfo(context, cookieOptions); var requestContext = new RequestContextInfo(context, cookieOptions);
@ -131,7 +134,8 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I
return user.TwoFactorAuthenticator; return user.TwoFactorAuthenticator;
} }
public async Task<bool> LoginAsync(CookieOptionsParameters cookieOptions, HttpContext context, TwoFactorAuthenticator authenticator, string code, CancellationToken cancellation = default) public async Task<bool> LoginAsync(CookieOptionsParameters cookieOptions, HttpContext context, TwoFactorAuthenticator authenticator, string code,
CancellationToken cancellation = default)
{ {
var requestContext = new RequestContextInfo(context, cookieOptions); var requestContext = new RequestContextInfo(context, cookieOptions);
@ -159,7 +163,7 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I
{ {
await RecordFailedLoginAttempt(requestContext.Fingerprint, firstTokenAuth.UserId, cancellation); await RecordFailedLoginAttempt(requestContext.Fingerprint, firstTokenAuth.UserId, cancellation);
throw new SecurityException("Invalid verification code. Please try again."); throw new SecurityException("Invalid verification code. Please try again.");
} }
await ResetFailedLoginAttempts(requestContext.Fingerprint, cancellation); await ResetFailedLoginAttempts(requestContext.Fingerprint, cancellation);
} }
@ -172,7 +176,8 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I
return true; return true;
} }
public async Task<TwoFactorAuthenticator> LoginAsync(CookieOptionsParameters cookieOptions, User user, HttpContext context, string password, string username, CancellationToken cancellation = default) public async Task<TwoFactorAuthenticator> LoginAsync(CookieOptionsParameters cookieOptions, User user, HttpContext context, string password,
string username, CancellationToken cancellation = default)
{ {
var requestContext = new RequestContextInfo(context, cookieOptions); var requestContext = new RequestContextInfo(context, cookieOptions);
username = username.Trim(); username = username.Trim();
@ -210,8 +215,8 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I
logger.LogWarning( logger.LogWarning(
error + error +
"Cached refresh token {ExpectedRefreshToken} does not match the provided refresh token {RefreshToken}", "Cached refresh token {ExpectedRefreshToken} does not match the provided refresh token {RefreshToken}",
authToken.UserId, authToken.UserId,
authToken.Fingerprint, authToken.Fingerprint,
authToken.RefreshToken, authToken.RefreshToken,
requestContext.RefreshToken); requestContext.RefreshToken);
else else