AzureAD / azure-activedirectory-identitymodel-extensions-for-dotnet

IdentityModel extensions for .Net
MIT License
1.03k stars 386 forks source link

[Bug / Feature Request] Create JsonWebToken with empty Payload #2656

Open remyblok opened 2 weeks ago

remyblok commented 2 weeks ago

Is your feature request related to a problem? Please describe. I need to create Detached JWS signature for all requests to a webservice. Also for GET requests (which do not have a body/payload). This library creates JWTs of thich I remove the payload to get the JWS variant. But for GET-requests there is no payload. The CreateToken()-method fails when the payload is null or string.Empty.

Describe the solution you'd like I want to be able to call JsonWebTokenHandler.CreateToken() with string.Empty as payload. The result should be an empty payload in the created token:

{header}..{signature}

Describe alternatives you've considered I've concidered using JsonWebTokenHandler.CreateToken(SecurityTokenDescriptor tokenDescriptor). The issue is that then an (empty) json-object is automatically created as payload.

I'm now calling the internal static CreateToken() on JsonWebTokenHandler using reflection with an string.Empty payload. This actually works perfectly and results in the expected behaviour as described above. Only reflection is not a future proof solution.

Additional context iDeal API desciption with requirements of Detached JWS for all requests

remyblok commented 2 weeks ago

Also. I looked at the documentation of CreateToken(). There it does not mention that the payload cannot be string.Empty. So this may even be concidered a bug. https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/c24bfe683427dbad566fe617d0d590ec3a61d8aa/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.CreateToken.cs#L32