question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JwtSecurityTokenHandler Validate Token fails if not using Windows in 5.3.0

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
pauloofmetacommented, Feb 1, 2019

@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?

0reactions
brentschmaltzcommented, Feb 6, 2019

@pauloofmeta please reopen if this issue is still occurring.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found