aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services/Token/IUserTokenService.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-03-23 21:30:14 +0800
committercrupest <crupest@outlook.com>2022-03-23 21:30:31 +0800
commitda9139b7bab95f6e5ba5f4bb2d99011c2d6db03a (patch)
tree051fd4ca4bc511db7e04b019a33fddaab2d0cc6b /BackEnd/Timeline/Services/Token/IUserTokenService.cs
parent3d6c9fd916e18c99b3a5497b8313672680571b5e (diff)
downloadtimeline-da9139b7bab95f6e5ba5f4bb2d99011c2d6db03a.tar.gz
timeline-da9139b7bab95f6e5ba5f4bb2d99011c2d6db03a.tar.bz2
timeline-da9139b7bab95f6e5ba5f4bb2d99011c2d6db03a.zip
Diffstat (limited to 'BackEnd/Timeline/Services/Token/IUserTokenService.cs')
-rw-r--r--BackEnd/Timeline/Services/Token/IUserTokenService.cs45
1 files changed, 45 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Services/Token/IUserTokenService.cs b/BackEnd/Timeline/Services/Token/IUserTokenService.cs
new file mode 100644
index 00000000..22fb0fb4
--- /dev/null
+++ b/BackEnd/Timeline/Services/Token/IUserTokenService.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Threading.Tasks;
+
+namespace Timeline.Services.Token
+{
+ public interface IUserTokenService
+ {
+ /// <summary>
+ /// Create a token for a user. Please ensure the user id exists!
+ /// </summary>
+ /// <param name="userId">The user id.</param>
+ /// <param name="expireTime">The expire time of the token.</param>
+ /// <returns>Return the generated token.</returns>
+ Task<string> CreateTokenAsync(long userId, DateTime? expireTime);
+
+ /// <summary>
+ /// Verify a token and get the info of the token.
+ /// </summary>
+ /// <param name="token">The token to verify.</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);
+
+ /// <summary>
+ /// Revoke a token to make it no longer valid.
+ /// </summary>
+ /// <param name="token">The token to revoke.</param>
+ /// <returns>Return true if a token is revoked.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="token"/> is null.</exception>
+ /// <remarks>
+ /// This method returns true if a real token is revoked and returns false if the token is not valid.
+ /// If the token is expired, false is return.
+ /// </remarks>
+ Task<bool> RevokeTokenAsync(string token);
+
+ /// <summary>
+ /// Revoke all tokens of a user.
+ /// </summary>
+ /// <param name="userId">User id of tokens.</param>
+ /// <returns>Return the task.</returns>
+ Task RevokeAllTokenByUserIdAsync(long userId);
+ }
+}