The problem is that in one controller, this method gets all the headers when reading the token, and in the other controller not all the headers, although the methods, library versions, etc. are the same, here is the method itself:
[HttpGet(Name = "GetTokenPrincipal")]
[Route("/GetTokenPrincipal")]
public ClaimsPrincipal? GetTokenPrincipal([FromQuery]string token)
{
var jwtSecurityToken = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler().ReadJwtToken(token);
var tokenEnc = jwtSecurityToken.Header.Enc;
throw new NotImplementedException();
}
Headers received from the first controller from jwe:
{"alg":"dir","enc":"A256CBC-HS512","typ":"JWT","cty":"JWT"}.{}
Headers received from the second controller from jwe:
{"alg":"dir","typ":"JWT"}.{}
What i try:
The problem was that the libraries had different versions:
Microsoft.IdentityModel.Tokens (Version was 8.0.1) (Version is now 7.1.2)
System.IdentityModel.Tokens.Jwt (Version was 7.1.2) (Version is now 7.1.2)
Versions of these libraries must be the same, or everything stops working!!