我正在尝试做到这一点,以便当用户访问我的网站时,他们能够选择他们想要使用的身份验证方法。他们将选择重定向到他们的 IdP 并通过 SAML(使用 SustainSys.Saml2 nuget pkg)或通过启用 MFA 的 AuthO 登录进行身份验证。我的问题是,当用户访问我的网站时,它会立即向他们显示 AuthO 登录页面,因此他们无法通过 SAML 进行身份验证(实际上这将是该网站更有可能的选择)。
我有一个页面,可以简单地让他们选择他们想要使用的身份验证类型
Account/SelectAuth
,但是当您第一次访问该站点时,AuthO 会自动拦截并显示他们的登录页面。我在想这个错误吗?或者,如果没有,我怎样才能让用户首先转到Account/SelectAuth
,在那里他们有两个按钮选择 AuthO + MFA 或 SAML,然后将他们发送到正确的操作。
Program.cs
builder.Services.AddAuthentication(opt =>
{
// Default scheme that maintains session is cookies.
//opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
// If there's a challenge to sign in, use the Saml2 scheme.
//opt.DefaultChallengeScheme = Saml2Defaults.Scheme;
})
.AddCookie("CookiesAuth", options =>
{
options.AccessDeniedPath = "/tracking/account/login";
options.LoginPath = "/tracking/account/login";
})
.AddSaml2(opt =>
{
// Us; the Service Provider
opt.SPOptions.EntityId = new EntityId(builder.Configuration["SAML:ServiceProvider:EntityId"]);
// Single logout messages should be signed according to the SAML2 standard, so we need
// to add a certificate for our app to sign logout messages with to enable logout functionality.
opt.SPOptions.ServiceCertificates.Add(new X509Certificate2(builder.Configuration["SAML:ServiceProvider:Certificate"], "", X509KeyStorageFlags.MachineKeySet));
// Them; the Identify Provider
opt.IdentityProviders.Add(
// IdP
new IdentityProvider(new EntityId(builder.Configuration["SAML:IdentityProvider:EntityId"]), opt.SPOptions)
{
AllowUnsolicitedAuthnResponse = true,
MetadataLocation = builder.Configuration["SAML:IdentityProvider:MetadataLocation"]
});
opt.Notifications.AcsCommandResultCreated = AccountController.AcsCommandResultCreated;
});