Answer the question
In order to leave comments, you need to log in
Adding a new subject to a JWT?
Hello. My question is how do I add new data to an existing jwt token. I am trying to add like this.
JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();
JwtSecurityToken jwtToken = (JwtSecurityToken)tokenHandler.ReadToken(token);
byte[] key = Convert.FromBase64String(secret);
TokenValidationParameters parametrs = new TokenValidationParameters()
{
RequireExpirationTime = true,
ValidateIssuer = false,
ValidateAudience = false,
IssuerSigningKey = new SymmetricSecurityKey(key)
};
SecurityToken securityToken;
ClaimsPrincipal principal = tokenHandler.ValidateToken(token, parametrs, out securityToken);
Claim myClaim=new Claim(property, value);
ClaimsIdentity identity = new ClaimsIdentity();
identity.AddClaim(myClaim);
principal.AddIdentity(identity);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question