diff --git a/.idea/.idea.ApiEfCoreLibrary/.idea/dataSources.xml b/.idea/.idea.ApiEfCoreLibrary/.idea/dataSources.xml index 1f84899..8cbdbd4 100644 --- a/.idea/.idea.ApiEfCoreLibrary/.idea/dataSources.xml +++ b/.idea/.idea.ApiEfCoreLibrary/.idea/dataSources.xml @@ -20,5 +20,12 @@ Server=romaric-thibault.fr,1433 $ProjectFileDir$ + + sqlserver.jb + true + com.jetbrains.jdbc.sqlserver.SqlServerDriver + Server=romaric-thibault.fr,1433 + $ProjectFileDir$ + \ No newline at end of file diff --git a/.idea/.idea.ApiEfCoreLibrary/.idea/db-forest-config.xml b/.idea/.idea.ApiEfCoreLibrary/.idea/db-forest-config.xml index df7cea4..8fedea3 100644 --- a/.idea/.idea.ApiEfCoreLibrary/.idea/db-forest-config.xml +++ b/.idea/.idea.ApiEfCoreLibrary/.idea/db-forest-config.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/ApiEfCoreLibrary/Endpoints/Author/CreateAuthorEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Author/CreateAuthorEndpoint.cs index 8cb928d..f8ce235 100644 --- a/ApiEfCoreLibrary/Endpoints/Author/CreateAuthorEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Author/CreateAuthorEndpoint.cs @@ -9,7 +9,8 @@ public class CreateAuthorEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("admin"); + // Roles("admin"); + AllowAnonymous(); } public override async Task HandleAsync(DeleteAuthorRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Author/GetAllAuthorsEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Author/GetAllAuthorsEndpoint.cs index 8bc0526..e3ae93c 100644 --- a/ApiEfCoreLibrary/Endpoints/Author/GetAllAuthorsEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Author/GetAllAuthorsEndpoint.cs @@ -10,7 +10,8 @@ public class GetAllAuthorsEndpoint(LibraryDbContext database) : EndpointWithoutR public override void Configure() { Get("/authors"); - Roles("viewer", "admin", "librarian"); + // Roles("viewer", "admin", "librarian"); + AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Author/GetAuthorEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Author/GetAuthorEndpoint.cs index 4cbff00..672ed12 100644 --- a/ApiEfCoreLibrary/Endpoints/Author/GetAuthorEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Author/GetAuthorEndpoint.cs @@ -16,7 +16,8 @@ public class GetAuthorEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("viewer", "admin", "librarian"); + // Roles("viewer", "admin", "librarian"); + AllowAnonymous(); } public override async Task HandleAsync(GetAuthorRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Author/UpdateAuthorEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Author/UpdateAuthorEndpoint.cs index 75d8e4b..58a3c94 100644 --- a/ApiEfCoreLibrary/Endpoints/Author/UpdateAuthorEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Author/UpdateAuthorEndpoint.cs @@ -11,7 +11,8 @@ public class UpdateAuthorEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("admin"); + // Roles("admin"); + AllowAnonymous(); } public override async Task HandleAsync(UpdateAuthorDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Book/CreateBookEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Book/CreateBookEndpoint.cs index f5265a0..e3b7509 100644 --- a/ApiEfCoreLibrary/Endpoints/Book/CreateBookEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Book/CreateBookEndpoint.cs @@ -9,8 +9,9 @@ public class CreateBookEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("admin"); + // Roles("admin"); + AllowAnonymous(); } public override async Task HandleAsync(DeleteBookRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Book/GetAllBooksEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Book/GetAllBooksEndpoint.cs index 436ddac..2503643 100644 --- a/ApiEfCoreLibrary/Endpoints/Book/GetAllBooksEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Book/GetAllBooksEndpoint.cs @@ -9,7 +9,9 @@ public class GetAllBooksEndpoint(LibraryDbContext database) : EndpointWithoutReq public override void Configure() { Get("/books"); - Roles("viewer", "admin", "librarian"); } + // Roles("viewer", "admin", "librarian"); + AllowAnonymous(); + } public override async Task HandleAsync(CancellationToken ct) { diff --git a/ApiEfCoreLibrary/Endpoints/Book/GetBookEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Book/GetBookEndpoint.cs index 8c0cf35..0e382e0 100644 --- a/ApiEfCoreLibrary/Endpoints/Book/GetBookEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Book/GetBookEndpoint.cs @@ -14,7 +14,9 @@ public class GetBookEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("viewer", "admin", "librarian"); } + // Roles("viewer", "admin", "librarian"); + AllowAnonymous(); + } public override async Task HandleAsync(GetBookRequest req, CancellationToken ct) { diff --git a/ApiEfCoreLibrary/Endpoints/Book/UpdateBookEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Book/UpdateBookEndpoint.cs index 582dfb5..a784084 100644 --- a/ApiEfCoreLibrary/Endpoints/Book/UpdateBookEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Book/UpdateBookEndpoint.cs @@ -10,7 +10,8 @@ public class UpdateBookEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("admin"); + // Roles("admin"); + AllowAnonymous(); } public override async Task HandleAsync(UpdateBookDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Loan/CreateLoanEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/CreateLoanEndpoint.cs index a01c41d..9c33ee4 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/CreateLoanEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/CreateLoanEndpoint.cs @@ -10,7 +10,8 @@ public class CreateLoanEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("admin"); + // Roles("admin"); + AllowAnonymous(); } public override async Task HandleAsync(DeleteLoanRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Loan/GetAllLoansEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/GetAllLoansEndpoint.cs index 4927e4c..baf3aa8 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/GetAllLoansEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/GetAllLoansEndpoint.cs @@ -9,7 +9,9 @@ public class GetAllLoanEndpoint(LibraryDbContext database) : EndpointWithoutRequ public override void Configure() { Get("/loans"); - Roles("viewer", "admin", "librarian"); } + // Roles("viewer", "admin", "librarian"); + AllowAnonymous(); + } public override async Task HandleAsync(CancellationToken ct) { diff --git a/ApiEfCoreLibrary/Endpoints/Loan/GetLoanEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/GetLoanEndpoint.cs index dd2cabd..f485a97 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/GetLoanEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/GetLoanEndpoint.cs @@ -14,7 +14,9 @@ public class GetLoanEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("viewer", "admin", "librarian"); } + // Roles("viewer", "admin", "librarian"); + AllowAnonymous(); + } public override async Task HandleAsync(GetLoanRequest req, CancellationToken ct) { diff --git a/ApiEfCoreLibrary/Endpoints/Loan/PatchLoanEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/PatchLoanEndpoint.cs index 6729d86..b53e4fa 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/PatchLoanEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/PatchLoanEndpoint.cs @@ -10,7 +10,8 @@ public class PatchLoanEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("admin", "librarian"); + // Roles("admin", "librarian"); + AllowAnonymous(); } public override async Task HandleAsync(PatchLoanDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Loan/UpdateLoanEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Loan/UpdateLoanEndpoint.cs index a33ac39..9fa6664 100644 --- a/ApiEfCoreLibrary/Endpoints/Loan/UpdateLoanEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Loan/UpdateLoanEndpoint.cs @@ -10,7 +10,8 @@ public class UpdateLoanEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("admin", "librarian"); + // Roles("admin", "librarian"); + AllowAnonymous(); } public override async Task HandleAsync(UpdateLoanDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Login/DeleteLoginEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Login/DeleteLoginEndpoint.cs index f4fdff0..29147a1 100644 --- a/ApiEfCoreLibrary/Endpoints/Login/DeleteLoginEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Login/DeleteLoginEndpoint.cs @@ -15,6 +15,7 @@ public class DeleteLoginEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(DeleteLoginRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Login/GetAllLoginEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Login/GetAllLoginEndpoint.cs index b937097..e6a7a6b 100644 --- a/ApiEfCoreLibrary/Endpoints/Login/GetAllLoginEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Login/GetAllLoginEndpoint.cs @@ -10,6 +10,7 @@ public class GetAllLoginEndpoint(LibraryDbContext database) : EndpointWithoutReq public override void Configure() { Get("/logins"); + AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Login/GetLoginEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Login/GetLoginEndpoint.cs index 1ebe155..18242a0 100644 --- a/ApiEfCoreLibrary/Endpoints/Login/GetLoginEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Login/GetLoginEndpoint.cs @@ -14,6 +14,7 @@ public class GetLoginEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(GetLoginRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/Login/UpdateLoginEndpoint.cs b/ApiEfCoreLibrary/Endpoints/Login/UpdateLoginEndpoint.cs index 543aa15..18760ee 100644 --- a/ApiEfCoreLibrary/Endpoints/Login/UpdateLoginEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/Login/UpdateLoginEndpoint.cs @@ -12,6 +12,7 @@ public class UpdateLoginEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(UpdateLoginDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/User/CreateUserEndpoint.cs b/ApiEfCoreLibrary/Endpoints/User/CreateUserEndpoint.cs index 773df79..8e55030 100644 --- a/ApiEfCoreLibrary/Endpoints/User/CreateUserEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/User/CreateUserEndpoint.cs @@ -9,7 +9,8 @@ public class CreateUserEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("admin"); + // Roles("admin"); + AllowAnonymous(); } public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Endpoints/User/GetAllUsersEndpoint.cs b/ApiEfCoreLibrary/Endpoints/User/GetAllUsersEndpoint.cs index 6367819..0645e16 100644 --- a/ApiEfCoreLibrary/Endpoints/User/GetAllUsersEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/User/GetAllUsersEndpoint.cs @@ -10,7 +10,9 @@ public class GetAllUsersEndpoint(LibraryDbContext database) : EndpointWithoutReq public override void Configure() { Get("/users"); - Roles("viewer", "admin", "librarian"); } + // Roles("viewer", "admin", "librarian"); + AllowAnonymous(); + } public override async Task HandleAsync(CancellationToken ct) { diff --git a/ApiEfCoreLibrary/Endpoints/User/GetUserEndpoint.cs b/ApiEfCoreLibrary/Endpoints/User/GetUserEndpoint.cs index 0f32843..8bf67db 100644 --- a/ApiEfCoreLibrary/Endpoints/User/GetUserEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/User/GetUserEndpoint.cs @@ -16,7 +16,9 @@ public class GetUserEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("viewer", "admin", "librarian"); } + // Roles("viewer", "admin", "librarian"); + AllowAnonymous(); + } public override async Task HandleAsync(GetUserRequest req, CancellationToken ct) { diff --git a/ApiEfCoreLibrary/Endpoints/User/UpdateUserEndpoint.cs b/ApiEfCoreLibrary/Endpoints/User/UpdateUserEndpoint.cs index 9a59fe5..91dc4a8 100644 --- a/ApiEfCoreLibrary/Endpoints/User/UpdateUserEndpoint.cs +++ b/ApiEfCoreLibrary/Endpoints/User/UpdateUserEndpoint.cs @@ -10,7 +10,8 @@ public class UpdateUserEndpoint(LibraryDbContext database) : Endpoint new {x.Id}); - Roles("admin"); + // Roles("admin"); + AllowAnonymous(); } public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct) diff --git a/ApiEfCoreLibrary/Program.cs b/ApiEfCoreLibrary/Program.cs index e8c5a1d..c662c40 100644 --- a/ApiEfCoreLibrary/Program.cs +++ b/ApiEfCoreLibrary/Program.cs @@ -7,12 +7,22 @@ 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 => + { + options.AddPolicy("AllowAll", policy => + { + policy.AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader(); + }); + }) .SwaggerDocument(options => { - options.ShortSchemaNames = true; + options.ShortSchemaNames = true; + }); // On ajoute ici la configuration de la base de données @@ -20,8 +30,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; @@ -31,4 +41,6 @@ app.UseAuthentication() app.UseHttpsRedirection(); +app.UseCors("AllowAll"); + app.Run(); \ No newline at end of file