Added Authorization
This commit is contained in:
parent
04049f31f6
commit
e47d6488c2
15 changed files with 134 additions and 21 deletions
|
@ -1,10 +1,7 @@
|
|||
using Discord.OAuth2;
|
||||
using Lieb.Data;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
@ -32,6 +29,15 @@ builder.Services.AddAuthentication(opt =>
|
|||
x.SaveTokens = true;
|
||||
});
|
||||
|
||||
builder.Services.AddAuthorization(options =>
|
||||
{
|
||||
foreach(string role in Constants.Roles.GetAllRoles())
|
||||
{
|
||||
options.AddPolicy(role, policy => policy.RequireClaim(Constants.ClaimType, role));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
@ -62,6 +68,7 @@ app.UseStaticFiles();
|
|||
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue