aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-16 22:11:29 +0800
committercrupest <crupest@outlook.com>2022-04-16 22:11:29 +0800
commitb4f783c20aa47cb601dc81e0dad07aa92517c229 (patch)
tree5555a97984df994910c26b3d5f2fc897cfbdfd28 /BackEnd/Timeline/Services
parent750785728f57af11dfc682ee9ee870e4dc191981 (diff)
downloadtimeline-b4f783c20aa47cb601dc81e0dad07aa92517c229.tar.gz
timeline-b4f783c20aa47cb601dc81e0dad07aa92517c229.tar.bz2
timeline-b4f783c20aa47cb601dc81e0dad07aa92517c229.zip
...
Diffstat (limited to 'BackEnd/Timeline/Services')
-rw-r--r--BackEnd/Timeline/Services/Token/IUserTokenService.cs5
-rw-r--r--BackEnd/Timeline/Services/Token/SecureRandomUserTokenService.cs6
2 files changed, 6 insertions, 5 deletions
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.
/// </summary>
/// <param name="token">The token to verify.</param>
+ /// <param name="checkLifetime">Whether to check lifetime of token.</param>
/// <returns>The info of the token.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="token"/> is null.</exception>
/// <exception cref="UserTokenException">Thrown when the token is not valid for reasons other than expired.</exception>
- /// <exception cref="UserTokenExpiredException">Thrown when the token is expired.</exception>
- Task<UserTokenInfo> ValidateTokenAsync(string token);
+ /// <exception cref="UserTokenExpiredException">Thrown when <paramref name="checkLifetime"/> is true and the token is expired.</exception>
+ Task<UserTokenInfo> ValidateTokenAsync(string token, bool checkLifetime = true);
/// <summary>
/// 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
}
/// <inheritdoc/>
- public async Task<UserTokenInfo> ValidateTokenAsync(string token)
+ public async Task<UserTokenInfo> 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);
}