Asp.net core 使用.NET Core使用Sustainsys登录SAML2时有多个IDP
我们正在使用Sustainsys中间件和.NET内核连接到SAML2 IDP。它工作得很好 然而,当我们在Startup.cs中添加多个IDP时,我们会遇到麻烦。用户将选择要登录的IDP,然后代码将向该IDP发送质询 如何在代码中指定哪个IDP 使用标准的.NET Framework,它很简单:Asp.net core 使用.NET Core使用Sustainsys登录SAML2时有多个IDP,asp.net-core,saml-2.0,sustainsys-saml2,Asp.net Core,Saml 2.0,Sustainsys Saml2,我们正在使用Sustainsys中间件和.NET内核连接到SAML2 IDP。它工作得很好 然而,当我们在Startup.cs中添加多个IDP时,我们会遇到麻烦。用户将选择要登录的IDP,然后代码将向该IDP发送质询 如何在代码中指定哪个IDP 使用标准的.NET Framework,它很简单: Context.GetOwinContext().Environment.Add("saml2.idp", new Entity(IDP2EntityId)); 但是在.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);
如何在
登录控制器中指定要使用的IDP?我找到了解决方案。我们研究了Sustainsys代码,发现了未记录的(?)功能,用于在AuthenticationProperties.Items中指定IDP,并使用“IDP”项。像这样:
LoginController.cs
string saml2AuthenticationScheme = "saml2.idp";
var props = new AuthenticationProperties
{
RedirectUri = returnUrl,
Items = { { "scheme", saml2AuthenticationScheme }, { "idp", theSelectedIDPIdentityId } }
};
return Challenge(properties: props, saml2AuthenticationScheme);
我找到了解决办法。我们研究了Sustainsys代码,发现了未记录的(?)功能,用于在AuthenticationProperties.Items中指定IDP,并使用“IDP”项。像这样:
LoginController.cs
string saml2AuthenticationScheme = "saml2.idp";
var props = new AuthenticationProperties
{
RedirectUri = returnUrl,
Items = { { "scheme", saml2AuthenticationScheme }, { "idp", theSelectedIDPIdentityId } }
};
return Challenge(properties: props, saml2AuthenticationScheme);