diff --git a/Security/Common/Dto/Responses/AuthTokenResponse.cs b/Security/Common/Dto/Responses/AuthTokenResponse.cs index 0c8a3d4..16aed38 100644 --- a/Security/Common/Dto/Responses/AuthTokenResponse.cs +++ b/Security/Common/Dto/Responses/AuthTokenResponse.cs @@ -5,6 +5,7 @@ namespace Mirea.Api.Security.Common.Dto.Responses; public class AuthTokenResponse { public required string AccessToken { get; set; } + public DateTime AccessExpiresIn { get; set; } public required string RefreshToken { get; set; } - public DateTime ExpiresIn { get; set; } + public DateTime RefreshExpiresIn { get; set; } } \ No newline at end of file diff --git a/Security/Services/AuthService.cs b/Security/Services/AuthService.cs index 5426532..2aa01d7 100644 --- a/Security/Services/AuthService.cs +++ b/Security/Services/AuthService.cs @@ -34,7 +34,7 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I public async Task GenerateAuthTokensAsync(TokenRequest request, string userId, CancellationToken cancellation = default) { var refreshToken = GenerateRefreshToken(); - var accessToken = GenerateAccessToken(userId); + var (token, expireIn) = GenerateAccessToken(userId); var authTokenStruct = new AuthToken { @@ -43,16 +43,17 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I RefreshToken = refreshToken, UserAgent = request.UserAgent, UserId = userId, - AccessToken = accessToken.Token + AccessToken = token }; await SetAuthTokenDataToCache(request.Fingerprint, authTokenStruct, cancellation); return new AuthTokenResponse { - AccessToken = accessToken.Token, - ExpiresIn = accessToken.ExpireIn, - RefreshToken = authTokenStruct.RefreshToken + AccessToken = token, + AccessExpiresIn = expireIn, + RefreshToken = authTokenStruct.RefreshToken, + RefreshExpiresIn = DateTime.UtcNow.Add(Lifetime), }; } @@ -77,17 +78,18 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I throw new SecurityException(request.Fingerprint); } - var accessToken = GenerateAccessToken(authToken.UserId); + var (token, expireIn) = GenerateAccessToken(authToken.UserId); await RevokeAccessToken(authToken.AccessToken); - authToken.AccessToken = accessToken.Token; + authToken.AccessToken = token; await SetAuthTokenDataToCache(request.Fingerprint, authToken, cancellation); return new AuthTokenResponse { - AccessToken = accessToken.Token, - ExpiresIn = accessToken.ExpireIn, - RefreshToken = GenerateRefreshToken() + AccessToken = token, + AccessExpiresIn = expireIn, + RefreshToken = GenerateRefreshToken(), + RefreshExpiresIn = DateTime.UtcNow.Add(Lifetime) }; }