private static void Initialize(IDictionary <string, IAuthenticationProvider> authenticationProviders)
        {
            authenticationProviders.ThrowIfNull("authenticationProviders");

            var discoveredProviders = ReflectionHelpers.FindAllTypesOf <IAuthenticationProvider>();

            if (discoveredProviders == null)
            {
                return;
            }

            // Try configure from custom config section.
            var providerConfig = ProviderConfigHelper.UseConfig();

            if (providerConfig != null)
            {
                SetupCustomConfigProviders(authenticationProviders, discoveredProviders, providerConfig);
            }

            var appSettings = ProviderConfigHelper.UseAppSettings();

            if (appSettings != null && appSettings.Any())
            {
                SetupAppSettingsConfigProviders(authenticationProviders, discoveredProviders, appSettings);
            }
        }
        public void GivenAValidConfigSectionWithAMisingProvider_UsingConfigFor_ThrowsAKeyNotFoundException()
        {
            // Arrange.

            // Act & Assert.
            Assert.Throws <KeyNotFoundException>(() => { ProviderConfigHelper.UseConfig().For("twitter"); });
        }
        public void GivenAInvalidConfigurationSection_UseConfig_ThrowsAConfigurationErrorsException()
        {
            // Arrange.
            const string fileName = "InvalidApp.config";

            // Act & Assert.
            Assert.Throws <ConfigurationErrorsException>(
                () => { ProviderConfigHelper.UseConfig(fileName, "authenticationProviders"); });
        }
        public void GivenAMissingConfigFile_UseConfig_ReturnsNull()
        {
            // Arrange.

            // Act & Assert.
            var result = Assert.Throws <ApplicationException>(() => ProviderConfigHelper.UseConfig("app.config", "blarg"));

            // Assert.
            Assert.NotNull(result);
            Assert.Equal("Missing the config section [blarg] from your .config file", result.Message);
        }
        public void GivenAValidConfigSectionWithAMisingProvider_ProvidersIndexer_ReturnsNull()
        {
            // Arrange.
            var authenticationProviders = ProviderConfigHelper.UseConfig();

            // Act.
            var missingProvider = authenticationProviders.Providers["foo"];

            // Assert.
            Assert.Null(missingProvider);
        }
        public void GivenAValidConfigSectionWithAFacebookKey_UseConfig_ReturnsAFacebookProviderWithACorrectKeyAndSecret()
        {
            // Arrange.

            // Act.
            var authenticationProviders = ProviderConfigHelper.UseConfig();
            var facebookProvider        = authenticationProviders.Providers["facebook"];

            // Assert.
            Assert.Equal("testKey", facebookProvider.Key);
            Assert.Equal("testSecret", facebookProvider.Secret);
        }
Esempio n. 7
0
        private static void Initialize()
        {
            var discoveredProviders = MefHelpers.GetExportedTypes <IAuthenticationProvider>();

            //TODO: Try configure from appSettings

            //Try configure from custom config section
            var providerConfig = ProviderConfigHelper.UseConfig();

            if (providerConfig != null)
            {
                SetupCustomConfigProviders(discoveredProviders, providerConfig);
            }
        }
        public void GivenAValidConfigSectionWithAFacebookKey_UseConfig_ReturnsAFacebookProviderWithACorrectKeyAndSecret()
        {
            // Arrange.

            // Act.
            var authenticationProviders = ProviderConfigHelper.UseConfig();
            var facebookProvider        = authenticationProviders.Providers["facebook"];

            // Assert.
            Assert.Equal(new Uri("http://www.mywebsite.com/authenticationCallback").AbsoluteUri,
                         authenticationProviders.CallbackUri);
            Assert.Equal("providerKey", authenticationProviders.CallbackQuerystringKey);
            Assert.Equal("testKey", facebookProvider.Key);
            Assert.Equal("testSecret", facebookProvider.Secret);
        }
        public void GivenAValidProviderConfigurationWithSomeKeys_NewAuthenticationService_HasSomeProvidersAdded()
        {
            // Arrange.
            var providerConfiguration = ProviderConfigHelper.UseConfig();
            var providerCount         = providerConfiguration.Providers.Count; // 2 hard-coded providers + 3 fakes autoloaded.

            // Act.
            var authenticationService = new AuthenticationService();

            // Assert.
            Assert.NotNull(authenticationService);
            var firstProvider = authenticationService.AuthenticationProviders.SingleOrDefault(x => x.Key == "facebook");

            Assert.NotNull(firstProvider);
            Assert.Equal("Facebook", firstProvider.Value.Name);
        }
        private static void Initialize(IDictionary <string, IAuthenticationProvider> authenticationProviders)
        {
            if (authenticationProviders == null)
            {
                throw new ArgumentNullException("authenticationProviders");
            }

            var discoveredProviders = MefHelpers.GetExportedTypes <IAuthenticationProvider>();

            if (discoveredProviders == null)
            {
                return;
            }

            // Try configure from custom config section.
            var providerConfig = ProviderConfigHelper.UseConfig();

            if (providerConfig != null)
            {
                SetupCustomConfigProviders(authenticationProviders, discoveredProviders, providerConfig);
            }
        }