summaryrefslogtreecommitdiff
path: root/Program.cs
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2022-11-27 12:46:26 -0600
committerHombreLaser <sebastian-440@live.com>2022-11-27 12:46:26 -0600
commit3da900a30e788d0acf2fcee7dba2aecdb16aab43 (patch)
treeec8312f37d26f81b22fb498728572f08983d67e5 /Program.cs
parent45eb6bcac6eaa57efba955dd45aad46f988aaf35 (diff)
Añadido logout
Diffstat (limited to 'Program.cs')
-rw-r--r--Program.cs8
1 files changed, 8 insertions, 0 deletions
diff --git a/Program.cs b/Program.cs
index ed98bd4..793aa1e 100644
--- a/Program.cs
+++ b/Program.cs
@@ -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.