Created
April 28, 2020 08:13
-
-
Save xtrmstep/0bb340400d730abb06f246c34961c48d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JwtTokenValidator : ISecurityTokenValidator | |
{ | |
public bool CanReadToken(string securityToken) => true; | |
public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParameters validationParameters, out SecurityToken validatedToken) | |
{ | |
var handler = new JwtSecurityTokenHandler(); | |
var tokenValidationParameters = new TokenValidationParameters | |
{ | |
ValidateIssuer = true, | |
ValidateAudience = true, | |
ValidateLifetime = true, | |
ValidateIssuerSigningKey = true, | |
ValidIssuer = "your string", | |
ValidAudience = "your string", | |
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("your secrete code")) | |
}; | |
var claimsPrincipal = handler.ValidateToken(token, tokenValidationParameters, out validatedToken); | |
return claimsPrincipal; | |
} | |
public bool CanValidateToken { get; } = true; | |
public int MaximumTokenSizeInBytes { get; set; } = int.MaxValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment