I'm using old code for JWT validation, and the reference to System.IdentityModel
throws an error unless I add the Microsoft.Data.SqlClient
dependency.
I would like to know why this happens.
private string generateJwtToken(Employee employee)
{
var tokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler();
var key = System.Text.Encoding.ASCII.GetBytes(secret);
var symmetricKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(key);
var claimRe = new System.Security.Claims.Claim("re", employee.re.ToString());
var claimRl = new System.Security.Claims.Claim("role", employee.role.ToString());
var claims = new[] { claimRe, claimRl };
var tokenDescriptor = new Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor
{
Subject = new System.Security.Claims.ClaimsIdentity(claims),
Expires = DateTime.UtcNow.AddDays(7),
SigningCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(symmetricKey, Microsoft.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
return tokenHandler.WriteToken(token);
}
Note: code from when I was studying.