forked from sanchezvem/PyroFetes
MAJ avec l'ajout de la gestion d'authentification
This commit is contained in:
@@ -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();
|
||||
Reference in New Issue
Block a user