From 3d6c9fd916e18c99b3a5497b8313672680571b5e Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 9 Mar 2022 21:21:15 +0800 Subject: Add user token entity in preparation for refactor of tokens. --- BackEnd/Timeline/Services/Token/UserTokenHandler.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'BackEnd/Timeline/Services/Token/UserTokenHandler.cs') diff --git a/BackEnd/Timeline/Services/Token/UserTokenHandler.cs b/BackEnd/Timeline/Services/Token/UserTokenHandler.cs index c1633f4a..03b07b53 100644 --- a/BackEnd/Timeline/Services/Token/UserTokenHandler.cs +++ b/BackEnd/Timeline/Services/Token/UserTokenHandler.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Security.Claims; +using System.Threading.Tasks; using Timeline.Configs; using Timeline.Entities; @@ -35,7 +36,7 @@ namespace Timeline.Services.Token _tokenSecurityKey = new SymmetricSecurityKey(key); } - public string GenerateToken(UserTokenInfo tokenInfo) + public Task GenerateTokenAsync(UserTokenInfo tokenInfo) { if (tokenInfo == null) throw new ArgumentNullException(nameof(tokenInfo)); @@ -60,11 +61,11 @@ namespace Timeline.Services.Token var token = _tokenHandler.CreateToken(tokenDescriptor); var tokenString = _tokenHandler.WriteToken(token); - return tokenString; + return Task.FromResult(tokenString); } - public UserTokenInfo VerifyToken(string token) + public Task ValidateTokenAsync(string token) { if (token == null) throw new ArgumentNullException(nameof(token)); @@ -100,12 +101,12 @@ namespace Timeline.Services.Token if (exp is null) throw new JwtUserTokenBadFormatException(token, JwtUserTokenBadFormatException.ErrorKind.NoExp); - return new UserTokenInfo + return Task.FromResult(new UserTokenInfo { Id = id, Version = version, ExpireAt = EpochTime.DateTime(exp.Value) - }; + }); } catch (Exception e) when (e is SecurityTokenException || e is ArgumentException) { -- cgit v1.2.3