示例#1
0
        private async Task InitializeDatabase(IApplicationBuilder app)
        {
            var clientUrls = new Dictionary <string, string>
            {
                { "AngularClient", this.Configuration.GetValue <string>("AngularClient") },
            };

            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>().Database.Migrate();

                serviceScope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>().Database.Migrate();

                var context = serviceScope.ServiceProvider.GetRequiredService <ConfigurationDbContext>();

                context.Database.Migrate();

                if (!await context.Clients.AnyAsync())
                {
                    context.Clients.AddRange(IdentityServiceConfiguration.GetClients(clientUrls).Select(client => client.ToEntity()));
                }

                if (!await context.IdentityResources.AnyAsync())
                {
                    context.IdentityResources.AddRange(IdentityServiceConfiguration.GetResources().Select(resource => resource.ToEntity()));
                }

                if (!await context.ApiResources.AnyAsync())
                {
                    context.ApiResources.AddRange(IdentityServiceConfiguration.GetApis().Select(api => api.ToEntity()));
                }

                await context.SaveChangesAsync();
            }
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "DavidMorales.WebHost v1"));

                app.UseDeveloperExceptionPage();

                app.UseCors(builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader();
                });
            }
            else
            {
                //app.UseExceptionHandler("/Error");
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "DavidMorales.WebHost v1"));
                app.UseDeveloperExceptionPage();

                app.UseCors(builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader();
                });
            }

            RestServiceConfiguration.Configure(app);
            DatabaseConfiguration.Configure(app);
            IdentityServiceConfiguration.Configure(app);
            AuthenticationConfiguration.Configure(app);
            AppAuthorizationConfiguration.Configure(app);
        }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Api Rest Configuration
            RestServiceConfiguration.ConfigureServices(services);

            // Database configuration
            DatabaseConfiguration.ConfigureServices(services, Configuration);

            // Identity service configuration
            IdentityServiceConfiguration.ConfigureServices(services, Configuration);

            // Authorization
            AppAuthorizationConfiguration.ConfigureAuthorization(services);

            // Authentication configuration
            AuthenticationConfiguration.ConfigureServices(services, Configuration);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "DavidMorales.WebHost", Version = "v1"
                });
            });



            // Identity
            services.AddTransient <AppIdentity>();
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            // Log
            services.AddLogging();

            // Cors
            services.AddCors();
        }
示例#4
0
        public async Task SeedAsync(ConfigurationDbContext context, IConfiguration configuration)
        {
            //callbacks urls from config:
            var clientUrls = new Dictionary <string, string>
            {
            };

            if (!await context.Clients.AnyAsync())
            {
                context.Clients.AddRange(IdentityServiceConfiguration.GetClients(clientUrls).Select(client => client.ToEntity()));
            }

            if (!await context.IdentityResources.AnyAsync())
            {
                context.IdentityResources.AddRange(IdentityServiceConfiguration.GetResources().Select(resource => resource.ToEntity()));
            }

            if (!await context.ApiResources.AnyAsync())
            {
                context.ApiResources.AddRange(IdentityServiceConfiguration.GetApis().Select(api => api.ToEntity()));
            }

            await context.SaveChangesAsync();
        }