2

Only for ComponentSpace users!

I need to add provider configurations from database after startup. There is no useful documentation on this topic. Here are few suggestions I found and tried with no success.

Has anyone successfully added identity providers configurations dynamically using ComponentSpace?

A post on their forum is suggesting to inject ComponentSpace.Saml2.Configuration.SamlConfigurations in my controller. The problem is that SamlConfigurations is null althow I already have working configurations loaded at startup.

https://componentspace.com/Forums/7950/

I can access the database as early as in app Configure from Startup.cs. But the saml has already been added in ConfigureServices using services.AddSaml, and there is no obvious way to update this.

identigral
  • 3,920
  • 16
  • 31
profimedica
  • 2,716
  • 31
  • 41

1 Answers1

4

The recommended approach is to implement the ISamlConfigurationResolver interface as described in the Configuration Guide.

https://www.componentspace.com/Forums/8234/Configuration-Guide

The section "SAML Configuration Options" outlines the alternatives and recommendations for when to use each approach.

The section "Implementing ISamlConfigurationResolver" describes this interface and includes a couple of example implementations. You would store your SAML configuration in a custom database. Your implementation of ISamlConfigurationResolver would retrieve information from this database as requested. Configuration is requested on demand as part of a SAML SSO or SLO flow.

Note that the current version of the documentation suggests using services.TryAddScoped to specify your implementation. This requires you to do this prior to calling services.AddSaml otherwise the default ISamlConfigurationResolver implementation that reads from appsettings.json is still active. A better approach is to call services.AddScoped();

Regarding the approach you tried, you can specify the SamlConfigurations programmatically. If you take a look at the ExampleIdentityProvider and ExampleServiceProvider projects we ship, their Startup classes include a ConfigureSaml method. Instead of calling services.AddSaml(Configuration.GetSection("SAML")), which adds the SAML configuration from the appsettinsg.json, you would call services.AddSaml(config => ConfigureSaml(config)).

However, I think for your scenario it's better to implement ISamlConfigurationResolver.

ComponentSpace
  • 1,287
  • 6
  • 9