diff options
author | 杨宇千 <crupest@outlook.com> | 2019-04-11 21:13:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-11 21:13:15 +0800 |
commit | 19cae15eba2bcede41b818e1b8ab7fd5ac92eb05 (patch) | |
tree | 34118752ae3015a26c0f6f3a02b3043806ce895a /Timeline/Services/JwtService.cs | |
parent | 5b5ca3acb1b9decb5ad13798dc79ba2d58f2ce95 (diff) | |
parent | 63573d7c988e0bc1b7e82eeea53ecc3678b0a2f5 (diff) | |
download | timeline-19cae15eba2bcede41b818e1b8ab7fd5ac92eb05.tar.gz timeline-19cae15eba2bcede41b818e1b8ab7fd5ac92eb05.tar.bz2 timeline-19cae15eba2bcede41b818e1b8ab7fd5ac92eb05.zip |
Merge pull request #19 from crupest/18-createtoken
Change create token api.
Diffstat (limited to 'Timeline/Services/JwtService.cs')
-rw-r--r-- | Timeline/Services/JwtService.cs | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/Timeline/Services/JwtService.cs b/Timeline/Services/JwtService.cs index a01f3f2b..abdde908 100644 --- a/Timeline/Services/JwtService.cs +++ b/Timeline/Services/JwtService.cs @@ -11,12 +11,6 @@ using Timeline.Entities; namespace Timeline.Services { - public class TokenValidationResult - { - public bool IsValid { get; set; } - public UserInfo UserInfo { get; set; } - } - public interface IJwtService { /// <summary> @@ -30,17 +24,17 @@ namespace Timeline.Services /// <summary> /// Validate a JWT token. /// Return null is <paramref name="token"/> is null. - /// If token is invalid, return a <see cref="TokenValidationResult"/> with - /// <see cref="TokenValidationResult.IsValid"/> set to false and - /// <see cref="TokenValidationResult.UserInfo"/> set to null. - /// If token is valid, return a <see cref="TokenValidationResult"/> with - /// <see cref="TokenValidationResult.IsValid"/> set to true and - /// <see cref="TokenValidationResult.UserInfo"/> filled with the user info + /// If token is invalid, return a <see cref="TokenValidationResponse"/> with + /// <see cref="TokenValidationResponse.IsValid"/> set to false and + /// <see cref="TokenValidationResponse.UserInfo"/> set to null. + /// If token is valid, return a <see cref="TokenValidationResponse"/> with + /// <see cref="TokenValidationResponse.IsValid"/> set to true and + /// <see cref="TokenValidationResponse.UserInfo"/> filled with the user info /// in the token. /// </summary> /// <param name="token">The token string to validate.</param> /// <returns>Null if <paramref name="token"/> is null. Or the result.</returns> - TokenValidationResult ValidateJwtToken(string token); + TokenValidationResponse ValidateJwtToken(string token); } @@ -86,7 +80,7 @@ namespace Timeline.Services } - public TokenValidationResult ValidateJwtToken(string token) + public TokenValidationResponse ValidateJwtToken(string token) { if (token == null) return null; @@ -114,7 +108,7 @@ namespace Timeline.Services Roles = identity.FindAll(identity.RoleClaimType).Select(claim => claim.Value).ToArray() }; - return new TokenValidationResult + return new TokenValidationResponse { IsValid = true, UserInfo = userInfo @@ -123,7 +117,7 @@ namespace Timeline.Services catch (Exception e) { _logger.LogInformation(e, "Token validation failed! Token is {} .", token); - return new TokenValidationResult { IsValid = false }; + return new TokenValidationResponse { IsValid = false }; } } } |