Exemplo n.º 1
0
        private void RemoveScheme(AuthenticationScheme scheme)
        {
            schemeProvider.RemoveScheme(scheme.Name);
            optionsCache.TryRemove(scheme.Name);

            logger.LogInformation("Removed external authentication {ExternalLogin} for tenant {Tenant}.", scheme.Name, resolvedTenant.TenantName);
        }
        public IActionResult Configure(ConfigurationModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //save settings
            _identityServerExternalAuthSettings.ClientId             = model.ClientId;
            _identityServerExternalAuthSettings.ClientSecret         = model.ClientSecret;
            _identityServerExternalAuthSettings.Authority            = model.Authority;
            _identityServerExternalAuthSettings.RequireHttpsMetadata = model.RequireHttpsMetadata;
            _identityServerExternalAuthSettings.ResponseType         = model.ResponseType;
            _identityServerExternalAuthSettings.SaveTokens           = model.SaveTokens;
            _identityServerExternalAuthSettings.Scopes        = model.Scopes;
            _identityServerExternalAuthSettings.NameClaimType = model.NameClaimType;
            _identityServerExternalAuthSettings.RoleClaimType = model.RoleClaimType;
            _settingService.SaveSetting(_identityServerExternalAuthSettings);

            //clear Facebook authentication options cache
            _optionsCache.TryRemove(OpenIdConnectDefaults.AuthenticationScheme);

            _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            return(Configure());
        }
Exemplo n.º 3
0
 public HttpClientFactoryOptionsConfigure(IOptionsMonitor <HttpClientOptions> optionsSnapshot,
                                          IOptionsMonitorCache <HttpClientFactoryOptions> cache, IServiceProvider serviceProvider)
 {
     _optionsSnapshot = optionsSnapshot;
     _serviceProvider = serviceProvider;
     optionsSnapshot.OnChange((options, name) => { cache.TryRemove(name); });
 }
Exemplo n.º 4
0
        public async Task InvokeAsync(HttpContext context,
                                      IAuthenticationSchemeProvider schemeProvider,
                                      IOptionsMonitorCache <FakeAuthenticationSchemeOptions> optionsCache)
        {
            var fakeOptions = context.RequestServices
                              .GetRequiredService <IOptionsSnapshot <FakeAuthenticationOptions> >().Value;

            foreach (var fakeScheme in fakeOptions.Schemes)
            {
                if (await schemeProvider.GetSchemeAsync(fakeScheme.SchemeName) != null)
                {
                    schemeProvider.RemoveScheme(fakeScheme.SchemeName);
                    optionsCache.TryRemove(fakeScheme.SchemeName);
                    var scheme = new AuthenticationScheme(fakeScheme.SchemeName,
                                                          fakeScheme.SchemeName,
                                                          typeof(FakeAuthenticationHandler));
                    schemeProvider.AddScheme(scheme);
                    var fakeSchemeOptions = new FakeAuthenticationSchemeOptions();
                    foreach (var claim in fakeScheme.Claims)
                    {
                        fakeSchemeOptions.Claims.Add(claim);
                    }
                    optionsCache.TryAdd(fakeScheme.SchemeName, fakeSchemeOptions);
                }
            }
            await _next(context);
        }
Exemplo n.º 5
0
        private void InvokeChanged(string?name)
        {
            name ??= Options.DefaultName;
            _cache.TryRemove(name);
            TOptions options = Get(name);

            _onChange?.Invoke(options, name);
        }
Exemplo n.º 6
0
        private void InvokeChanged(string name)
        {
            name = name ?? Microsoft.Extensions.Options.Options.DefaultName;
            _cache.TryRemove(name);
            var options = Get(name);

            _onChange?.Invoke(options, name);
        }
Exemplo n.º 7
0
        public void Configure(WebOptimizerOptions options)
        {
            _config.GetReloadToken().RegisterChangeCallback(_ =>
            {
                _options.TryRemove(Options.DefaultName);
            }, null);

            ConfigurationBinder.Bind(_config.GetSection("WebOptimizer"), options);
        }
Exemplo n.º 8
0
 /// <summary/>
 public ChangeOnConfigureNamedOptions(string optionName, string dependentOptionsName, IOptionsMonitorCache <TOptions> cache)
 {
     this.clearCache = name =>
     {
         if (name == dependentOptionsName)
         {
             cache.TryRemove(optionName);
         }
     };
 }
