On startup of my ASP.NET Core web app (which uses IdentityServer 4), in the ConfigureServices method I register external identity providers that I want to enable SSO for via OAuth2 and OIDC.
services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = authenticationScheme;
options.DefaultScheme = authenticationScheme;
})
.AddOAuthSsoIdentityProviders(ssoIdentityProviders);
internal static AuthenticationBuilder AddOAuthSsoIdentityProviders(this AuthenticationBuilder authenticationBuilder, List<IdentityProvider> ssoIdentityProviders)
{
var oAuthSsoIdentityProviders = ssoIdentityProviders
.Where(idp => idp.SsoFlowType == SsoFlowType.Oidc || idp.SsoFlowType == SsoFlowType.OAuth2)
.ToList();
foreach (var ssoIdentityProvider in oAuthSsoIdentityProviders)
{
switch (ssoIdentityProvider.SsoFlowType)
{
case SsoFlowType.Oidc:
authenticationBuilder.AddOpenIdConnect(ssoIdentityProvider.SsoCode, options => SetOidcOptions(ssoIdentityProvider, options));
break;
case SsoFlowType.OAuth2:
authenticationBuilder.AddOAuth(ssoIdentityProvider.SsoCode, options => SetOAuth2Options(ssoIdentityProvider, options));
break;
}
}
return authenticationBuilder;
}
This works great, however our site admins need the ability to update the configurations of these external identity providers. For example, they may want to add a new partner or change the authentication request url of an existing one. Currently we have to recycle our ASP.NET Core website's app pool to have it re-run the startup code and update the settings. This obviously isn't a good solution, so I'm wondering how we can add or modify these configurations after startup?