1 | using FinkiChattery.Identity.Data;
|
---|
2 | using FinkiChattery.Identity.Models;
|
---|
3 | using FinkiChattery.Identity.Services;
|
---|
4 | using Microsoft.AspNetCore.Builder;
|
---|
5 | using Microsoft.AspNetCore.Hosting;
|
---|
6 | using Microsoft.EntityFrameworkCore;
|
---|
7 | using Microsoft.Extensions.Configuration;
|
---|
8 | using Microsoft.Extensions.DependencyInjection;
|
---|
9 | using Microsoft.Extensions.Hosting;
|
---|
10 |
|
---|
11 | namespace FinkiChattery.Identity
|
---|
12 | {
|
---|
13 | public class Startup
|
---|
14 | {
|
---|
15 | public IWebHostEnvironment Environment { get; }
|
---|
16 | public IConfiguration Configuration { get; }
|
---|
17 | public AppSettings AppSettings { get; }
|
---|
18 |
|
---|
19 | public Startup(IWebHostEnvironment environment, IConfiguration configuration)
|
---|
20 | {
|
---|
21 | Environment = environment;
|
---|
22 | Configuration = configuration;
|
---|
23 | AppSettings = new AppSettings(configuration);
|
---|
24 | }
|
---|
25 |
|
---|
26 | public void ConfigureServices(IServiceCollection services)
|
---|
27 | {
|
---|
28 | services.AddControllersWithViews();
|
---|
29 |
|
---|
30 | services.AddDbContextPool<ApplicationDbContext<ApplicationUser>>(options =>
|
---|
31 | options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
|
---|
32 |
|
---|
33 | services.AddIdentityServerAndIdentityProvider(AppSettings);
|
---|
34 | services.RegisterAppServices();
|
---|
35 |
|
---|
36 | services.AddCors(options =>
|
---|
37 | {
|
---|
38 | options.AddPolicy(
|
---|
39 | name: AppSettings.CorsSettings.CorsPolicyName,
|
---|
40 | builder => builder.WithOrigins(AppSettings.CorsSettings.AllowedCorsOrigins).AllowAnyHeader().AllowAnyMethod());
|
---|
41 | });
|
---|
42 | }
|
---|
43 |
|
---|
44 | public void Configure(IApplicationBuilder app)
|
---|
45 | {
|
---|
46 | if (Environment.IsDevelopment())
|
---|
47 | {
|
---|
48 | app.UseDeveloperExceptionPage();
|
---|
49 | app.UseDatabaseErrorPage();
|
---|
50 | }
|
---|
51 |
|
---|
52 | app.UseHttpsRedirection();
|
---|
53 | app.UseStaticFiles();
|
---|
54 |
|
---|
55 | app.UseRouting();
|
---|
56 | app.UseCors(AppSettings.CorsSettings.CorsPolicyName);
|
---|
57 |
|
---|
58 | app.UseAuthentication();
|
---|
59 | app.UseAuthorization();
|
---|
60 | app.UseIdentityServer();
|
---|
61 |
|
---|
62 | app.UseEndpoints(endpoints =>
|
---|
63 | {
|
---|
64 | endpoints.MapDefaultControllerRoute();
|
---|
65 | });
|
---|
66 | }
|
---|
67 | }
|
---|
68 | } |
---|