/// <summary> /// Default constructor. /// </summary> /// <param name="providerConfiguration">Configuration of the current authentication provider.</param> /// <param name="deviceHiveConfiguration">DeviceHiveConfiguration object.</param> /// <param name="dataContext">DataContext object.</param> public AuthenticationProvider(AuthenticationProviderConfiguration providerConfiguration, DeviceHiveConfiguration deviceHiveConfiguration, DataContext dataContext) { if (providerConfiguration == null) throw new ArgumentNullException("providerConfiguration"); if (deviceHiveConfiguration == null) throw new ArgumentNullException("deviceHiveConfiguration"); if (dataContext == null) throw new ArgumentNullException("dataContext"); ProviderConfiguration = providerConfiguration; DeviceHiveConfiguration = deviceHiveConfiguration; DataContext = dataContext; }
/// <summary> /// Default constructor. /// </summary> /// <param name="providerConfiguration">Configuration of the current authentication provider.</param> /// <param name="deviceHiveConfiguration">DeviceHiveConfiguration object.</param> /// <param name="dataContext">DataContext object.</param> public AuthenticationProvider(AuthenticationProviderConfiguration providerConfiguration, DeviceHiveConfiguration deviceHiveConfiguration, DataContext dataContext) { if (providerConfiguration == null) { throw new ArgumentNullException("providerConfiguration"); } if (deviceHiveConfiguration == null) { throw new ArgumentNullException("deviceHiveConfiguration"); } if (dataContext == null) { throw new ArgumentNullException("dataContext"); } ProviderConfiguration = providerConfiguration; DeviceHiveConfiguration = deviceHiveConfiguration; DataContext = dataContext; }
/// <summary> /// Initializes the authentication manager. /// Reads the configiration and instantiates enabled authentication providers. /// </summary> /// <param name="kernel">NInject kernel.</param> public void Initialize(IKernel kernel) { var providers = _configuration.Authentication.Providers.Cast<AuthenticationProviderConfigurationElement>().ToArray(); foreach (var provider in providers.Where(p => p.Enabled)) { var providerType = Type.GetType(provider.Type, false); if (providerType == null) { throw new Exception(string.Format("Could not load type: '{0}'!" + " Please put the all referenced assemblies into the DeviceHive executable folder.", provider.Type)); } if (!typeof(AuthenticationProvider).IsAssignableFrom(providerType)) { throw new Exception(string.Format("The type '{0}' must implement AuthenticationProvider" + " in order to be registered as authentication provider!", providerType)); } var providerConfiguration = new AuthenticationProviderConfiguration(provider.ClientId, provider.ClientSecret, provider.Argument); var providerInstance = (AuthenticationProvider)kernel.Get(providerType, new ConstructorArgument("providerConfiguration", providerConfiguration)); var providerInfo = new AuthenticationProviderInfo(provider.Name, providerInstance, providerConfiguration); _providers.Add(provider.Name, providerInfo); } }
/// <summary> /// Initializes the authentication manager. /// Reads the configiration and instantiates enabled authentication providers. /// </summary> /// <param name="kernel">NInject kernel.</param> public void Initialize(IKernel kernel) { var providers = _configuration.Authentication.Providers.Cast <AuthenticationProviderConfigurationElement>().ToArray(); foreach (var provider in providers.Where(p => p.Enabled)) { var providerType = Type.GetType(provider.Type, false); if (providerType == null) { throw new Exception(string.Format("Could not load type: '{0}'!" + " Please put the all referenced assemblies into the DeviceHive executable folder.", provider.Type)); } if (!typeof(AuthenticationProvider).IsAssignableFrom(providerType)) { throw new Exception(string.Format("The type '{0}' must implement AuthenticationProvider" + " in order to be registered as authentication provider!", providerType)); } var providerConfiguration = new AuthenticationProviderConfiguration(provider.ClientId, provider.ClientSecret, provider.Argument); var providerInstance = (AuthenticationProvider)kernel.Get(providerType, new ConstructorArgument("providerConfiguration", providerConfiguration)); var providerInfo = new AuthenticationProviderInfo(provider.Name, providerInstance, providerConfiguration); _providers.Add(provider.Name, providerInfo); } }