public static IServiceCollection AddSsoServices(this IServiceCollection services, GlobalSettings globalSettings) { // SAML SP Configuration var samlEnvironment = new SamlEnvironment { SpSigningCertificate = CoreHelpers.GetIdentityServerCertificate(globalSettings), }; services.AddSingleton(s => samlEnvironment); services.AddSingleton <Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider, DynamicAuthenticationSchemeProvider>(); // Oidc services.AddSingleton <Microsoft.Extensions.Options.IPostConfigureOptions <OpenIdConnectOptions>, OpenIdConnectPostConfigureOptions>(); services.AddSingleton <Microsoft.Extensions.Options.IOptionsMonitorCache <OpenIdConnectOptions>, ExtendedOptionsMonitorCache <OpenIdConnectOptions> >(); // Saml2 services.AddSingleton <Microsoft.Extensions.Options.IPostConfigureOptions <Saml2Options>, PostConfigureSaml2Options>(); services.AddSingleton <Microsoft.Extensions.Options.IOptionsMonitorCache <Saml2Options>, ExtendedOptionsMonitorCache <Saml2Options> >(); return(services); }
public DynamicAuthenticationSchemeProvider( IOptions <AuthenticationOptions> options, IPostConfigureOptions <OpenIdConnectOptions> oidcPostConfigureOptions, IOptionsMonitorCache <OpenIdConnectOptions> oidcOptionsMonitorCache, IPostConfigureOptions <Saml2Options> saml2PostConfigureOptions, IOptionsMonitorCache <Saml2Options> saml2OptionsMonitorCache, ISsoConfigRepository ssoConfigRepository, ILogger <DynamicAuthenticationSchemeProvider> logger, GlobalSettings globalSettings, SamlEnvironment samlEnvironment, IHttpContextAccessor httpContextAccessor) : base(options) { _oidcPostConfigureOptions = oidcPostConfigureOptions; _extendedOidcOptionsMonitorCache = oidcOptionsMonitorCache as IExtendedOptionsMonitorCache <OpenIdConnectOptions>; if (_extendedOidcOptionsMonitorCache == null) { throw new ArgumentNullException("_extendedOidcOptionsMonitorCache could not be resolved."); } _saml2PostConfigureOptions = saml2PostConfigureOptions; _extendedSaml2OptionsMonitorCache = saml2OptionsMonitorCache as IExtendedOptionsMonitorCache <Saml2Options>; if (_extendedSaml2OptionsMonitorCache == null) { throw new ArgumentNullException("_extendedSaml2OptionsMonitorCache could not be resolved."); } _ssoConfigRepository = ssoConfigRepository; _logger = logger; _globalSettings = globalSettings; _schemeCacheLifetime = TimeSpan.FromSeconds(_globalSettings.Sso?.CacheLifetimeInSeconds ?? 30); _samlEnvironment = samlEnvironment; _cachedSchemes = new Dictionary <string, DynamicAuthenticationScheme>(); _cachedHandlerSchemes = new Dictionary <string, DynamicAuthenticationScheme>(); _semaphore = new SemaphoreSlim(1); _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); }