private static IAuthenticationProvider DiscoverProvider(IEnumerable <Type> discoveredProviders,
                                                                ProviderKey providerKey)
        {
            if (discoveredProviders == null)
            {
                throw new ArgumentNullException("discoveredProviders");
            }

            if (providerKey == null)
            {
                throw new ArgumentNullException("providerKey");
            }

            var name = providerKey.Name.ToLowerInvariant();

            var provider = discoveredProviders.SingleOrDefault(x => x.Name.ToLowerInvariant().StartsWith(name));

            if (provider == null)
            {
                var errorMessage =
                    string.Format(
                        "Unable to find the provider [{0}]. Is there a provider dll available? Is there a typo in the provider name? Solution suggestions: Check to make sure the correct dll's are in the 'bin' directory and/or check the name to make sure there's no typo's in there. Example: If you're trying include the GitHub provider, make sure the name is 'github' (any case) and that the ExtraProviders dll exists in the 'bin' directory or make sure you've downloaded the package via NuGet -> install-package SimpleAuthentication.ExtraProviders.",
                        name);
                //TraceSource.TraceError(errorMessage);
                throw new ApplicationException(errorMessage);
            }

            IAuthenticationProvider authenticationProvider = null;

            // Make sure we have a provider with the correct constructor parameters.
            // How? If a person creates their own provider and doesn't offer a constructor
            // that has a sigle ProviderParams, then we're stuffed. So we need to help them.
            if (provider.GetConstructor(new[] { typeof(ProviderParams) }) != null)
            {
                var parameters = new ProviderParams
                {
                    PublicApiKey = providerKey.Key,
                    SecretApiKey = providerKey.Secret,
                    Scopes       = string.IsNullOrEmpty(providerKey.Scope)
                                                  ? null
                                                  : providerKey.Scope.Split(new[] { ',' },
                                                                            StringSplitOptions.RemoveEmptyEntries)
                };
                authenticationProvider = Activator.CreateInstance(provider, parameters) as IAuthenticationProvider;
            }

            if (authenticationProvider == null)
            {
                // We didn't find a proper constructor for the provider class we wish to instantiate.
                var errorMessage =
                    string.Format(
                        "The type {0} doesn't have the proper constructor. It requires a constructor that only accepts 1 argument of type ProviderParams. Eg. public MyProvider(ProviderParams providerParams){{ .. }}.",
                        provider.FullName);
                //TraceSource.TraceError(errorMessage);
                throw new ApplicationException(errorMessage);
            }

            return(authenticationProvider);
        }
        private static IAuthenticationProvider DiscoverProvider(IEnumerable<Type> discoveredProviders,
                                                                ProviderKey providerKey)
        {
            if (discoveredProviders == null)
            {
                throw new ArgumentNullException("discoveredProviders");
            }

            if (providerKey == null)
            {
                throw new ArgumentNullException("providerKey");
            }

            var name = providerKey.Name.ToLowerInvariant();

            var provider = discoveredProviders.SingleOrDefault(x => x.Name.ToLowerInvariant().StartsWith(name));

            if (provider == null)
            {
                var errorMessage =
                    string.Format(
                        "Unable to find the provider [{0}]. Is there a provider dll available? Is there a typo in the provider name? Solution suggestions: Check to make sure the correct dll's are in the 'bin' directory and/or check the name to make sure there's no typo's in there. Example: If you're trying include the GitHub provider, make sure the name is 'github' (any case) and that the ExtraProviders dll exists in the 'bin' directory or make sure you've downloaded the package via NuGet -> install-package SimpleAuthentication.ExtraProviders.",
                        name);
                //TraceSource.TraceError(errorMessage);
                throw new ApplicationException(errorMessage);
            }

            IAuthenticationProvider authenticationProvider = null;

            // Make sure we have a provider with the correct constructor parameters.
            // How? If a person creates their own provider and doesn't offer a constructor
            // that has a sigle ProviderParams, then we're stuffed. So we need to help them.
            if (provider.GetConstructor(new[] {typeof (ProviderParams)}) != null)
            {
                var parameters = new ProviderParams
                                 {
                                     PublicApiKey = providerKey.Key,
                                     SecretApiKey = providerKey.Secret,
                                     Scopes = string.IsNullOrEmpty(providerKey.Scope)
                                                  ? null
                                                  : providerKey.Scope.Split(new[] {','},
                                                                            StringSplitOptions.RemoveEmptyEntries)
                                 };
                authenticationProvider = Activator.CreateInstance(provider, parameters) as IAuthenticationProvider;
            }

            if (authenticationProvider == null)
            {
                // We didn't find a proper constructor for the provider class we wish to instantiate.
                var errorMessage =
                    string.Format(
                        "The type {0} doesn't have the proper constructor. It requires a constructor that only accepts 1 argument of type ProviderParams. Eg. public MyProvider(ProviderParams providerParams){{ .. }}.",
                        provider.FullName);
                //TraceSource.TraceError(errorMessage);
                throw new ApplicationException(errorMessage);
            }

            return authenticationProvider;
        }
 public OpenIdProvider(ProviderParams providerParams) : base("OpenId", "OpenId")
 {
 }