From 0611a5ca3e7c1f82002323743519fcd497782bde Mon Sep 17 00:00:00 2001 From: "victor.gaborit" Date: Fri, 16 Feb 2024 08:02:17 +0100 Subject: [PATCH] =?UTF-8?q?fix=20security=20pour=20la=20WebAPI=20:=20ajout?= =?UTF-8?q?=20dbContext=20pour=20acceder=20=C3=A0=20la=20base=20ou=20sont?= =?UTF-8?q?=20stocker=20les=20tokens=20et=20ajout=20des=20nuggets=20necess?= =?UTF-8?q?aire=20(Identity.EntityFramework=20et=20EntityFrameworkCore.InM?= =?UTF-8?q?emory.=20Changements=20aport=C3=A9s=20dans=20le=20program.cs=20?= =?UTF-8?q?(utilisation=20du=20context=20avec=20une=20base=20de=20donn?= =?UTF-8?q?=C3=A9es=20en=20m=C3=A9moire=20InMemory=20et=20utilisation=20du?= =?UTF-8?q?=20EndPoint)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_SQLuedo/API/API.csproj | 4 +++- API_SQLuedo/API/Controllers/UserController.cs | 3 ++- API_SQLuedo/API/Program.cs | 7 +++++-- API_SQLuedo/API/WebAPIDbContext.cs | 11 +++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 API_SQLuedo/API/WebAPIDbContext.cs diff --git a/API_SQLuedo/API/API.csproj b/API_SQLuedo/API/API.csproj index 74687fb..cd3cbe6 100644 --- a/API_SQLuedo/API/API.csproj +++ b/API_SQLuedo/API/API.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -8,11 +8,13 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/API_SQLuedo/API/Controllers/UserController.cs b/API_SQLuedo/API/Controllers/UserController.cs index 81f1f59..08ac4c5 100644 --- a/API_SQLuedo/API/Controllers/UserController.cs +++ b/API_SQLuedo/API/Controllers/UserController.cs @@ -52,7 +52,8 @@ namespace API.Controllers [HttpPut] public IActionResult CreateUser(string username, string password, string email, bool isAdmin) { - return Ok(_userDataService.CreateUser(username, password, email, isAdmin)); + // return Ok(_userDataService.CreateUser(username, password, email, isAdmin)); + return CreatedAtAction(nameof(GetUsers), _userDataService.CreateUser(username, password, email, isAdmin)); } } } diff --git a/API_SQLuedo/API/Program.cs b/API_SQLuedo/API/Program.cs index a8e96f7..80f106f 100644 --- a/API_SQLuedo/API/Program.cs +++ b/API_SQLuedo/API/Program.cs @@ -1,3 +1,4 @@ +using API; using DbContextLib; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; @@ -14,9 +15,11 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddScoped(); builder.Services.AddDbContext(); +builder.Services.AddDbContext(options => options.UseInMemoryDatabase("appDb")); +builder.Services.AddIdentityApiEndpoints().AddEntityFrameworkStores(); builder.Services.AddAuthorization(); -builder.Services.AddIdentityApiEndpoints() - .AddEntityFrameworkStores(); +//builder.Services.AddIdentityApiEndpoints() +// .AddEntityFrameworkStores(); builder.Services.AddSwaggerGen(option => { option.SwaggerDoc("v1", new OpenApiInfo { Title = "Demo API", Version = "v1" }); diff --git a/API_SQLuedo/API/WebAPIDbContext.cs b/API_SQLuedo/API/WebAPIDbContext.cs new file mode 100644 index 0000000..afc8996 --- /dev/null +++ b/API_SQLuedo/API/WebAPIDbContext.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + +namespace API +{ + public class WebAPIDbContext : IdentityDbContext + { + public WebAPIDbContext(DbContextOptions options) : base(options) { } + } +}