azure-activedirectory-identitymodel-extensions-for-dotnet: JwtSecurityTokenHandler Validate Token fails if not using Windows in 5.3.0

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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted 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?