Esempio n. 1
0
        /// <summary>
        /// Add the OPENID API.
        /// </summary>
        /// <param name="serviceCollection"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IServiceCollection AddOpenIdApi(this IServiceCollection serviceCollection, IdentityServerOptions options)
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            ConfigureSimpleIdentityServer(
                serviceCollection,
                options);
            return(serviceCollection);
        }
Esempio n. 2
0
        public static IServiceCollection AddHostIdentityServer(this IServiceCollection serviceCollection, IdentityServerOptions options)
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            serviceCollection
            .AddSingleton(options.Scim)
            .AddTransient <IRedirectInstructionParser, RedirectInstructionParser>()
            .AddTransient <IActionResultParser, ActionResultParser>()
            .AddSingleton <IHttpContextAccessor, HttpContextAccessor>()
            .AddSingleton <IActionContextAccessor, ActionContextAccessor>()
            .AddDataProtection();
            return(serviceCollection);
        }
 public static void UseOpenIdApi(this IApplicationBuilder app, IdentityServerOptions options, ILoggerFactory loggerFactory)
 {
     UseOpenIdApi(app, options);
 }
        public static IServiceCollection AddHostIdentityServer(this IServiceCollection serviceCollection, IdentityServerOptions options)
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.AuthenticateResourceOwner == null)
            {
                serviceCollection.AddTransient <IAuthenticateResourceOwnerService, DefaultAuthenticateResourceOwerService>();
            }
            else
            {
                serviceCollection.AddTransient(typeof(IAuthenticateResourceOwnerService), options.AuthenticateResourceOwner);
            }

            if (options.ConfigurationService == null)
            {
                serviceCollection.AddTransient <IConfigurationService, DefaultConfigurationService>();
            }
            else
            {
                serviceCollection.AddTransient(typeof(IConfigurationService), options.ConfigurationService);
            }

            if (options.PasswordService == null)
            {
                serviceCollection.AddTransient <IPasswordService, DefaultPasswordService>();
            }
            else
            {
                serviceCollection.AddTransient(typeof(IPasswordService), options.PasswordService);
            }

            var twoFactorServiceStore = new TwoFactorServiceStore();

            if (options.TwoFactorAuthentications != null)
            {
                foreach (var twoFactorAuthentication in options.TwoFactorAuthentications)
                {
                    if (twoFactorAuthentication.TwoFactorAuthType != Core.Common.Models.TwoFactorAuthentications.NONE && twoFactorAuthentication.TwoFactorAuthenticationService != null)
                    {
                        twoFactorServiceStore.Add(twoFactorAuthentication.TwoFactorAuthenticationService);
                    }
                }
            }

            serviceCollection.AddSingleton <ITwoFactorServiceStore>(twoFactorServiceStore);
            serviceCollection
            .AddSingleton(options.Authenticate)
            .AddSingleton(options.Scim)
            .AddTransient <IRedirectInstructionParser, RedirectInstructionParser>()
            .AddTransient <IActionResultParser, ActionResultParser>()
            .AddSingleton <IHttpContextAccessor, HttpContextAccessor>()
            .AddSingleton <IActionContextAccessor, ActionContextAccessor>()
            .AddDataProtection();
            return(serviceCollection);
        }
        public static IServiceCollection AddSimpleIdentityServer(
            this IServiceCollection serviceCollection,
            IdentityServerOptions options)
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.Logging == null)
            {
                throw new ArgumentNullException(nameof(options.Logging));
            }

            if (options.DataSource == null)
            {
                throw new ArgumentNullException(nameof(options.DataSource));
            }

            switch (options.DataSource.OpenIdDataSourceType)
            {
            case DataSourceTypes.SqlServer:
                serviceCollection.AddSimpleIdentityServerSqlServer(options.DataSource.OpenIdConnectionString);
                break;

            case DataSourceTypes.SqlLite:
                serviceCollection.AddSimpleIdentityServerSqlLite(options.DataSource.OpenIdConnectionString);
                break;

            case DataSourceTypes.Postgre:
                serviceCollection.AddSimpleIdentityServerPostgre(options.DataSource.OpenIdConnectionString);
                break;

            case DataSourceTypes.InMemory:
                serviceCollection.AddSimpleIdentityServerInMemory();
                break;

            default:
                throw new ArgumentException($"the data source '{options.DataSource.OpenIdDataSourceType}' type is not supported");
            }

            switch (options.DataSource.EvtStoreDataSourceType)
            {
            case DataSourceTypes.SqlServer:
                serviceCollection.AddEventStoreSqlServer(options.DataSource.EvtStoreConnectionString);
                break;

            case DataSourceTypes.SqlLite:
                serviceCollection.AddEventStoreSqlLite(options.DataSource.EvtStoreConnectionString);
                break;

            case DataSourceTypes.Postgre:
                serviceCollection.AddEventStorePostgre(options.DataSource.EvtStoreConnectionString);
                break;

            case DataSourceTypes.InMemory:
                serviceCollection.AddEventStoreInMemory();
                break;
            }

            ConfigureSimpleIdentityServer(
                serviceCollection,
                options);
            return(serviceCollection);
        }