diff options
author | crupest <crupest@outlook.com> | 2022-03-09 21:21:15 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-09 21:21:15 +0800 |
commit | 3d6c9fd916e18c99b3a5497b8313672680571b5e (patch) | |
tree | e67ae49937dcdb7f5c874a2ebfdca4fde72a059f /BackEnd/Timeline/Services/Token/UserTokenHandler.cs | |
parent | 3cd0140ff4425b37b6e8dd8e8f16a54b1338c352 (diff) | |
download | timeline-3d6c9fd916e18c99b3a5497b8313672680571b5e.tar.gz timeline-3d6c9fd916e18c99b3a5497b8313672680571b5e.tar.bz2 timeline-3d6c9fd916e18c99b3a5497b8313672680571b5e.zip |
Add user token entity in preparation for refactor of tokens.
Diffstat (limited to 'BackEnd/Timeline/Services/Token/UserTokenHandler.cs')
-rw-r--r-- | BackEnd/Timeline/Services/Token/UserTokenHandler.cs | 11 |
1 files changed, 6 insertions, 5 deletions
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<string> 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<UserTokenInfo> 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)
{
|