Convert the AppSettings to model class
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@@ -15,6 +13,8 @@ using AutoMapper;
|
||||
|
||||
using skydiveLogs_api.Ioc;
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api
|
||||
{
|
||||
@@ -32,9 +32,12 @@ namespace skydiveLogs_api
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
|
||||
|
||||
// JWT
|
||||
var jwtConf = Configuration.GetSection("JWT")
|
||||
.GetChildren()
|
||||
.ToDictionary(d => d.Key, d => d.Value);
|
||||
var jwtSection = Configuration.GetSection("JWT");
|
||||
services.Configure<JwtSettings>(jwtSection);
|
||||
|
||||
var jwtSettings = new JwtSettings();
|
||||
jwtSection.Bind(jwtSettings);
|
||||
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
@@ -45,22 +48,22 @@ namespace skydiveLogs_api
|
||||
ValidateAudience = true,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = jwtConf["Issuer"],
|
||||
ValidAudience = jwtConf["Issuer"],
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtConf["Key"]))
|
||||
ValidIssuer = jwtSettings.Issuer,
|
||||
ValidAudience = jwtSettings.Issuer,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Passphrase))
|
||||
};
|
||||
});
|
||||
|
||||
// CORS
|
||||
var corsConf = Configuration.GetSection("Cors")
|
||||
.GetChildren()
|
||||
.ToDictionary(d => d.Key, d => d.Value);
|
||||
var corsSettings = new CorsSettings();
|
||||
Configuration.GetSection("Cors").Bind(corsSettings);
|
||||
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddDefaultPolicy(
|
||||
builder =>
|
||||
{
|
||||
builder.WithOrigins(corsConf["FrontUrl"])
|
||||
builder.WithOrigins(corsSettings.FrontUrl)
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
});
|
||||
@@ -106,7 +109,6 @@ namespace skydiveLogs_api
|
||||
var initDbService = serviceProvider.GetRequiredService<IInitDbService>();
|
||||
initDbService.GenerateDb();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
Reference in New Issue
Block a user