From 08819c6738a4f82ccf07ae5ed60835b087f7bb34 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sun, 6 Nov 2022 02:10:44 -0600 Subject: AƱadidos grupos y usuarios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Program.cs') diff --git a/Program.cs b/Program.cs index d717af7..2678a94 100644 --- a/Program.cs +++ b/Program.cs @@ -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(); builder.Services.AddScoped(); +// 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(); -- cgit v1.2.3