This file contains 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 TokenReadResult ReadToken(string tokenString) | |
{ | |
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtKey"])); | |
var handler = new JwtSecurityTokenHandler(); | |
var validations = new TokenValidationParameters | |
{ | |
ValidateIssuerSigningKey = true, | |
IssuerSigningKey = key, | |
ValidateIssuer = true, | |
ValidIssuer = _configuration["JwtIssuer"], | |
ValidateAudience = true, | |
ValidAudience = _configuration["JwtAudience"] | |
}; | |
var identity = handler.ValidateToken(tokenString, validations, out var tokenSecure).Identity as ClaimsIdentity; | |
if (identity == null) | |
{ | |
throw new Exception("boom - Identity is not valid"); | |
} | |
return new TokenReadResult | |
{ | |
Username = identity.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment