Null:AssertionConsumerService 期间的对象引用=> saml2AuthnResponse.CreateSession
Null : Object reference during AssertionConsumerService => saml2AuthnResponse.CreateSession
我是 运行 ITFoxtec.Identity.Saml2.Mvc (v4.5.0) MVC.NET(4.7.2 框架)。
我的 IdP 说已成功通过身份验证...重定向回来...
但是当我从 IdP 得到回复时 - 我在这个调用中发现了一个空异常。不幸的是,它没有给我行号或任何有助于追踪它的信息。
saml2AuthnResponse.CreateSession()
我尝试了多种构建 nuget 包的方法,以使其在失败的地方注销 - 但到目前为止,当 using/referencing 来自包外时,我还没有成功。我在 web.config:
中设置了如下其他设置
<add key="Saml2:CertificateValidationMode" value="PeerOrChainTrust" />
<add key="Saml2:RevocationMode" value="NoCheck" />
我的 AssertionConsumerService 与您网站上的示例几乎相同:
public ActionResult AssertionConsumerService()
{
var binding = new Saml2PostBinding();
var saml2AuthnResponse = new Saml2AuthnResponse(config);
binding.Unbind(Request.ToGenericHttpRequest(), saml2AuthnResponse);
saml2AuthnResponse.CreateSession(claimsAuthenticationManager: new SAMLDefaultClaimsAuthenticationManager());
var returnUrl = binding.GetRelayStateQuery()[relayStateReturnUrl];
return Redirect(string.IsNullOrWhiteSpace(returnUrl) ? Url.Content("~/") : returnUrl);
}
在 Saml2ResponseExtensions.cs CreateSession() ln.19 上的 printf 调试中
我可以说它(可能?)不会在这一行之前抛出(因为我可以复制+粘贴在我的外部范围内重新创建所有前面的变量,没有问题)。
var sessionSecurityToken = lifetime.HasValue
? new SessionSecurityToken(transformedPrincipal, lifetime.Value)
...
@AndersRevsgaard 有什么想法吗?
我一直追踪到这一行,它引发了 Null ref 错误:
FederatedAuthentication.SessionAuthenticationModule.AuthenticateSessionSecurityToken(sessionSecurityToken, true);
虽然仍然很神秘,但这个答案解决了这个问题:
What makes the FederatedAuthentication.SessionAuthenticationModule return NULL?
通过向 web.config.
添加一些部分
<configSections>
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>
<system.web>
<authentication mode="None" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</modules>
</system.webServer>
<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="false" />
</federationConfiguration>
</system.identityModel.services>
您可以查看 ITFoxTec 测试 web.config 以获取完整示例:
https://github.com/ITfoxtec/ITfoxtec.SAML2/blob/master/WebAppTest/Web.config
我是 运行 ITFoxtec.Identity.Saml2.Mvc (v4.5.0) MVC.NET(4.7.2 框架)。 我的 IdP 说已成功通过身份验证...重定向回来... 但是当我从 IdP 得到回复时 - 我在这个调用中发现了一个空异常。不幸的是,它没有给我行号或任何有助于追踪它的信息。
saml2AuthnResponse.CreateSession()
我尝试了多种构建 nuget 包的方法,以使其在失败的地方注销 - 但到目前为止,当 using/referencing 来自包外时,我还没有成功。我在 web.config:
中设置了如下其他设置<add key="Saml2:CertificateValidationMode" value="PeerOrChainTrust" />
<add key="Saml2:RevocationMode" value="NoCheck" />
我的 AssertionConsumerService 与您网站上的示例几乎相同:
public ActionResult AssertionConsumerService()
{
var binding = new Saml2PostBinding();
var saml2AuthnResponse = new Saml2AuthnResponse(config);
binding.Unbind(Request.ToGenericHttpRequest(), saml2AuthnResponse);
saml2AuthnResponse.CreateSession(claimsAuthenticationManager: new SAMLDefaultClaimsAuthenticationManager());
var returnUrl = binding.GetRelayStateQuery()[relayStateReturnUrl];
return Redirect(string.IsNullOrWhiteSpace(returnUrl) ? Url.Content("~/") : returnUrl);
}
在 Saml2ResponseExtensions.cs CreateSession() ln.19 上的 printf 调试中 我可以说它(可能?)不会在这一行之前抛出(因为我可以复制+粘贴在我的外部范围内重新创建所有前面的变量,没有问题)。
var sessionSecurityToken = lifetime.HasValue
? new SessionSecurityToken(transformedPrincipal, lifetime.Value)
...
@AndersRevsgaard 有什么想法吗?
我一直追踪到这一行,它引发了 Null ref 错误:
FederatedAuthentication.SessionAuthenticationModule.AuthenticateSessionSecurityToken(sessionSecurityToken, true);
虽然仍然很神秘,但这个答案解决了这个问题: What makes the FederatedAuthentication.SessionAuthenticationModule return NULL? 通过向 web.config.
添加一些部分<configSections>
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>
<system.web>
<authentication mode="None" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</modules>
</system.webServer>
<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="false" />
</federationConfiguration>
</system.identityModel.services>
您可以查看 ITFoxTec 测试 web.config 以获取完整示例: https://github.com/ITfoxtec/ITfoxtec.SAML2/blob/master/WebAppTest/Web.config