-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
104 lines (86 loc) · 2.91 KB
/
Copy pathProgram.cs
File metadata and controls
104 lines (86 loc) · 2.91 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
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Microsoft.Identity.Web;
using Microsoft.EntityFrameworkCore;
using inventory_cloud_api.Data;
using inventory_cloud_api.Middleware;
using Serilog;
// FORCE REBUILD 2026-04-26
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog();
builder.Services.AddApplicationInsightsTelemetry(options =>
{
options.ConnectionString = builder.Configuration["ApplicationInsights:ConnectionString"];
});
// Add services
builder.Services.AddControllers();
// DbContext
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnection")
));
// Swagger
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
AuthorizationCode = new OpenApiOAuthFlow
{
AuthorizationUrl = new Uri("https://login.microsoftonline.com/3c21b5f0-0af8-4d57-a2bf-ba61c165cfd7/oauth2/v2.0/authorize"),
TokenUrl = new Uri("https://login.microsoftonline.com/3c21b5f0-0af8-4d57-a2bf-ba61c165cfd7/oauth2/v2.0/token"),
Scopes = new Dictionary<string, string>
{
{ "api://b72268e4-116d-4f04-b4a1-cd6a95567bd7/access_as_user", "Access API" }
}
}
}
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "oauth2"
}
},
new[] { "api://b72268e4-116d-4f04-b4a1-cd6a95567bd7/access_as_user" }
}
});
});
// Auth
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"));
builder.Services.AddAuthorization();
// Health checks
builder.Services.AddHealthChecks()
.AddSqlServer(
builder.Configuration
.GetConnectionString("DefaultConnection")!
);
var app = builder.Build();
// Middleware
app.UseSwagger();
app.UseMiddleware<ExceptionMiddleware>();
app.UseSwaggerUI(options =>
{
options.OAuthClientId("f561c4ef-a529-4adb-84b2-a3bb96a61e86");
options.OAuthUsePkce();
options.OAuthScopes("api://b72268e4-116d-4f04-b4a1-cd6a95567bd7/access_as_user");
});
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.MapHealthChecks("/health").AllowAnonymous();
app.MapGet("/", () => "RUNNING OK").AllowAnonymous();
app.Run();