我们正在使用带有.NET核心的可持续发展中间件来连接到SAML2身份提供商。它工作得很好。
但是,当我们在Startup.cs中添加多个IDP时,我们就会遇到麻烦。用户将选择要登录到哪个IDP,然后代码应向该IDP发送质询。
我们如何在代码中指定哪个IDP?
使用标准的.NET框架,它是直接的:
Context.GetOwinContext().Environment.Add("saml2.idp", new Entity(IDP2EntityId));但是在.NET核心中间件中没有这样的构造。
这是我的代码。基本上,我在启动时添加了两个IDPs,但我不知道如何在登录/质询期间指定哪一个?使用此代码时,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
发布于 2021-01-12 18:55:44
我找到了解决方案。我们研究了可持续发展的代码,发现了未记录的(?)在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);https://stackoverflow.com/questions/65681006
复制相似问题