Example #1
0
        public static void Main(string[] args)
        {
            var factory = new ConfigurationDbContextFactory();
            var context = factory.Create(new DbContextFactoryOptions
            {
                EnvironmentName = "Dev"
            });

            if (!context.Clients.Any())
            {
                foreach (var client in ClientStore.Clients)
                {
                    context.Clients.Add(client.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.IdentityResources.Any())
            {
                foreach (var resource in ResourceProvider.GetIdentityResources())
                {
                    context.IdentityResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }

            if (!context.ApiResources.Any())
            {
                foreach (var resource in ResourceProvider.GetApiResources())
                {
                    context.ApiResources.Add(resource.ToEntity());
                }
                context.SaveChanges();
            }
        }
Example #2
0
        public static void RegisterIdentityServer(this IServiceCollection services, string connectionString)
        {
            var migrationsAssembly = typeof(Program).GetTypeInfo().Assembly.GetName().Name;

            services.AddSingleton <IClientStore, ClientStore>();

            services.AddIdentityServer()
            .AddTemporarySigningCredential()

            .AddInMemoryApiResources(ResourceProvider.GetApiResources())
            .AddInMemoryIdentityResources(ResourceProvider.GetIdentityResources())

            //.AddConfigurationStore(
            //    builder => builder.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly)),
            //    options => options.DefaultSchema = "config")

            .AddOperationalStore(
                builder => builder.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly)),
                options => options.DefaultSchema = "oper")

            .AddAspNetIdentity <ApplicationUser>();
        }