-
Notifications
You must be signed in to change notification settings - Fork 858
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (65 loc) · 2.76 KB
/
Program.cs
File metadata and controls
78 lines (65 loc) · 2.76 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
var builder = WebApplication.CreateBuilder(args);
// Add service defaults & Aspire components.
builder.AddServiceDefaults();
builder.Services.AddAuthentication()
.AddJwtBearer("Bearer", jwtOptions =>
{
// {TENANT ID} is the directory (tenant) ID.
//
// Authority format {AUTHORITY} matches the issurer (`iss`) of the JWT returned by the identity provider.
//
// Authority format {AUTHORITY} for ME-ID tenant type (V1 STS token): https://sts.windows.net/{TENANT ID}/
// Authority format {AUTHORITY} for ME External ID tenant type: https://{DIRECTORY NAME}.ciamlogin.com/{TENANT ID}/v2.0
// Authority format {AUTHORITY} for B2C tenant type: https://login.microsoftonline.com/{TENANT ID}/v2.0
// The format of the authority URL depends on the tenant type and the version of the tokens issued by the identity provider.
// For guidance on adopting V2 tokens and the corresponding authority URL format, see the article.
//
jwtOptions.Authority = "{AUTHORITY}";
//
// The following should match just the path of the Application ID URI configured when adding the "Weather.Get" scope
// under "Expose an API" in the Azure or Entra portal. {CLIENT ID} is the application (client) ID of this
// app's registration in the Azure portal.
//
// Audience format {AUDIENCE} for ME-ID tenant type: api://{CLIENT ID (WEB API APP)}
// Audience format {AUDIENCE} for ME External ID tenant type: {CLIENT ID (WEB API APP)}
// Audience format {AUDIENCE} for B2C tenant type: https://{DIRECTORY NAME}.onmicrosoft.com/{CLIENT ID (WEB API APP)}
//
jwtOptions.Audience = "{AUDIENCE}";
});
builder.Services.AddAuthorization();
// Add OpenApi
builder.Services.AddOpenApi();
var app = builder.Build();
// Configure Swagger UI
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/openapi/v1.json", "v1");
});
}
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.MapDefaultEndpoints();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/weather-forecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
}).RequireAuthorization();
app.Run();
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}