
[英]Not able to implement the AspNet Core 2 Handler support for SAML2 from Sustainsys
[英]Not able to SignOut using Saml2 from Sustainsys
这应该将我的应用重定向到我的 AdFs 登出页面,然后将我重定向回我的应用。 但是,它只是将我重定向到我的路线“/logout”。 在我的 ADFS 服务器上查看日志没有任何反应。
[AllowAnonymous]
[HttpGet]
[Route("api/logout")]
public async Task<IActionResult> Logout()
{
return SignOut(new AuthenticationProperties()
{
RedirectUri = "/logout"
},
Saml2Defaults.Scheme);
}
登录工作正常。 我什至尝试过同样的方法,但不起作用。 在这里,ReturnUrl 方法从 HttpContext.Response.Header 获取位置。 当我尝试注销时,位置始终是 null。
[AllowAnonymous]
[HttpGet]
[Route("api/login")]
public async Task<string> LoginAdfs()
{
string redirectUri = _appSettings.Saml.SpEntityId;
await HttpContext.ChallengeAsync(new AuthenticationProperties
{
RedirectUri = string.Concat(redirectUri, "/autenticado")
});
return ReturnUrl();
}
知道会发生什么吗?
更新 21/11/2019
原来 Saml2Handler 根本没有尝试将请求发送到服务器。 我在我的 output window 上收到这些消息:
Sustainsys.Saml2.AspNetCore2.Saml2Handler: Debug: Initiating logout, checking requirements for federated logout
Issuer of LogoutNameIdentifier claim (should be Idp entity id):
Issuer is a known Idp: False
Session index claim (should have a value):
Idp has SingleLogoutServiceUrl:
There is a signingCertificate in SPOptions: True
Idp configured to DisableOutboundLogoutRequests (should be false):
Sustainsys.Saml2.AspNetCore2.Saml2Handler: Information: Federated logout not possible, redirecting to post-logout
这是我的启动配置,我不明白这里有什么问题:
ServiceCertificate se = new ServiceCertificate()
{
Certificate = new X509Certificate2(SpCert, "",X509KeyStorageFlags.MachineKeySet),
Use = CertificateUse.Signing
};
SPOptions sp = new SPOptions
{
AuthenticateRequestSigningBehavior = SigningBehavior.Never,
EntityId = new EntityId(SpEntityId),
ReturnUrl = new Uri("/login"),
NameIdPolicy = new Sustainsys.Saml2.Saml2P.Saml2NameIdPolicy(null, Sustainsys.Saml2.Saml2P.NameIdFormat.Unspecified),
};
sp.ServiceCertificates.Add(se);
IdentityProvider idp = new IdentityProvider(new EntityId(appSettings.Saml.EntityId), sp);
idp.Binding = Saml2BindingType.HttpPost;
idp.AllowUnsolicitedAuthnResponse = true;
//idp.WantAuthnRequestsSigned = true;
idp.SingleSignOnServiceUrl = new Uri("/login");
//idp.LoadMetadata = true;
idp.SigningKeys.AddConfiguredKey(new X509Certificate2(IdpCert));
idp.MetadataLocation = theMetadata;
idp.DisableOutboundLogoutRequests = true;
为了使注销工作,两个特殊声明“LogoutNameIdentifier”和“SessionIndex”(全名是http://Sustainsys.se/Saml2/LogoutNameIdentifier
和http://Sustainsys.se/Saml2/SessionIndex
需要出现在用户上. 那些携带有关当前 session 的信息,Saml2 库需要能够进行注销。
现在我看不到你的整个启动,所以我无法理解你的应用程序的流程。 但是这些声明应该存在于库返回的身份中 - 可能存储在外部 cookie 中(如果您使用的是 asp.net 身份)。 然后,当您的应用程序设置应用程序 cookie 时,这两个声明必须传递到 session 身份。
此外,您实际上已经使用DisableOutboundLogoutRequests
禁用了出站注销。 但这不是这里的主要问题,因为您的日志表明所需的声明不存在。
根据我自己的经验,Anders Abel 提到的这两个声明应该出现在用户身上。 在我通过所有声明以及登录请求之前,我没有看到这些声明。 ASP.NET 核心在SignInAsync
上重新创建主体,并且需要在请求中传递声明。
通过以下内容,我可以使用我的服务完成 SingleLogout:
await HttpContext.SignInAsync(user.SubjectId, user.Username, props, user.Claims.ToArray());
您作为服务提供商使用的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.