diff --git a/Back/skydiveLogs-api.Business/skydiveLogs-api.Business.csproj b/Back/skydiveLogs-api.Business/skydiveLogs-api.Business.csproj index 4e1543c..01de365 100644 --- a/Back/skydiveLogs-api.Business/skydiveLogs-api.Business.csproj +++ b/Back/skydiveLogs-api.Business/skydiveLogs-api.Business.csproj @@ -1,7 +1,7 @@ - + - netcoreapp2.2 + netcoreapp3.1 skydiveLogs_api.Business diff --git a/Back/skydiveLogs-api.Data/skydiveLogs-api.Data.csproj b/Back/skydiveLogs-api.Data/skydiveLogs-api.Data.csproj index e67d3fb..7dd6ff9 100644 --- a/Back/skydiveLogs-api.Data/skydiveLogs-api.Data.csproj +++ b/Back/skydiveLogs-api.Data/skydiveLogs-api.Data.csproj @@ -1,12 +1,12 @@ - + - netcoreapp2.2 + netcoreapp3.1 skydiveLogs_api.Data - + diff --git a/Back/skydiveLogs-api.Ioc/skydiveLogs-api.Ioc.csproj b/Back/skydiveLogs-api.Ioc/skydiveLogs-api.Ioc.csproj index e0c0316..e57eef5 100644 --- a/Back/skydiveLogs-api.Ioc/skydiveLogs-api.Ioc.csproj +++ b/Back/skydiveLogs-api.Ioc/skydiveLogs-api.Ioc.csproj @@ -1,7 +1,7 @@ - + - netcoreapp2.2 + netcoreapp3.1 skydiveLogs_api.Ioc diff --git a/Back/skydiveLogs-api.Model/skydiveLogs-api.Model.csproj b/Back/skydiveLogs-api.Model/skydiveLogs-api.Model.csproj index dbf4987..da75e40 100644 --- a/Back/skydiveLogs-api.Model/skydiveLogs-api.Model.csproj +++ b/Back/skydiveLogs-api.Model/skydiveLogs-api.Model.csproj @@ -1,7 +1,7 @@ - netcoreapp2.2 + netcoreapp3.1 skydiveLogs_api.Model diff --git a/Back/skydiveLogs-api/Controllers/UserController.cs b/Back/skydiveLogs-api/Controllers/UserController.cs index 28246cb..493711f 100644 --- a/Back/skydiveLogs-api/Controllers/UserController.cs +++ b/Back/skydiveLogs-api/Controllers/UserController.cs @@ -64,31 +64,29 @@ namespace skydiveLogs_api.Controllers private string CreateToken(UserReq model) { - var tokenHandler = new JwtSecurityTokenHandler(); - var key = Encoding.ASCII.GetBytes("tata"); - var tokenDescriptor = new SecurityTokenDescriptor - { - Subject = new ClaimsIdentity(new Claim[] - { - new Claim(ClaimTypes.Name, model.Login) - }), - Expires = DateTime.UtcNow.AddMinutes(30), - SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) - }; - var token = tokenHandler.CreateToken(tokenDescriptor); - return tokenHandler.WriteToken(token); + //var tokenHandler = new JwtSecurityTokenHandler(); + //var key = Encoding.ASCII.GetBytes("azertyuiopqsdfghjklmwxcvbn"); + //var tokenDescriptor = new SecurityTokenDescriptor + //{ + // Subject = new ClaimsIdentity(new Claim[] + // { + // new Claim(ClaimTypes.Name, model.Login) + // }), + // Expires = DateTime.UtcNow.AddMinutes(30), + // SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) + //}; + //var token = tokenHandler.CreateToken(tokenDescriptor); + //return tokenHandler.WriteToken(token); + var key = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes("azertyuiopqsdfghjklmwxcvbn" /* this._configuration["jwt:key"] */)); + var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); + var token = new JwtSecurityToken("toto" /* this._configuration["jwt:issuer"] */, + "toto" /* this._configuration["jwt:issuer"] */, + expires: System.DateTime.Now.AddMinutes(30), + signingCredentials: credentials); - //var key = new SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes("tata" /* this._configuration["jwt:key"] */)); - //var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); - - //var token = new JwtSecurityToken("toto" /* this._configuration["jwt:issuer"] */, - // "toto" /* this._configuration["jwt:issuer"] */, - // expires: System.DateTime.Now.AddMinutes(30), - // signingCredentials: credentials); - - //return new JwtSecurityTokenHandler().WriteToken(token); + return new JwtSecurityTokenHandler().WriteToken(token); } private readonly IUserService _userService; diff --git a/Back/skydiveLogs-api/Startup.cs b/Back/skydiveLogs-api/Startup.cs index 98302ac..317cd6e 100644 --- a/Back/skydiveLogs-api/Startup.cs +++ b/Back/skydiveLogs-api/Startup.cs @@ -25,42 +25,43 @@ namespace skydiveLogs_api // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + services.AddMvc(options => { options.EnableEndpointRouting = false; }) + .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); // JWT - //services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - // .AddJwtBearer(options => - // { - // options.SaveToken = true; - // options.TokenValidationParameters = new TokenValidationParameters() - // { - // ValidateIssuer = true, - // ValidateAudience = true, - // ValidateLifetime = true, - // ValidateIssuerSigningKey = true, - // ValidIssuer = "toto", // Configuration["jwt:issuer"], - // ValidAudience = "toto", // Configuration["jwt:issuer"], - // IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("tata" /* this.Configuration["jwt:key"] */)) - // }; - // }); - var key = Encoding.ASCII.GetBytes("tata"); - services.AddAuthentication(x => - { - x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - }) - .AddJwtBearer(x => - { - x.RequireHttpsMetadata = false; - x.SaveToken = true; - x.TokenValidationParameters = new TokenValidationParameters - { - ValidateIssuerSigningKey = true, - IssuerSigningKey = new SymmetricSecurityKey(key), - ValidateIssuer = false, - ValidateAudience = false - }; - }); + services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(options => + { + options.SaveToken = true; + options.TokenValidationParameters = new TokenValidationParameters() + { + ValidateIssuer = true, + ValidateAudience = true, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + ValidIssuer = "toto", // Configuration["jwt:issuer"], + ValidAudience = "toto", // Configuration["jwt:issuer"], + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("azertyuiopqsdfghjklmwxcvbn" /* this.Configuration["jwt:key"] */)) + }; + }); + //var key = Encoding.ASCII.GetBytes("azertyuiopqsdfghjklmwxcvbn"); + //services.AddAuthentication(x => + //{ + // x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + // x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + //}) + //.AddJwtBearer(x => + //{ + // x.RequireHttpsMetadata = false; + // x.SaveToken = true; + // x.TokenValidationParameters = new TokenValidationParameters + // { + // ValidateIssuerSigningKey = true, + // IssuerSigningKey = new SymmetricSecurityKey(key), + // ValidateIssuer = false, + // ValidateAudience = false + // }; + //}); // CORS var corsConf = Configuration.GetSection("Cors") @@ -85,9 +86,9 @@ namespace skydiveLogs_api } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - if (env.IsDevelopment()) + if (env.EnvironmentName == "Development") { app.UseDeveloperExceptionPage(); } diff --git a/Back/skydiveLogs-api/skydiveLogs-api.csproj b/Back/skydiveLogs-api/skydiveLogs-api.csproj index c995cc1..8ccd641 100644 --- a/Back/skydiveLogs-api/skydiveLogs-api.csproj +++ b/Back/skydiveLogs-api/skydiveLogs-api.csproj @@ -1,7 +1,7 @@ - netcoreapp2.2 + netcoreapp3.1 InProcess skydiveLogs_api 9d7d268e-ee4d-43a2-a9b7-5b00b516f6f8 @@ -21,8 +21,10 @@ + - + +