I'm using Microsofts libraries to create an encrypted JWT ( JWE ), using RSA public/private keys. I'm propably missing something on how to properly create the JWT, because the header 'typ' value is 'JWT' instead of 'JWE'.
// Create JWT credentials
var encryptingCredentials = new EncryptingCredentials(publicKey,
"RSA-OAEP",
"A256CBC-HS512");
// Create JWT header
var header = new JwtHeader(encryptingCredentials);
// Create JWT payload
var payload = new JwtPayload
{
...
};
// Create JWT request string
var securityToken = new JwtSecurityToken(header, payload);
var handler = new JwtSecurityTokenHandler();
var tokenString = handler.WriteToken(securityToken);
// Final redirect url
var url = $"https://some-external-service.com/oidc/authorize?request={tokenString}";
return Redirect(url);
The produced header ( after base64url decoding ) is as follows
{
"alg": "RSA-OAEP",
"enc": "A256CBC-HS512",
"kid": "any.oidc-encryption-preprod.test.jwk.v.1",
"typ": "JWT"
}
When I compare this to a working reference example in python, the only difference is
"typ": "JWE"
Headers Typ property is read-only, and doing header["typ"] = "JWE" doesn't change the output.
Receiving end produces server error 500, their python example works great so something is wrong with my JWT output.
Am I using System.IdentityModel.Tokens.Jwt libraries wrong?