Exemplo n.º 9
0
 private void InvokeChanged(string? name)
 {
     name = name ?? Options.DefaultName;
     _cache.TryRemove(name);
     TOptions options = Get(name);
     if (_onChange != null)
     {
         _onChange.Invoke(options, name);
     }
 }
Exemplo n.º 10
0
        private void CreateHttpClientFactoryOptions(UpstreamRequestSenderSettings settings)
        {
            httpFactoryOptionsMonitorCache.TryRemove(settings.HttpClientName);

            var options = new HttpClientFactoryOptions();

            options.HttpMessageHandlerBuilderActions.Add(builder => ConfigureHttpMessageHandlerBuilder(builder, settings));

            httpFactoryOptionsMonitorCache.TryAdd(settings.HttpClientName, options);
        }
        public TOptions CreateOptions(string schemeName)
        {
            ArgumentValidation.ValidateString(nameof(schemeName), schemeName);

            var options = _optionsFactory.Create(schemeName);

            _optionsMonitorCache.TryRemove(schemeName);
            _optionsMonitorCache.TryAdd(schemeName, options);

            PostConfigure(schemeName, options);

            return(options);
        }
Exemplo n.º 12
0
        public void Configure(WebOptimizerOptions options)
        {
            _config.GetReloadToken().RegisterChangeCallback(_ =>
            {
                _options.TryRemove(Options.DefaultName);
            }, null);

            _config.GetSection("WebOptimizer").Bind(options);

            options.EnableCaching           = options.EnableCaching ?? !_hostingEnvironment.IsDevelopment();
            options.EnableDiskCache         = options.EnableDiskCache ?? !_hostingEnvironment.IsDevelopment();
            options.EnableMemoryCache       = options.EnableMemoryCache ?? true;
            options.EnableTagHelperBundling = options.EnableTagHelperBundling ?? true;
            options.CacheDirectory          = string.IsNullOrWhiteSpace(options.CacheDirectory)
                ? Path.Combine(_hostingEnvironment.ContentRootPath, "obj", "WebOptimizerCache")
                : options.CacheDirectory;
        }
        public IActionResult Configure(ConfigurationModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //save settings
            _oAuth2AuthenticationSettings.ClientId            = model.ClientId;
            _oAuth2AuthenticationSettings.ClientSecret        = model.ClientSecret;
            _oAuth2AuthenticationSettings.Authority           = model.Authority;
            _oAuth2AuthenticationSettings.Scopes              = model.Scopes;
            _oAuth2AuthenticationSettings.AdministratorsRoles = model.AdministratorsRoles;
            _settingService.SaveSetting(_oAuth2AuthenticationSettings);

            _optionsCache.TryRemove(OAuth2AuthenticationDefaults.AuthenticationScheme);

            //SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            return(Configure());
        }
Exemplo n.º 14
0
        public IActionResult Configure(ConfigurationModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageExternalAuthenticationMethods))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //save settings
            _facebookExternalAuthSettings.ClientKeyIdentifier = model.ClientId;
            _facebookExternalAuthSettings.ClientSecret        = model.ClientSecret;
            _settingService.SaveSetting(_facebookExternalAuthSettings);

            //clear Facebook authentication options cache
            _optionsCache.TryRemove(FacebookDefaults.AuthenticationScheme);

            _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            return(Configure());
        }
