Add few config to create the token

This commit is contained in:
Sébastien André
2020-03-20 15:10:18 +01:00
parent 8dc6310080
commit 7bad7e80d5
5 changed files with 39 additions and 44 deletions

View File

@@ -29,6 +29,9 @@ namespace skydiveLogs_api
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
// JWT
var jwtConf = Configuration.GetSection("JWT")
.GetChildren()
.ToDictionary(d => d.Key, d => d.Value);
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
@@ -39,29 +42,11 @@ namespace skydiveLogs_api
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"] */))
ValidIssuer = jwtConf["Issuer"],
ValidAudience = jwtConf["Issuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtConf["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")