ComponentSpace.SAML2、.NET Core 2.2、IdentityServer4 2.3.2 - AddSaml 重载和 SamlMiddleware 的奇怪行为

问题描述 投票:0回答:0

我正在使用

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)
重载。

  1. 以前工作的地方,现在我得到一个开发人员异常页面,告诉我使用
    IIdentityServerBuilder.AddInMemoryPersistedGrants()
    ,不仅如此,即使在
    ConfigureServices
    中添加,消息仍然存在,直到我在
    app.UseIdentityServer()
    中删除/评论
    Configure
  2. 一旦完成,现在我得到一个错误说
    SamlMiddleware
    没有注册,即使我在
    IServiceCollection.AddSamlMiddleware()
    中调用
    ConfigureServices
    并且根据在引擎盖下调用
    IServiceCollection.AddTransient<SamlMiddleware>()
    的ComponentSpace。

我已经尝试了从

ComponentSpace.Saml2
(具有我需要的中间件功能的最小版本)到
3.0.0
(与Core 2.2兼容的最大版本)的每个
4.0.0
版本,并且行为是相同的。我也接触过 ComponentSpace,他们也被难住了。有谁知道这里可能发生了什么以及如何解决它?

c# .net-core identityserver4 saml-2.0
© www.soinside.com 2019 - 2024. All rights reserved.