Exemplo n.º 15
0
 private void ClearWsFederationOptionsCache()
 {
     _wsFederationOptionsCache.TryRemove(GetCacheKey("WsFederation"));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Try to remove an options instance.
 /// </summary>
 /// <param name="name">The name of the options instance.</param>
 /// <returns>Whether anything was removed.</returns>
 public bool TryRemove(string name)
 {
     return(_parent.TryRemove(name));
 }
Exemplo n.º 17
0
 private void ClearFacebookCache()
 {
     _facebookOptionsCache.TryRemove(GetCacheKey("Facebook"));
 }
Exemplo n.º 18
0
 private void ClearGoogleCache()
 {
     _googleOptionsCache.TryRemove(GetCacheKey("Google"));
 }
Exemplo n.º 19
0
 private void ClearTwitterCache()
 {
     _twitterOptionsCache.TryRemove(GetCacheKey("Twitter"));
 }
Exemplo n.º 20
0
 private void ClearMicrosoftAccountOptionsCache()
 {
     _microsoftOptionsCache.TryRemove(GetCacheKey("Microsoft"));
 }
Exemplo n.º 21
0
        public async Task AddOrUpdate(string tenantId)
        {
            var scheme          = $"{tenantId}-scheme";
            var oidOptions      = new OpenIdConnectOptions();
            var samlOptions     = new Saml2pAuthenticationOptions();
            var saml2SpOptions  = new SpOptions();
            var saml2IdpOptions = new IdpOptions();
            var tenant          = _repo.GetAllTenants().FirstOrDefault(x => x.TenantId.Equals(tenantId));
            var oidcProtocol    = tenant.Protocol.Equals("oidc");

            if (tenant != null && oidcProtocol)
            {
                var oidConfig = _repo.GetOpenIdConfig(tenantId);
                oidOptions = BuildOidOptions(oidConfig);
            }
            else
            {
                var samlConfig = _repo.GetSamlConfig(tenantId);
                saml2SpOptions = new SpOptions()
                {
                    EntityId                   = "https://localhost:44374/saml",
                    SigningCertificate         = new X509Certificate2("testclient.pfx", "test"),
                    MetadataPath               = "/saml/metadata",
                    SignAuthenticationRequests = true
                };
                saml2IdpOptions = new IdpOptions()
                {
                    EntityId             = samlConfig.IdpEntityId,
                    SingleSignOnEndpoint = new SamlEndpoint(samlConfig.SingleSignOnEndpoint, SamlBindingTypes.HttpPost),
                    SingleLogoutEndpoint = new SamlEndpoint(samlConfig.SingleLogoutEndpoint, SamlBindingTypes.HttpPost),
                    SigningCertificate   = new X509Certificate2(samlConfig.IdpSigningCertificate), //file name
                };

                samlOptions = BuildSamlOptions(samlConfig, saml2SpOptions, saml2IdpOptions);
            }

            if (await _schemeProvider.GetSchemeAsync(scheme) == null)

            {
                _schemeProvider.AddScheme(new AuthenticationScheme(scheme, scheme, oidcProtocol ? typeof(OpenIdConnectHandler) : typeof(Saml2pAuthenticationHandler)));
            }
            else
            {
                if (oidcProtocol)
                {
                    _openIdOptions.TryRemove(scheme);
                }
                else
                {
                    _saml2pOptions.TryRemove(scheme);
                }
            }
            if (oidcProtocol)
            {
                _oidPostConfOptions.PostConfigure(scheme, oidOptions);
                _openIdOptions.TryAdd(scheme, oidOptions);
            }
            else
            {
                _saml2pOptions.TryAdd(scheme, samlOptions);
            }
        }
 private void OnChange(object state)
 {
     _prevOptions = (BundlingOptions)state;
     _optionsCache.TryRemove(Options.DefaultName);
 }
Exemplo n.º 23
0
        public async Task <IActionResult> Configure(ConfigurationModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageExternalAuthenticationMethods))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(await Configure());
            }

            //load settings for a chosen store scope
            var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync();

            var _externalAuthSettings = await _settingService.LoadSettingAsync <ExternalAuthSettings>(storeScope);

            #region Facebook

            //save settings facebook
            _externalAuthSettings.FacebookClientId     = model.FacebookClientId;
            _externalAuthSettings.FacebookClientSecret = model.FacebookClientSecret;
            _externalAuthSettings.FacebookEnable       = model.FacebookBtnIsDisplay;
            await _settingService.SaveSettingAsync(_externalAuthSettings);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.FacebookEnable, model.FacebookBtnIsDisplay_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.FacebookClientSecret, model.FacebookClientSecret_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.FacebookClientId, model.FacebookClientId_OverrideForStore, storeScope, false);

            #endregion Facebook

            #region twitter

            //save settings
            _externalAuthSettings.TwitterClientId     = model.TwitterClientId;
            _externalAuthSettings.TwitterClientSecret = model.TwitterClientSecret;
            _externalAuthSettings.TwitterEnable       = model.TwitterBtnIsDisplay;
            await _settingService.SaveSettingAsync(_externalAuthSettings);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.TwitterEnable, model.TwitterBtnIsDisplay_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.TwitterClientId, model.TwitterClientId_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.TwitterClientSecret, model.TwitterClientSecret_OverrideForStore, storeScope, false);

            #endregion twitter

            #region Google

            //save settings
            _externalAuthSettings.GoogleClientId     = model.GoogleClientId;
            _externalAuthSettings.GoogleClientSecret = model.GoogleClientSecret;
            _externalAuthSettings.GoogleEnable       = model.GmailBtnIsDisplay;
            await _settingService.SaveSettingAsync(_externalAuthSettings);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.GoogleEnable, model.GmailBtnIsDisplay_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.GoogleClientId, model.GoogleClientId_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.GoogleClientSecret, model.GoogleClientSecret_OverrideForStore, storeScope, false);

            #endregion Google

            #region Miscrosoft

            //save settings
            _externalAuthSettings.MicrosoftClientId     = model.MicrosoftClientId;
            _externalAuthSettings.MicrosoftClientSecret = model.MicrosoftClientSecret;
            _externalAuthSettings.MicrosoftEnable       = model.MicrosoftBtnIsDisplay;
            await _settingService.SaveSettingAsync(_externalAuthSettings);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.MicrosoftEnable, model.MicrosoftBtnIsDisplay_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.MicrosoftClientId, model.MicrosoftClientId_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.MicrosoftClientSecret, model.MicrosoftClientSecret_OverrideForStore, storeScope, false);

            #endregion Miscrosoft

            #region LinkedIn

            //save settings
            _externalAuthSettings.LinkedInClientId     = model.LinkedInClientId;
            _externalAuthSettings.LinkedInClientSecret = model.LinkedInClientSecret;
            _externalAuthSettings.LinkedInEnable       = model.LinkedInBtnIsDisplay;
            await _settingService.SaveSettingAsync(_externalAuthSettings);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.LinkedInEnable, model.LinkedInBtnIsDisplay_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.LinkedInClientId, model.LinkedInClientId_OverrideForStore, storeScope, false);

            await _settingService.SaveSettingOverridablePerStoreAsync(_externalAuthSettings, x => x.LinkedInClientSecret, model.LinkedInClientSecret_OverrideForStore, storeScope, false);

            #endregion LinkedIn

            _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved"));

            //clear Facebook authentication options cache
            _optionsFacebookCache.TryRemove(FacebookDefaults.AuthenticationScheme);
            _optionsGoogleCache.TryRemove(GoogleDefaults.AuthenticationScheme);
            _optionsMicrosoftCache.TryRemove(MicrosoftAccountDefaults.AuthenticationScheme);
            _optionsTwitterCache.TryRemove(TwitterDefaults.AuthenticationScheme);

            return(await Configure());
        }
        public async Task <IActionResult> Add([FromBody] SchemeData schemeData)
        {
            var schemeName = string.Format("{0}_{1}", schemeData.Domain, schemeData.Scheme);

            if (schemeData.Scheme == "Google")
            {
                IOptionsMonitorCache <GoogleOptions> oAuthOptionsCache = serviceProvider.GetRequiredService <IOptionsMonitorCache <GoogleOptions> >();
                OAuthPostConfigureOptions <GoogleOptions, GoogleHandler> oAuthPostConfigureOptions = serviceProvider.GetRequiredService <OAuthPostConfigureOptions <GoogleOptions, GoogleHandler> >();

                if (await schemeProvider.GetSchemeAsync(schemeName) == null)
                {
                    schemeProvider.AddScheme(new AuthenticationScheme(schemeName, schemeData.Scheme, typeof(GoogleHandler)));
                }
                else
                {
                    oAuthOptionsCache.TryRemove(schemeName);
                }
                var options = new GoogleOptions
                {
                    ClientId     = "xxxxxxx",
                    ClientSecret = "xxxxxxxxxxxx"
                };
                oAuthPostConfigureOptions.PostConfigure(schemeName, options);
                oAuthOptionsCache.TryAdd(schemeName, options);
            }
            else if (schemeData.Scheme == "Auth0")
            {
                IOptionsMonitorCache <Saml2Options> oAuthOptionsCache         = serviceProvider.GetRequiredService <IOptionsMonitorCache <Saml2Options> >();
                PostConfigureSaml2Options           oAuthPostConfigureOptions = serviceProvider.GetRequiredService <PostConfigureSaml2Options>();

                if (await schemeProvider.GetSchemeAsync(schemeName) == null)
                {
                    schemeProvider.AddScheme(new AuthenticationScheme(schemeName, schemeData.Scheme, typeof(Saml2Handler)));
                }
                else
                {
                    oAuthOptionsCache.TryRemove(schemeName);
                }
                //urn:ccidentity.auth0.com
                var options = new Saml2Options();
                options.SPOptions.EntityId   = new EntityId("https://localhost:44332/auth0");
                options.SPOptions.ModulePath = "/Saml2Auth0";
                options.SPOptions.MinIncomingSigningAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";

                var idp = new IdentityProvider(new EntityId("urn:ccidentity.auth0.com"), options.SPOptions)
                {
                    MetadataLocation = "https://xxxxxxxx/samlp/metadata/7HmaqIPuC32Pc95e0clSqN3n3ogzkTkP",
                    LoadMetadata     = true,
                    AllowUnsolicitedAuthnResponse = true,
                    Binding = Saml2BindingType.HttpRedirect,
                    SingleSignOnServiceUrl = new Uri("https://xxxxxxx/samlp/7HmaqIPuC32Pc95e0clSqN3n3ogzkTkP"),
                };

                idp.SigningKeys.AddConfiguredKey(new X509Certificate2(Convert.FromBase64String("MIIDAzCCAeugAwIBAgIJLNhPpvvzUXRnMA0GCSqGSIb3DQEBCwUAMB8xHTAbBgNVBAMTFGNjaWRlbnRpdHkuYXV0aDAuY29tMB4XDTIwMDQwMTEwMTEzMVoXDTMzMTIwOTEwMTEzMVowHzEdMBsGA1UEAxMUY2NpZGVudGl0eS5hdXRoMC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDXOaxVEhjYW+eT3YduAnRMGrJGcriVU1e3n3RXB6SPt4QsmXsOcdLItaqKthSKeRTkOtXvRANvve1YrEUeMwWzv9gsKoQrwM5fDKwG+chEJNxEZEtMmGfqasb++taLTduNPphSm1xs0RNHeeFXdJHt4QWVsCMJfH2RRUlRHaqj4niew/uzJOZNiWLnXp+03tiy5uwOyxyOhpMOX9QZqpSwHHzZ8OoLIIxynuSiWipZoeCoxrZKM3kHW9YlwLVZvcqAZhWTbut6sC+Y+1O1Sfh1tr6XxWzcP5GaMMV2xQPgPYYKjYMiMeFSe4E5P3R4QxmEoeOpAhWzHQbiyzMYLIO1AgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFFldi8Vcq5IwPROX5ssxqm+uuQaZMA4GA1UdDwEB/wQEAwIChDANBgkqhkiG9w0BAQsFAAOCAQEA1DWRiUaTCHqPUQRzOOnuiSib2dga2Qd1v39dqaaHrLe345c0eo1yn0cE50xtSTlx++WeIQ3RbXCMm70Za3+AfQhTOisqiHS0Nb+ZrxkHFzl0JNgY4AHQFbYsM3QwZQLBjfhL3KyYoTiQRifn/L9N1F/ZJN5PatoybwwJAbo4V0Y1g9pMSWXhbUKJCBP3Eq/8LPx2erAs3RkheYtz+beviOiXNeNYvUNxmPNy+vpp/zvFG5q20vtK7a3EBbOh1pputoctmAfnGoyjZ06JDAa006iJiGwXlwNonBFClLwbds4H3fc9hv4RsCWlVVdcO+l5FL17nhMRYZUn74lGHOCMZg==")));

                options.IdentityProviders.Add(idp);

                oAuthPostConfigureOptions.PostConfigure(schemeName, options);
                oAuthOptionsCache.TryAdd(schemeName, options);
            }
            else if (schemeData.Scheme == "Saml2")
            {
                IOptionsMonitorCache <Saml2Options> oAuthOptionsCache         = serviceProvider.GetRequiredService <IOptionsMonitorCache <Saml2Options> >();
                PostConfigureSaml2Options           oAuthPostConfigureOptions = serviceProvider.GetRequiredService <PostConfigureSaml2Options>();

                if (await schemeProvider.GetSchemeAsync(schemeName) == null)
                {
                    schemeProvider.AddScheme(new AuthenticationScheme(schemeName, schemeData.Scheme, typeof(Saml2Handler)));
                }
                else
                {
                    oAuthOptionsCache.TryRemove(schemeName);
                }

                var options = new Saml2Options();
                options.SPOptions.EntityId = new EntityId("https://localhost:44332/Saml2");
                options.SPOptions.MinIncomingSigningAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";

                var idp = new IdentityProvider(new EntityId("https://xxxxxxxxxxxx/adfs/services/trust"), options.SPOptions)
                {
                    //MetadataLocation = "https://xxxxxxxxxxxx/FederationMetadata/2007-06/FederationMetadata.xml",
                    //LoadMetadata = true,
                    AllowUnsolicitedAuthnResponse = true,
                    Binding = Saml2BindingType.HttpRedirect,
                    SingleSignOnServiceUrl = new Uri("https://xxxxxxxxx/adfs/ls/"),
                };

                idp.SigningKeys.AddConfiguredKey(new X509Certificate2(Convert.FromBase64String("MIIC5jCCAc6gAwIBAgIQOMQMbu2YTpFIO7bLoDczgjANBgkqhkiG9w0BAQsFADAvMS0wKwYDVQQDEyRBREZTIFNpZ25pbmcgLSBEZXYtMTAxLkJhbmtPZlpvbmUubGswHhcNMjAwMzMwMTQyOTQ5WhcNMjEwMzMwMTQyOTQ5WjAvMS0wKwYDVQQDEyRBREZTIFNpZ25pbmcgLSBEZXYtMTAxLkJhbmtPZlpvbmUubGswggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC0sv1rrY0QcVy8kCYz48dTE0qWlwg7J67kNDuO4um37DKnmSK43QTKMkN4Oe / q6 + a8YV2XW7aHqVzirdyeCWDqWf0fuef0jBhysylwdZI8P8PHAhX632jkQ9dXKqKC9kVEsV + LMzMB98xv3ue + rAjQMctrvdapTgvRTOyu5SEHV7zKN / AXDgqM1AT9ae4prRhg7F37Y6h4DVjCdOZgV7LpmgkkFxFnmk0G5il9yfFnLs2Xw3dQxh8HPj9XCgeNT3GGnui + d69BnESsWDjUBUuBGB / +6WQixC4SnKzbssVTy3W4h3aSSsGljAAJfh5YUafzqCjG7Z6xE16LNBieKjbVAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAH / a2bttVBkWzk4Q7K8qjgC / GQboK1NJewEPdi + 8GKG5RD + hWWz /qmXKT0u6ZklzmNrsxj + jPxIOzlv7Aaa5CbGUHHRoG7mgWnvV7y0Qys3OfRUpIzOK0HzDhe / LlyHyX3TpKDH / b1YQJiE6yHgwEdkO4ZBQsOHDNm9pvWH2YJQqMFbWPA4ZeUASeUO0h + BdR4Fog / MYu86lensZwZUKbq / 1 + M5xao3LZfQh5oyEBpH0roRJOazjMSHV + U4sLdvkvXx6in4BLwt1HiMAm0oA6c + vSW5GANAJBXPupfP6Njt0lpGGC3bLgWOlU65NTPwIZhvAjs / gV / pBa + jVMVxDP0g = ")));

                options.IdentityProviders.Add(idp);

                oAuthPostConfigureOptions.PostConfigure(schemeName, options);
                oAuthOptionsCache.TryAdd(schemeName, options);
            }
            else
            {
                IOptionsMonitorCache <FacebookOptions> oAuthOptionsCache = serviceProvider.GetRequiredService <IOptionsMonitorCache <FacebookOptions> >();
                OAuthPostConfigureOptions <FacebookOptions, FacebookHandler> oAuthPostConfigureOptions = serviceProvider.GetRequiredService <OAuthPostConfigureOptions <FacebookOptions, FacebookHandler> >();

                if (await schemeProvider.GetSchemeAsync(schemeName) == null)
                {
                    schemeProvider.AddScheme(new AuthenticationScheme(schemeName, schemeData.Scheme, typeof(FacebookHandler)));
                }
                else
                {
                    oAuthOptionsCache.TryRemove(schemeName);
                }
                var options = new FacebookOptions
                {
                    AppId     = "xxxxxxxxxxxx",
                    AppSecret = "xxxxxxxxxxxxxxxxx"
                };

                oAuthOptionsCache.TryAdd(schemeName, options);
                oAuthPostConfigureOptions.PostConfigure(schemeName, options);
                oAuthOptionsCache.TryAdd(schemeName, options);
            }

            return(Redirect("/"));
        }
Exemplo n.º 25
0
 public void UnRegister()
 {
     _schemeProvider.RemoveScheme(SchemeName);
     _optionsCache.TryRemove(SchemeName);
 }
Exemplo n.º 26
0
 public IActionResult Remove(string scheme)
 {
     _schemeProvider.RemoveScheme(scheme);
     _optionsCache.TryRemove(scheme);
     return(Redirect("/"));
 }
Exemplo n.º 27
0
 private void ClearOpenIdConnectOptionsCache()
 {
     _openIdConnectOptionsCache.TryRemove(GetCacheKey("OpenIdConnect"));
 }