如何在身份服务器 3 中为 Sustainsys 外部提供程序设置 acr 值



我在SQL中使用本地用户帐户进行了Idsvr3。此外,我还配置了使用 SAML2 的外部身份提供程序 https://github.com/Sustainsys/Saml2 我遵循了此处的示例

现在,当用户访问客户端应用程序时,他将被重定向到登录页面,该页面显示用于本地登录的用户ID/密码文本框以及重定向到外部提供程序的按钮。

我想改变这种行为。我希望用户根据某些条件直接转到外部登录。我已经读到我可以将所需的登录提供程序传递给acr_valuesIdSvr3 将直接转到外部提供程序。

这是我如何使用IdSvr3注册外部提供程序(请注意,为简洁起见,删除了一些代码(

public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Map("/identity", idsrvApp =>
{
var identityServerOptions = new IdentityServerOptions
{
AuthenticationOptions = new AuthenticationOptions()
{                        
}
.Configure(ConfigureIdentityProviders),                    
};
idsrvApp.UseIdentityServer(identityServerOptions);
});            
}
private void ConfigureIdentityProviders(IAppBuilder app, string signInAsType)
{                           
// SAML2
var options = new Saml2AuthenticationOptions(false)
{
SPOptions = new SPOptions
{
EntityId = new EntityId("https://localhost:44300/IdSrv3/Saml2"),
},
SignInAsAuthenticationType = signInAsType,
Caption = "SAML2p"
};
UseIdSrv3LogoutOnFederatedLogout(app, options);
options.SPOptions.ServiceCertificates.Add(new X509Certificate2(
AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/App_Data/Sustainsys.Saml2.Tests.pfx"));
options.IdentityProviders.Add(new IdentityProvider(
new EntityId("https://stubidp.sustainsys.com/Metadata"),
options.SPOptions)
{
LoadMetadata = true
});
app.UseSaml2Authentication(options);            
}
}

这是客户端应用程序启动

public class Startup
{
public void Configuration(IAppBuilder app)
{            
app.UseCookieAuthentication(CK);
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "https://localhost:44300/identity",
Scope = "openid profile email",
ClientId = "XXXXXXXXXXXXXXX",
RedirectUri = "http://localhost:36102/",
ResponseType = "id_token",
SignInAsAuthenticationType = "Cookies",               
Notifications = new OpenIdConnectAuthenticationNotifications
{                    
RedirectToIdentityProvider = (n) =>
{
if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.AuthenticationRequest)
{
if(SomeCondition == true)
{
n.ProtocolMessage.AcrValues = "idp:saml2";
}
}
return Task.FromResult(0);
}
}                
});
}        
}

但是,身份服务器会引发错误External login error: provider requested saml2 is not a configured external provider

提供程序的有效名称是什么Sustainsys/Saml2配置在哪里?

我想我找到了。idp实际上是AuthenticationType财产的价值。 在 IdentityServer3 中设置外部提供程序期间,默认情况下,Saml2AuthenticationOptions将 AutheticationType 设置为Saml2。 所以在客户端应用程序中,我必须使用与acr-values完全相同的值,它是区分大小写的。我使用的是小s而不是大写S。当我更改为Saml2时,它起作用了。

我还可以将AutheticationType覆盖为我想要的任何字符串,这很好,因为现在我可以设置多个支持SAML2协议的外部IdP,并通过它们的AutheticationType来区分它们

我也发现这个文档很有帮助 https://media.readthedocs.org/pdf/saml2/latest/saml2.pdf

在第2.5.4 Step 3: Configure your identity server with the new identity provider节中查看 okta 如何配置IdentityServer3

同样来自身份服务器文档

身份验证类型必须是唯一值才能标识外部 标识提供者。此值还将用于 生成的令牌。此外,相同的值可用于 在授权/身份验证期间预先选择身份提供程序 使用 acr_values 参数的请求(有关详细信息,请参阅此处 信息(。此值还用于限制允许的标识 客户端配置上的提供程序。

相关内容

最新更新