Token handler unable to convert the token to jwt token
This is how I do it and it works for me:
var token = new System.IdentityModel.Tokens.JwtSecurityToken(jwt);
The above line works for
System.IdentityModel.Tokens.Jwt
package version4.0.0
. As @Nick commented, in the latest versions of the package, theJwtSecurityToken
does not exist in the previous namespace anymore, instead it exists inSystem.IdentityModel.Tokens.Jwt
so you need to write:var token = new System.IdentityModel.Tokens.Jwt.JwtSecurityToken(jwt);
Unless your token is not well-formed. It would be better if you share the token too.
Update:
You also need to remove the word "Bearer " from the beginning of the token (If you haven't):
var jwt = context.Request.Headers["Authorization"].Replace("Bearer ", string.Empty);