Update to DotNet Core 3.1
+ next step to add JWT token authorize
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user