2025-08-03 12:19:29 +02:00
|
|
|
using PresentPortal.Shared;
|
|
|
|
|
|
2025-07-06 19:15:24 +02:00
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
|
|
// Add service defaults & Aspire client integrations.
|
|
|
|
|
builder.AddServiceDefaults();
|
|
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
|
builder.Services.AddProblemDetails();
|
|
|
|
|
|
|
|
|
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
|
|
|
builder.Services.AddOpenApi();
|
|
|
|
|
|
2025-08-03 12:19:29 +02:00
|
|
|
builder.Services.AddAuthentication()
|
2025-08-03 19:45:34 +02:00
|
|
|
.AddKeycloakJwtBearer(ServiceNames.Keycloak, KeycloakConstants.Realm, options =>
|
2025-08-03 12:19:29 +02:00
|
|
|
{
|
2025-08-03 19:45:34 +02:00
|
|
|
var keycloakHost = builder.Configuration.GetValue<string>($"services:{ServiceNames.Keycloak}:http:0")
|
|
|
|
|
?? throw new InvalidOperationException("Keycloak host is not configured.");
|
|
|
|
|
|
|
|
|
|
options.MetadataAddress = $"{keycloakHost}/realms/{KeycloakConstants.Realm}/.well-known/openid-configuration";
|
|
|
|
|
options.RequireHttpsMetadata = !builder.Environment.IsDevelopment();
|
|
|
|
|
options.Audience = KeycloakConstants.ClientId;
|
|
|
|
|
options.Authority = keycloakHost;
|
2025-08-03 12:19:29 +02:00
|
|
|
});
|
2025-08-03 12:50:14 +02:00
|
|
|
builder.Services.AddAuthorization();
|
2025-08-03 12:19:29 +02:00
|
|
|
|
2025-07-06 19:15:24 +02:00
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
app.UseExceptionHandler();
|
|
|
|
|
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.MapOpenApi();
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 12:19:29 +02:00
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
2025-07-06 19:15:24 +02:00
|
|
|
string[] summaries =
|
|
|
|
|
["Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"];
|
|
|
|
|
|
|
|
|
|
app.MapGet("/weatherforecast", () =>
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
})
|
2025-08-03 12:19:29 +02:00
|
|
|
.WithName("GetWeatherForecast")
|
|
|
|
|
.RequireAuthorization();
|
2025-07-06 19:15:24 +02:00
|
|
|
|
|
|
|
|
app.MapDefaultEndpoints();
|
|
|
|
|
|
|
|
|
|
app.Run();
|
|
|
|
|
|
|
|
|
|
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
|
|
|
|
{
|
|
|
|
|
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
|
|
|
}
|