From 1003342da3fc5b8aeedf0668ff3c82e0c4cb47ed Mon Sep 17 00:00:00 2001 From: Young Date: Sun, 6 Oct 2024 16:17:13 +0800 Subject: [PATCH] update codes --- .../Security/DefaultTokenHandler.cs | 15 +++++++++++++++ src/Infrastructure/Security/TokenInfo.cs | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/Infrastructure/Security/DefaultTokenHandler.cs create mode 100644 src/Infrastructure/Security/TokenInfo.cs diff --git a/src/Infrastructure/Security/DefaultTokenHandler.cs b/src/Infrastructure/Security/DefaultTokenHandler.cs new file mode 100644 index 0000000..15df00c --- /dev/null +++ b/src/Infrastructure/Security/DefaultTokenHandler.cs @@ -0,0 +1,15 @@ +using System.IdentityModel.Tokens.Jwt; +using Microsoft.IdentityModel.Tokens; + +namespace Infrastructure.Security; + +public class DefaultTokenHandler(IEncryptionService encryptionService, JwtSecurityTokenHandler jwtSecurityTokenHandler) + : TokenHandler +{ + public override Task ValidateTokenAsync(string token, + TokenValidationParameters validationParameters) + { + var decodeToken = encryptionService.Decrypt(token); + return jwtSecurityTokenHandler.ValidateTokenAsync(decodeToken, validationParameters); + } +} \ No newline at end of file diff --git a/src/Infrastructure/Security/TokenInfo.cs b/src/Infrastructure/Security/TokenInfo.cs new file mode 100644 index 0000000..9db0294 --- /dev/null +++ b/src/Infrastructure/Security/TokenInfo.cs @@ -0,0 +1,10 @@ +namespace Infrastructure.Security; + +public class TokenInfo(string token, double expiredIn, string tokenType) +{ + public string? Token { get; } = token; + + public double? ExpiredIn { get; } = expiredIn; + + public string? TokenType { get; } = tokenType; +} \ No newline at end of file