From b4f783c20aa47cb601dc81e0dad07aa92517c229 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 16 Apr 2022 22:11:29 +0800 Subject: ... --- BackEnd/Timeline/Services/Token/IUserTokenService.cs | 5 +++-- BackEnd/Timeline/Services/Token/SecureRandomUserTokenService.cs | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'BackEnd/Timeline/Services/Token') diff --git a/BackEnd/Timeline/Services/Token/IUserTokenService.cs b/BackEnd/Timeline/Services/Token/IUserTokenService.cs index 22fb0fb4..a9689f57 100644 --- a/BackEnd/Timeline/Services/Token/IUserTokenService.cs +++ b/BackEnd/Timeline/Services/Token/IUserTokenService.cs @@ -17,11 +17,12 @@ namespace Timeline.Services.Token /// Verify a token and get the info of the token. /// /// The token to verify. + /// Whether to check lifetime of token. /// The info of the token. /// Thrown when is null. /// Thrown when the token is not valid for reasons other than expired. - /// Thrown when the token is expired. - Task ValidateTokenAsync(string token); + /// Thrown when is true and the token is expired. + Task ValidateTokenAsync(string token, bool checkLifetime = true); /// /// Revoke a token to make it no longer valid. diff --git a/BackEnd/Timeline/Services/Token/SecureRandomUserTokenService.cs b/BackEnd/Timeline/Services/Token/SecureRandomUserTokenService.cs index 4d79295a..ceef4798 100644 --- a/BackEnd/Timeline/Services/Token/SecureRandomUserTokenService.cs +++ b/BackEnd/Timeline/Services/Token/SecureRandomUserTokenService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; @@ -81,7 +81,7 @@ namespace Timeline.Services.Token } /// - public async Task ValidateTokenAsync(string token) + public async Task ValidateTokenAsync(string token, bool checkLifetime = true) { var entity = await _databaseContext.UserTokens.Where(t => t.Token == token && !t.Deleted).SingleOrDefaultAsync(); @@ -92,7 +92,7 @@ namespace Timeline.Services.Token var currentTime = _clock.GetCurrentTime(); - if (entity.ExpireAt.HasValue && entity.ExpireAt.Value <= currentTime) + if (checkLifetime && entity.ExpireAt.HasValue && entity.ExpireAt.Value <= currentTime) { throw new UserTokenExpiredException(token, entity.ExpireAt.Value, currentTime); } -- cgit v1.2.3