diff --git a/ApiEfCoreLibrary/Endpoints/Author/CreateAuthorEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Author/CreateAuthorEndpoint.cs index f8ce235..8cb928d 100644 --- a/ApiEfCoreLibrary/Endpoints/Author/CreateAuthorEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Author/CreateAuthorEndpoint.cs @@ -9,8 +9,7 @@ public class CreateAuthorEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("admin"); - AllowAnonymous(); + Roles("admin"); } public override async Task HandleAsync(DeleteAuthorRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Author/GetAllAuthorsEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Author/GetAllAuthorsEndpoint.cs index e3ae93c..8bc0526 100644 --- a/ApiEfCoreLibrary/Endpoints/Author/GetAllAuthorsEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Author/GetAllAuthorsEndpoint.cs @@ -10,8 +10,7 @@ public class GetAllAuthorsEndpoint(LibraryDbContext database) : EndpointWithoutR public override void Configure() { Get("/authors"); - // Roles("viewer", "admin", "librarian"); - AllowAnonymous(); + Roles("viewer", "admin", "librarian"); } public override async Task HandleAsync(CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Author/GetAuthorEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Author/GetAuthorEndpoint.cs index 672ed12..4cbff00 100644 --- a/ApiEfCoreLibrary/Endpoints/Author/GetAuthorEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Author/GetAuthorEndpoint.cs @@ -16,8 +16,7 @@ public class GetAuthorEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("viewer", "admin", "librarian"); - AllowAnonymous(); + Roles("viewer", "admin", "librarian"); } public override async Task HandleAsync(GetAuthorRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Author/UpdateAuthorEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Author/UpdateAuthorEndpoint.cs index 58a3c94..75d8e4b 100644 --- a/ApiEfCoreLibrary/Endpoints/Author/UpdateAuthorEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Author/UpdateAuthorEndpoint.cs @@ -11,8 +11,7 @@ public class UpdateAuthorEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("admin"); - AllowAnonymous(); + Roles("admin"); } public override async Task HandleAsync(UpdateAuthorDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Book/CreateBookEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Book/CreateBookEndpoint.cs index e3b7509..dc7c68a 100644 --- a/ApiEfCoreLibrary/Endpoints/Book/CreateBookEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Book/CreateBookEndpoint.cs @@ -10,8 +10,7 @@ public class CreateBookEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("admin"); - AllowAnonymous(); + Roles("admin"); } public override async Task HandleAsync(DeleteBookRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Book/GetAllBooksEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Book/GetAllBooksEndpoint.cs index 2503643..40139b3 100644 --- a/ApiEfCoreLibrary/Endpoints/Book/GetAllBooksEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Book/GetAllBooksEndpoint.cs @@ -9,8 +9,7 @@ public class GetAllBooksEndpoint(LibraryDbContext database) : EndpointWithoutReq public override void Configure() { Get("/books"); - // Roles("viewer", "admin", "librarian"); - AllowAnonymous(); + Roles("viewer", "admin", "librarian"); } public override async Task HandleAsync(CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Book/GetBookEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Book/GetBookEndpoint.cs index 0e382e0..1e89b4f 100644 --- a/ApiEfCoreLibrary/Endpoints/Book/GetBookEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Book/GetBookEndpoint.cs @@ -14,8 +14,7 @@ public class GetBookEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("viewer", "admin", "librarian"); - AllowAnonymous(); + Roles("viewer", "admin", "librarian"); } public override async Task HandleAsync(GetBookRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Book/UpdateBookEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Book/UpdateBookEndpoint.cs index a784084..582dfb5 100644 --- a/ApiEfCoreLibrary/Endpoints/Book/UpdateBookEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Book/UpdateBookEndpoint.cs @@ -10,8 +10,7 @@ public class UpdateBookEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("admin"); - AllowAnonymous(); + Roles("admin"); } public override async Task HandleAsync(UpdateBookDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Loan/CreateLoanEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/CreateLoanEndpoint.cs index 9c33ee4..a01c41d 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/CreateLoanEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/CreateLoanEndpoint.cs @@ -10,8 +10,7 @@ public class CreateLoanEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("admin"); - AllowAnonymous(); + Roles("admin"); } public override async Task HandleAsync(DeleteLoanRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Loan/GetAllLoansEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/GetAllLoansEndpoint.cs index baf3aa8..2b681a3 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/GetAllLoansEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/GetAllLoansEndpoint.cs @@ -9,8 +9,7 @@ public class GetAllLoanEndpoint(LibraryDbContext database) : EndpointWithoutRequ public override void Configure() { Get("/loans"); - // Roles("viewer", "admin", "librarian"); - AllowAnonymous(); + Roles("viewer", "admin", "librarian"); } public override async Task HandleAsync(CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Loan/GetLoanEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/GetLoanEndpoint.cs index f485a97..5c0f567 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/GetLoanEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/GetLoanEndpoint.cs @@ -14,8 +14,7 @@ public class GetLoanEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("viewer", "admin", "librarian"); - AllowAnonymous(); + Roles("viewer", "admin", "librarian"); } public override async Task HandleAsync(GetLoanRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Loan/PatchLoanEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/PatchLoanEndpoint.cs index 722d975..4db0ad2 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/PatchLoanEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/PatchLoanEndpoint.cs @@ -10,8 +10,7 @@ public class PatchLoanEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("admin", "librarian"); - AllowAnonymous(); + Roles("admin", "librarian"); } public override async Task HandleAsync(PatchLoanDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Loan/UpdateLoanEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/UpdateLoanEndpoint.cs index 9fa6664..a33ac39 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/UpdateLoanEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/UpdateLoanEndpoint.cs @@ -10,8 +10,7 @@ public class UpdateLoanEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("admin", "librarian"); - AllowAnonymous(); + Roles("admin", "librarian"); } public override async Task HandleAsync(UpdateLoanDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Refresh/RefreshTokenEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Refresh/RefreshTokenEndpoint.cs index 4b7bfb6..a80aa69 100644 --- a/ApiEfCoreLibrary/Endpoints/Refresh/RefreshTokenEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Refresh/RefreshTokenEndpoint.cs @@ -1,5 +1,4 @@ using System.IdentityModel.Tokens.Jwt; -using ApiEfCoreLibrary.DTO.Login.Response; using ApiEfCoreLibrary.DTO.Refresh.Request; using ApiEfCoreLibrary.DTO.Refresh.Response; using FastEndpoints; diff --git a/ApiEfCoreLibrary/Endpoints/User/CreateUserEndpoint.cs b/ApiEfCoreLibrary/Endpoints/User/CreateUserEndpoint.cs index 8e55030..773df79 100644 --- a/ApiEfCoreLibrary/Endpoints/User/CreateUserEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/User/CreateUserEndpoint.cs @@ -9,8 +9,7 @@ public class CreateUserEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("admin"); - AllowAnonymous(); + Roles("admin"); } public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/User/GetAllUsersEndpoint.cs b/ApiEfCoreLibrary/Endpoints/User/GetAllUsersEndpoint.cs index 0645e16..ab71252 100644 --- a/ApiEfCoreLibrary/Endpoints/User/GetAllUsersEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/User/GetAllUsersEndpoint.cs @@ -10,8 +10,7 @@ public class GetAllUsersEndpoint(LibraryDbContext database) : EndpointWithoutReq public override void Configure() { Get("/users"); - // Roles("viewer", "admin", "librarian"); - AllowAnonymous(); + Roles("viewer", "admin", "librarian"); } public override async Task HandleAsync(CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/User/GetUserEndpoint.cs b/ApiEfCoreLibrary/Endpoints/User/GetUserEndpoint.cs index 8bf67db..1fe7983 100644 --- a/ApiEfCoreLibrary/Endpoints/User/GetUserEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/User/GetUserEndpoint.cs @@ -16,8 +16,7 @@ public class GetUserEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("viewer", "admin", "librarian"); - AllowAnonymous(); + Roles("viewer", "admin", "librarian"); } public override async Task HandleAsync(GetUserRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/User/UpdateUserEndpoint.cs b/ApiEfCoreLibrary/Endpoints/User/UpdateUserEndpoint.cs index 91dc4a8..9a59fe5 100644 --- a/ApiEfCoreLibrary/Endpoints/User/UpdateUserEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/User/UpdateUserEndpoint.cs @@ -10,8 +10,7 @@ public class UpdateUserEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - // Roles("admin"); - AllowAnonymous(); + Roles("admin"); } public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Program.cs b/ApiEfCoreLibrary/Program.cs index 55547e1..ec25732 100644 --- a/ApiEfCoreLibrary/Program.cs +++ b/ApiEfCoreLibrary/Program.cs @@ -7,8 +7,8 @@ WebApplicationBuilder builder = WebApplication.CreateBuilder(args); // On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet builder.Services - //.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong") - //.AddAuthorization() + .AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong") + .AddAuthorization() .AddFastEndpoints() .AddCors(options => { @@ -29,8 +29,8 @@ builder.Services.AddDbContext(); // On construit l'application en lui donnant vie WebApplication app = builder.Build(); -app//.UseAuthentication() - //.UseAuthorization() +app.UseAuthentication() + .UseAuthorization() .UseFastEndpoints(options => { options.Endpoints.ShortNames = true; @@ -38,7 +38,7 @@ app//.UseAuthentication() }) .UseSwaggerGen(); -app.UseHttpsRedirection(); +// app.UseHttpsRedirection(); app.UseCors();