diff options
author | HombreLaser <sebastian-440@live.com> | 2022-11-27 12:46:26 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-11-27 12:46:26 -0600 |
commit | 3da900a30e788d0acf2fcee7dba2aecdb16aab43 (patch) | |
tree | ec8312f37d26f81b22fb498728572f08983d67e5 /Program.cs | |
parent | 45eb6bcac6eaa57efba955dd45aad46f988aaf35 (diff) |
Añadido logout
Diffstat (limited to 'Program.cs')
-rw-r--r-- | Program.cs | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; @@ -8,6 +9,7 @@ using System.Text; using Microsoft.EntityFrameworkCore; using BackendPIA; using BackendPIA.Models; +using BackendPIA.Policies; using BackendPIA.Services; var builder = WebApplication.CreateBuilder(args); @@ -32,6 +34,8 @@ builder.Services.AddScoped<IRaffleService, RaffleService>(); builder.Services.AddScoped<ITicketService, TicketService>(); builder.Services.AddScoped<IPrizeService, PrizeService>(); // End of custom services configuration. +// Register the custom authorization handler. +builder.Services.AddScoped<IAuthorizationHandler, CorrectTokenHandler>(); // Swagger configuration. builder.Services.AddEndpointsApiExplorer(); @@ -75,6 +79,10 @@ builder.Services.AddAuthentication(options => { IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])), ClockSkew = TimeSpan.Zero } ); + +builder.Services.AddAuthorization(options => { + options.AddPolicy("ValidToken", policy => policy.Requirements.Add(new CorrectTokenRequirement())); +}); // End of authentication configuration. // Identity configuration. |