Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.