Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation of a customized header using JsonWebTokenHandler #1210

Closed
GeoK opened this issue Jun 24, 2019 · 8 comments · Fixed by #1223
Closed

Allow creation of a customized header using JsonWebTokenHandler #1210

GeoK opened this issue Jun 24, 2019 · 8 comments · Fixed by #1223
Assignees
Labels
Enhancement The issue is a new feature
Milestone

Comments

@GeoK
Copy link
Member

GeoK commented Jun 24, 2019

Some customers have expressed the need for a facility that allows setting custom attributes in the header part, during token creation.

@steveoshima
Copy link

steveoshima commented Sep 28, 2019

FYI, this currently isnt working with RSA-PSS support.
For more info see code snippet below:
var handler = new JsonWebTokenHandler(); handler.SetDefaultTimesOnTokenCreation = false; return handler.CreateToken(jwt.Payload, new SigningCredentials(key, SecurityAlgorithms.RsaSsaPssSha256), new Dictionary<string, object>());
The key generation code is not shown but can confirm it works with standard RSA algorithm just not RSA-PSS.

I have tried a few branches which have the customized header support on the CreateToken function but all behave the same when using the RSA-PSS algorithm.

I will try and dedicate more time to add some tests. or an example repo if the above isnt enough.
FYI using .net core 2.2.100 on macos. Building branch mafurman/customJwtHeader using build.sh
When I use dev branch the additional header params are not supported in the CreateToken function.
Thanks.

@steveoshima
Copy link

You will see the testin is missing additonal header setup, if this is added im sure the error will occur. -

@GeoK
Copy link
Member Author

GeoK commented Oct 16, 2019

Hi @steveoshima - There is support for additional header claims, in both dev5x and dev branches.

I wasn't able to reproduce the issue you are facing, both on Windows and Mac, using different .net frameworks, even when changing the test as suggested here: #1223 (comment).

Please provide us with more information. What exactly is not working? Are you not seeing the additional header claims when you use RSA-PSS claim, or are you unable to create/sign a token?
Code sample and/or a repro project would be very helpful, together with the full stack trace.

@steveoshima
Copy link

steveoshima commented Oct 16, 2019

Hi, when using public 5.5.0 nuget release it does not allow
CreateToken(jwt.Payload, new SigningCredentials(key, SecurityAlgorithms.RsaSsaPssSha256), new Dictionary<string, object>());
With a branch such as mafurman/customJwtHeader which does allow the above I find SecurityAlgorithms.RsaSsaPssSha256 is not supported when attempting to generate the signed JWT.
When I use the dev branch neither SecurityAlgorithms.RsaSsaPssSha256 nor additional header parmeters are allowed, building using build.sh then updating my project the new built nupkg from artifact folder. The dev branch causes this error using.
CreateToken(jwt.Payload, new SigningCredentials(key, SecurityAlgorithms.RsaSsaPssSha256));
NotSupportedException: IDX10634: Unable to create the SignatureProvider. Algorithm: 'PS256', SecurityKey: 'Microsoft.IdentityModel.Tokens.RsaSecurityKey' is not supported.
(yet works for public nuget 5.5.0 release)

@GeoK
Copy link
Member Author

GeoK commented Oct 16, 2019

Correct, support for additional header claims is coming in v5.6.0.
How are you creating a SecurityKey ("key")?

Is your key an RSAOpenSsl object?

@steveoshima
Copy link

steveoshima commented Oct 17, 2019

I'm using nuget packge PemUtils to read in a private key - https://github.com/huysentruitw/pem-utils
e.g.
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("PrivateKeyHere"))) { using (var reader = new PemReader(stream)) { var key = new RsaSecurityKey(RSA.Create(reader.ReadRsaKey())); key.KeyId = "KidHere"; var handler = new JsonWebTokenHandler(); handler.SetDefaultTimesOnTokenCreation = false; return handler.CreateToken(jwt.Payload, new SigningCredentials(key, SecurityAlgorithms.RsaSsaPssSha256)); } }

When is 5.6.0 due for release? would be useful to get asap. Thanks and good work.

@GeoK
Copy link
Member Author

GeoK commented Oct 17, 2019

We will release 5.6.0 on Friday or early next week.

Can you check if your key is an RSACryptoServiceProvider or an RSAOpenSsl object?
RSACryptoServiceProvider doesn't support PSS.

@steveoshima
Copy link

The private key is generated from RSAOpenSsl object yes.

@GeoK GeoK modified the milestones: 6.x, 5.6.0 Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement The issue is a new feature
Projects
None yet
4 participants