refactor: improve logging

This commit is contained in:
Polianin Nikita 2024-12-28 08:29:06 +03:00
parent 206720cd63
commit c3c9844e2f

View File

@ -226,26 +226,18 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I
cookieOptions.DropCookie(context, CookieNames.AccessToken); cookieOptions.DropCookie(context, CookieNames.AccessToken);
cookieOptions.DropCookie(context, CookieNames.RefreshToken); cookieOptions.DropCookie(context, CookieNames.RefreshToken);
const string error = "Token validation failed for user ID {UserId}. Fingerprint: {Fingerprint}. "; logger.LogWarning("Token validation failed for user ID {UserId}. Fingerprint: {Fingerprint}. " +
if (authToken.RefreshToken != requestContext.RefreshToken) "RefreshToken: {ExpectedRefreshToken} -> {RefreshToken}, " +
logger.LogWarning( "UserAgent: {ExpectedUserAgent} -> {ProvidedUserAgent}, " +
error + "Ip: {ExpectedUserIp} -> {ProvidedIp}",
"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); authToken.UserAgent,
else requestContext.UserAgent,
logger.LogWarning( authToken.Ip,
error + requestContext.Ip);
"User-Agent {ExpectedUserAgent} and IP {ExpectedUserIp} in cache do not match the provided " +
"User-Agent {ProvidedUserAgent} and IP {ProvidedIp}",
authToken.UserId,
authToken.Fingerprint,
authToken.UserAgent,
authToken.Ip,
requestContext.UserAgent,
requestContext.Ip);
throw new SecurityException(defaultMessageError); throw new SecurityException(defaultMessageError);
} }