使用.NET Core使用Sustainsys登录SAML2的多个IDP



我们使用带有.NET Core的Sustainsys中间件连接到SAML2 IDP。它运行良好。

然而,当我们在Startup.cs中添加多个IDP时,我们就会遇到麻烦。用户将选择登录哪个IDP,然后代码应向该IDP发送质询。

我们如何在代码中指定哪个IDP?

使用标准的.NET框架,它是直接的:

Context.GetOwinContext().Environment.Add("saml2.idp", new Entity(IDP2EntityId));

但是在.NET核心中间件中没有这样的构造。

这是我的密码。基本上,我在启动过程中添加了两个IDP,但我不知道如何在登录/挑战过程中指定哪一个?有了这个代码,IDP-1总是被选中,因为它是第一个添加的。

STARTUP.CS

public void ConfigureServices(IServiceCollection services)
{
var authenticationBuilder = GetAuthenticationBuilder(services);
string authenticationScheme = "saml2.idp"
authenticationBuilder.AddSaml2(authenticationScheme, options =>
{
options.SPOptions = GetSPOptions();
// Add IDP-1
options.IdentityProviders.Add(
new IdentityProvider(new EntityId(IDPEntityUrl1), options.SPOptions)
{
MetadataLocation = IDPMetadataUrl1
});
// Add IDP-2
options.IdentityProviders.Add(
new IdentityProvider(new EntityId(IDPEntityUrl2), options.SPOptions)
{
MetadataLocation = IDPMetadataUrl2
});
}
}

LOGINCONTROLLER.CS

string saml2AuthenticationScheme = "saml2.idp";
var props = new AuthenticationProperties
{
RedirectUri = returnUrl,
Items = { { "scheme", saml2AuthenticationScheme } }
};
return Challenge(properties: props, saml2AuthenticationScheme);

如何指定要在LoginController中使用的IDP?

我找到了解决方案。我们研究了Sustainsys代码,并发现了未记录的(?(特性来指定AuthenticationProperties中的IDP;idp";项目像这样:

LoginController.cs

string saml2AuthenticationScheme = "saml2.idp";
var props = new AuthenticationProperties
{
RedirectUri = returnUrl,
Items = { { "scheme", saml2AuthenticationScheme }, { "idp", theSelectedIDPIdentityId } }
};
return Challenge(properties: props, saml2AuthenticationScheme);

最新更新