-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
107 lines (88 loc) · 3.54 KB
/
Copy pathProgram.cs
File metadata and controls
107 lines (88 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using ClubGear.Data;
using ClubGear.Middleware;
using ClubGear.Models;
using ClubGear.Services;
using ClubGear.Services.Abstractions;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddClubGearCoreServices();
builder.Services.Configure<EmailSettings>(builder.Configuration.GetSection(EmailSettings.SectionName));
builder.Services.AddDbContextFactory<ApplicationDbContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddScoped<ApplicationDbContext>(sp =>
sp.GetRequiredService<IDbContextFactory<ApplicationDbContext>>().CreateDbContext());
builder.Services
.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Password.RequireDigit = true;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = true;
options.Password.RequiredLength = 8;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
builder.Services
.AddAuthentication()
.AddOpenIdConnect("oidc.generic", "External IdP", options =>
{
options.SignInScheme = IdentityConstants.ExternalScheme;
// Placeholder so OIDC middleware doesn't reject startup validation.
// OidcOptionsReloader overwrites this at request time from SystemConfigEntry.
options.ClientId = "unconfigured";
options.Authority = "https://unconfigured.invalid";
});
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Account/Login";
options.AccessDeniedPath = "/Account/AccessDenied";
});
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var seeder = scope.ServiceProvider.GetRequiredService<IApplicationSeeder>();
await seeder.SeedAsync();
var pluginLifecycleService = scope.ServiceProvider.GetRequiredService<IPluginLifecycleService>();
await pluginLifecycleService.LoadActivatedAsync();
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseMiddleware<GlobalExceptionMiddleware>();
app.UseRouting();
app.UseAuthentication();
app.UseMiddleware<MaintenanceModeMiddleware>();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapControllerRoute(
name: "member-singular-forward",
pattern: "Member/{action=Index}/{id?}",
defaults: new { controller = "Members" });
app.MapControllerRoute(
name: "self-service-hyphen-forward",
pattern: "Self-Service/{action=Index}/{id?}",
defaults: new { controller = "SelfService" });
app.MapGet("/api/members", context =>
{
context.Response.Redirect("/api/member", permanent: false);
return Task.CompletedTask;
});
app.MapGet("/api/members/{id:int}", (HttpContext context, int id) =>
{
context.Response.Redirect($"/api/member/{id}", permanent: false);
return Task.CompletedTask;
});
app.Run();
// Expose Program for WebApplicationFactory in integration tests.
public partial class Program { }