Sustainsys / Saml2

Saml2 Authentication services for ASP.NET
Other
959 stars 602 forks source link

Support for .NET 6 #1316

Closed samisq closed 2 years ago

samisq commented 2 years ago

Running Sustainsys SAML2 on .NET 6 throws the following exception:

System.InvalidCastException: Unable to cast object of type 'RSASecurityTransforms' to type 'System.Security.Cryptography.RSACryptoServiceProvider'.
   at Sustainsys.Saml2.WebSso.Saml2RedirectBinding.AddSignature(String queryString, ISaml2Message message)
   at Sustainsys.Saml2.WebSso.Saml2RedirectBinding.Bind[TMessage](TMessage message, ILoggerAdapter logger, Action`3 xmlCreatedNotification)
   at Sustainsys.Saml2.IdentityProvider.Bind[TMessage](TMessage message, Action`3 xmlCreatedNotification)
   at Sustainsys.Saml2.WebSso.SignInCommand.InitiateLoginToIdp(IOptions options, IDictionary`2 relayData, Saml2Urls urls, IdentityProvider idp, Uri returnUrl, HttpRequestData request)
   at Sustainsys.Saml2.WebSso.SignInCommand.Run(EntityId idpEntityId, String returnPath, HttpRequestData request, IOptions options, IDictionary`2 relayData)
   at Sustainsys.Saml2.AspNetCore2.Saml2Handler.ChallengeAsync(AuthenticationProperties properties)
   at Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, String scheme, AuthenticationProperties properties)

The runtime detection logic in EnvironmentHelpers.IsNetCore doesn't account for versions higher than .NET 5. Also, X509Certificate2.Private is now obsolete in .NET 6. The recommendation is to use X509Certificate2.GetRSAPrivateKey

Sustainsys SAML2 version: 2.8.0.

AndersAbel commented 2 years ago

Duplicate of #1252 .