48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using Backend.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddDbContext<AppDbContext>(options =>
|
|
options.UseNpgsql(builder.Configuration.GetConnectionString("Postgres")));
|
|
|
|
// MARKER: CORS SERVICES
|
|
|
|
builder.Services
|
|
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
.AddJwtBearer(options =>
|
|
{
|
|
options.MetadataAddress = builder.Configuration["Supabase:MetadataAddress"]
|
|
?? throw new InvalidOperationException("Supabase:MetadataAddress not configured");
|
|
options.RequireHttpsMetadata = true;
|
|
options.MapInboundClaims = false;
|
|
options.TokenValidationParameters = new TokenValidationParameters
|
|
{
|
|
ValidateIssuer = true,
|
|
ValidIssuer = builder.Configuration["Supabase:Issuer"],
|
|
ValidateAudience = true,
|
|
ValidAudience = builder.Configuration["Supabase:Audience"],
|
|
ValidateIssuerSigningKey = true,
|
|
ValidateLifetime = true,
|
|
ClockSkew = TimeSpan.FromSeconds(30),
|
|
NameClaimType = "sub"
|
|
};
|
|
});
|
|
|
|
builder.Services.AddAuthorization();
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
var app = builder.Build();
|
|
|
|
// MARKER: CORS MIDDLEWARE
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|