-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Net8 uses the new JwtSecurityTokenHandler() WriteToken error. #52369
Comments
How can I allow the key length to be compatible with my previous version? |
The underlying change to increase the minimum key sizes is due to changes in v7 of the IdentityModel libraries, which ASP.NET Core 8 depends on, so I think this question is best suited for the https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet repo. |
Is there anything else I can do besides increasing the length of the key? |
I'm not aware of a way to force a smaller key size to be used. FYI this was the change that increased the minimum key length: AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2072 |
I ran into the same issue where I thought the old keys should be compatible to provide seamless migration, but it didn't work.
|
I faced the same issue during migration of my product to net8: JWTs are used by end-users for accessing API from 3rd parties (like Zapier or PowerAutomate) and it is really painful to force all users to re-generate and update their JWTs. I've reviewed It seems that extending key size with zeros keeps backward compatibility with previously generated JWTs (in net6 and even in netcore31). How to add this support of old 'short' keys:
Nothing is changed in HMAC code that actually uses the key, so extending the key with zeros allows to bypass |
See this document for a workaround if you cannot change to a longer key: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/wiki/IDX10720 |
@martincostello in my NET8 app I tried to set
but without a workaround with zeros anyway I constantly get
(with the latest Microsoft.IdentityModel.Tokens 7.1.2) It is unclear for me how this switch could work - I cannot find anything that checks this switch in Maybe this switch only in the case when CustomCryptorProvider is used?.. In any way, this is definitely not the case when JWT auth is enabled for MVC Core app in a standard way. |
Maybe there's some nuance to it that isn't described in the documentation I linked to. You'd have to ask over in that repo. |
@VitaliyMF The switch works fine in v6.35.0. (See code here) But it seems that this change wasn't merged on v7.1.2. The PR is here: AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2421 |
Hope it will be merged into 7.x branch soon. For now, my workaround works just fine - for all version (old 6.x, 6.30+ and 7.x) (and already used in production). |
Thanks for answering this, @martincostello! Closing as no further action is pending here. |
Is there an existing issue for this?
Describe the bug
I am in net6, and this code can be used normally. However, there was an error in net8,
The length of the SecretKey is 16
SymmetricSecurityKey key =
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtSettings.SecretKey));
Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: