Update/clear cached configuration

In our product we allow the customer to create the SAML configuration through the UI. We store it in our database (this was converted from the old CS ASP.NET Saml implementation), but it is not using the SamlDatabaseConfigurationResolver. Basically, the create works fine, but if we need to make an updates, the changes can’t be tested until we clear/update the configuration cache. I read the docs and attempted to use the IOptionsSnapshot samlConfigurations sample but seems like I need to set the values manually (the “samlConfigurations.Value” is a read only property.
Is there any way to just update the cached configuration by setting the full SamlConfiguration object to the cached object?
In the old ASP.NET version we used to just do this assignment:
SAMLController.Configuration = _samlConfiguration

Is there anything similar to this in the .Net core version?
Thanks!

For dynamic configurations and especially those stored in databases, our recommendation is to implement the ISamlConfigurationResolver interface.

The SamlDatabaseConfigurationResolver implements this interface with the SAML configuration stored in an Entity Framework database. However, a custom implementation of this interface could retrieve configuration from a custom database.

I’m assuming instead SAML configuration is being set using an Action method.

For example:

 builder.Services.AddSaml(ConfigureSaml);

where the ConfigureSaml method has the following signature:

public static void ConfigureSaml(SamlConfigurations samlConfigurations)

You can access the SamlConfigurations using dependency injection and then update it as required.

For example:

public class SamlController : Controller
{
    private readonly SamlConfigurations _samlConfigurations;

    public SamlController(IOptionsMonitor<SamlConfigurations> samlConfigurations)
    {
        _samlConfigurations = samlConfigurations.CurrentValue;
    }

    public async Task<IActionResult> UpdateConfiguration()
    {
        var samlConfiguration = _samlConfigurations.Configurations.First();

        // Update the SAML configuration.
        samlConfiguration
            .LocalServiceProviderConfiguration
            .AssertionConsumerServiceUrl = "/SAML/AssertionConsumerService";

        return new EmptyResult();
    }
}

Thanks for the response!
I did create a custom resolver using the “AbstractSamlConfigurationResolver” class instead of the interface since I didn’t need all of the required methods.
So basically I need to update the configuration in the database and then update the individual values in the cache manually? There is no option to just replace the whole cached configuration using a new SamlConfiguration object?

By default, SAML configuration isn’t cached. If required, you can introduce caching as shown in the following example.

builder.Services.AddSaml().AddCachedConfigurationResolver<ConfigurationExamples.CustomConfigurationResolver>();

If you’re just extending AbstractSamlConfigurationResolver the SAML configuration isn’t being cached.

Please note that the ISamlConfigurationResolver and the Action method I mentioned previously are two different approaches for supplying SAML configuration.