-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
53 lines (40 loc) · 1.72 KB
/
Program.cs
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
using AK.OAuthSamples.OpenIdDict.Server.Configuration;
using AK.OAuthSamples.OpenIdDict.Server.Routes;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.IdentityModel.Logging;
var builder = WebApplication.CreateBuilder(args);
var isLocal = builder.Environment.IsDevelopment() || builder.Environment.IsEnvironment("Local");
if (isLocal)
builder.Configuration.AddUserSecrets<AppSettings>();
// Resolving the settings
var settings = builder.Services.AddAndConfigureAppSettings(builder.Configuration);
// Configuring the IoC/DI container
builder.Services.AddAndConfigureSwagger(settings)
.AddCors()
.AddAndConfigureAuthorisation(settings);
// Building the middleware pipeline
var app = builder.Build();
if (isLocal)
app.UseDeveloperExceptionPage();
app .UseHttpsRedirection();
if (isLocal)
app.ConfigureSwagger(settings); // Swagger is available in DEV only
app .UseCors (policyBuilder =>
policyBuilder .AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader())
.Use(async (context, next) =>
{ // Here's a convenient debugging hack
if (isLocal)
Console.WriteLine(context.Request.GetDisplayUrl());
await next.Invoke();
})
.UseAuthentication()
.UseAuthorization(); // Note 1: 'Authorization' is required only if the project has secured end-points
// Note 2: the Authorization middleware must be registered AFTER the Authentication middleware
app.MapTestRoutes();
if (isLocal)
// Enable showing extra debug information in the console. Must be added right before `Run()`, see https://stackoverflow.com/a/73956586/968003
// Includes potential PII (personally identifiable information) in exceptions in order to be in compliance with GDPR
IdentityModelEventSource.ShowPII = true;
app.Run();