MAJ avec l'ajout de la gestion d'authentification

This commit is contained in:
2025-12-08 12:26:46 +01:00
parent f60d3443ca
commit 78e5a4e960
51 changed files with 25 additions and 80 deletions

View File

@@ -1,20 +1,27 @@
using FastEndpoints;
using FastEndpoints.Security;
using FastEndpoints.Swagger;
using Microsoft.EntityFrameworkCore;
using PyroFetes;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Services
builder.Services
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
.AddAuthentication();
builder.Services.AddAuthorization();
builder.Services.AddCors(options =>
options.AddDefaultPolicy(policyBuilder =>
policyBuilder
.WithOrigins("http://localhost:4200") // mettre le port Angular exact
.WithMethods("GET", "POST", "PUT", "PATCH", "DELETE")
.AllowAnyHeader()
policyBuilder.WithOrigins("http://localhost:4200")
.WithMethods("GET", "POST", "PUT", "PATCH", "DELETE")
.AllowAnyHeader()
.AllowCredentials()
)
);
builder.Services.AddFastEndpoints().SwaggerDocument(options =>
builder.Services.AddFastEndpoints().SwaggerDocument(options =>
{
options.ShortSchemaNames = true;
});
@@ -23,20 +30,19 @@ builder.Services.AddDbContext<PyroFetesDbContext>();
WebApplication app = builder.Build();
// Middleware
app.UseHttpsRedirection();
// CORS doit être avant les endpoints
app.UseCors();
// FastEndpoints et Swagger
app.UseAuthentication();
app.UseAuthorization();
app.UseFastEndpoints(options =>
{
options.Endpoints.RoutePrefix = "API";
options.Endpoints.RoutePrefix = "API";
options.Endpoints.ShortNames = true;
}).UseSwaggerGen();
// app.UseAuthorization();
// app.UseAuthentication();
app.Run();