diff options
author | HombreLaser <sebastian-440@live.com> | 2022-11-06 02:10:44 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-11-06 02:10:44 -0600 |
commit | 08819c6738a4f82ccf07ae5ed60835b087f7bb34 (patch) | |
tree | 9c0c77626587136d41002769fb5a030e1be2f5b8 /Program.cs | |
parent | f060c4f88f635af3295ea7652cbbbd08dbf1c6cf (diff) |
Añadidos grupos y usuarios
Diffstat (limited to 'Program.cs')
-rw-r--r-- | Program.cs | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -1,4 +1,10 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Identity; +using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; +using System.IdentityModel.Tokens.Jwt; +using System.Text; using LibraryAPI.Models; using LibraryAPI.Filters; using LibraryAPI.Services; @@ -11,6 +17,21 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddHostedService<LoggerService>(); builder.Services.AddScoped<ActionFilter>(); +// JWT Config. +builder.Services.AddAuthentication(options => { + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; +}).AddJwtBearer(options => + options.TokenValidationParameters = new TokenValidationParameters { + ValidateIssuer = false, + ValidateAudience = false, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["keyjwt"])), + ClockSkew = TimeSpan.Zero + }); +builder.Services.AddAuthorization(); var app = builder.Build(); @@ -22,6 +43,8 @@ if (app.Environment.IsDevelopment()) app.UseHttpsRedirection(); +app.UseAuthentication(); + app.UseAuthorization(); app.MapControllers(); |