如何在身份服务器 3 中为 Sustainsys 外部提供者设置 acr 值
How to set acr-values for Sustainsys external provider in identity server 3
我在 SQL 中有 Idsvr3
个本地用户帐户。此外,我还使用 https://github.com/Sustainsys/Saml2 I followed the sample here
配置了支持 SAML2 的外部身份提供者
现在,当用户访问客户端应用程序时,他会被重定向到登录页面,该页面显示 userid/password 用于本地登录的文本框以及一个重定向到外部提供商的按钮。
我想改变这种行为。我希望用户根据某些条件直接转到外部登录。我已经 read that 我可以将所需的登录提供程序传递给 acr_values
并且 IdSvr3 将直接转到外部提供程序。
以下是我如何使用 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
节中的 IdentityServer3
是如何配置 okta 的
同样来自 IdentityServer documentation
AuthenticationType must be a unique value to identify the external
identity provider. This value will also be used for the idp claim in
the resulting tokens. Furthermore the same value can be used to
pre-select identity providers during authorization/authentication
requests using the acr_values parameter (see this for more
information). This value is also used to restrict the allowed identity
providers on the Client configuration.
我在 SQL 中有 Idsvr3
个本地用户帐户。此外,我还使用 https://github.com/Sustainsys/Saml2 I followed the sample here
现在,当用户访问客户端应用程序时,他会被重定向到登录页面,该页面显示 userid/password 用于本地登录的文本框以及一个重定向到外部提供商的按钮。
我想改变这种行为。我希望用户根据某些条件直接转到外部登录。我已经 read that 我可以将所需的登录提供程序传递给 acr_values
并且 IdSvr3 将直接转到外部提供程序。
以下是我如何使用 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
IdentityServer3
是如何配置 okta 的
同样来自 IdentityServer documentation
AuthenticationType must be a unique value to identify the external identity provider. This value will also be used for the idp claim in the resulting tokens. Furthermore the same value can be used to pre-select identity providers during authorization/authentication requests using the acr_values parameter (see this for more information). This value is also used to restrict the allowed identity providers on the Client configuration.