我正在使用
IdentityServer4
作为 IDP,使用 ComponentSpace.Saml2
库对 SP 发起的 SSO 进行概念验证。我目前仅限于 dotnet Core 2.2
和 IdentityServer4 2.3.2
,因为升级它们是一项重大任务,超出了本项目的范围。
因此,我最初的 POC 进展顺利并按预期工作,直接从
PartnerServiceProvider
加载 appsettings.json
配置。接下来我们尝试以大致如下的方式从数据库中获取多个 SP 配置:
var SSOConfigKeys = Configuration.GetSection("SAMLVendorConnections").Get<string[]>();
// we need to instantiate this so we can use the config in startup here
ISPInitiatedVendorSSOConfigSelector vendorSSOCfg = new SPInitiatedVendorSSOConfigSelector(deps);
Dictionary<string, SPInitiatedVendorSSOConfig> ssoCfgMap = new Dictionary<string, SPInitiatedVendorSSOConfig>();
SamlConfigurations samlCfg = Configuration.GetSection("SAML").Get<SamlConfigurations>();
samlCfg.Configurations.First().PartnerServiceProviderConfigurations = new List<PartnerServiceProviderConfiguration>();
foreach (var k in SSOConfigKeys)
{
ssoCfgMap.Add(k, await vendorSSOCfg.Get(k));
samlCfg.Configurations.First().PartnerServiceProviderConfigurations.Add(
new PartnerServiceProviderConfiguration()
{
// set properties based on what we got from the db
});
}
services.AddSaml((cfg) =>
{
cfg = samlCfg;
})
但问题源于现在使用
IServiceCollection.AddSaml(Action<SamlConfigurations>)
重载而不是静态配置案例中使用的 IServiceCollection.AddSaml(IConfiguration)
重载。
IIdentityServerBuilder.AddInMemoryPersistedGrants()
,不仅如此,即使在ConfigureServices
中添加,消息仍然存在,直到我在app.UseIdentityServer()
中删除/评论Configure
SamlMiddleware
没有注册,即使我在IServiceCollection.AddSamlMiddleware()
中调用ConfigureServices
并且根据在引擎盖下调用IServiceCollection.AddTransient<SamlMiddleware>()
的ComponentSpace。我已经尝试了从
ComponentSpace.Saml2
(具有我需要的中间件功能的最小版本)到3.0.0
(与Core 2.2兼容的最大版本)的每个4.0.0
版本,并且行为是相同的。我也接触过 ComponentSpace,他们也被难住了。有谁知道这里可能发生了什么以及如何解决它?