JwtSecurityTokenHandler Validate Token fails if not using Windows in 5.3.0
See original GitHub issueWhen creating a new JwtSecurityTokenHandler()
and passing in a RSACryptoServiceProvider
in OSX, an exception is thrown when calling ValidateToken
.
The error is: System.PlatformNotSupportedException: 'CspKeyContainerInfo' requires Windows Cryptographic API (CAPI), which is not available on this platform.
Exceptions caught:
'System.PlatformNotSupportedException: 'CspKeyContainerInfo' requires Windows Cryptographic API (CAPI), which is not available on this platform.
at System.Security.Cryptography.RSACryptoServiceProvider.get_CspKeyContainerInfo()
at Microsoft.IdentityModel.Tokens.RSACryptoServiceProviderProxy..ctor(RSACryptoServiceProvider rsa) in C:\agent2\_work\56\s\src\Microsoft.IdentityModel.Tokens\RsaCryptoServiceProviderProxy.cs:line 74
at Microsoft.IdentityModel.Tokens.AsymmetricAdapter.Initialize(RSA rsa, String algorithm) in C:\agent2\_work\56\s\src\Microsoft.IdentityModel.Tokens\AsymmetricAdapter.cs:line 305
at Microsoft.IdentityModel.Tokens.AsymmetricAdapter..ctor(SecurityKey key, String algorithm, HashAlgorithm hashAlgorithm, HashAlgorithmName hashAlgorithmName, Boolean requirePrivateKey) in C:\agent2\_work\56\s\src\Microsoft.IdentityModel.Tokens\AsymmetricAdapter.cs:line 84
The stack-trace refers to RsaCryptoServiceProviderProxy.cs
and looking at the commit history, it looks like it added Net Standard 2.0 Support. The parameter references the CspKeyContainerInfo
in the constructor here.
This does not work in OSX as, as the exception states, CspKeyContainerInfo isn’t supported. So when it tries to access the parameter, this exception is thrown. The code used to call this previously worked in 5.2.4.
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (10 by maintainers)
Top Results From Across the Web
Access Token validating fails with JWTSecurityTokenHandler
Check the new token from azure with jwt.io. If the aud is equal the registered application id the token can be successfull validated....
Read more >c# - TokenValidationParameters no longer working after ...
TokenValidationParameters is in assembly: Microsoft.IdentityModel.Tokens. It looks like you are using Katana (the first version of asp.net ...
Read more >How to Validate JWTs in .NET
Then you create a token handler ( JwtSecurityTokenHandler ) and use it to validate the token against the validation parameters.
Read more >.NET 6.0 - Create and Validate JWT Tokens + Use Custom ...
This code attempts to validate the provided JWT token and return the userId from the token claims. If the token is null or...
Read more >System.IdentityModel.Tokens.Jwt 6.32.1
Includes types that provide support for creating, serializing and validating JSON Web Tokens.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@GeoK I’m sorry, I ran a test on a console application using only Microsoft.IdentityModel.Tokens in version 5.4.0, and it worked in linux and windows, I believe that this is not working in my webapi netcoreapp application because of the version of Microsoft.AspNetCore .App still does not contain this fix, correct?
@pauloofmeta please reopen if this issue is still occurring.