Add JWT reference
The first thing we need to do is go to the Nuget Manager for the solution and search for:


Once we have installed it we need to verify the next lines of code in the ConfigureServices
we will need to add the following lines of code into such a method.
// Set up JWT token
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII
.GetBytes(Configuration.GetSection("AppSettings:Token").Value)),
ValidateIssuer = false,
ValidateAudience = false
};
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hyreet V1", Version = "v1" });
});
In our AppSettings.json
we need to add the following lines of code:
{
"AppSettings": {
"Token": "super_secret_key"
},
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=HyreetDB;Uid=root;Pwd=MyDevelopment**;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Last updated
Was this helpful?