31 lines
1014 B
C#
31 lines
1014 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Selector.Model.Authorisation;
|
|
|
|
namespace Selector.Model.Extensions
|
|
{
|
|
public static class ServiceExtensions
|
|
{
|
|
public static void AddAuthorisationHandlers(this IServiceCollection services)
|
|
{
|
|
services.AddAuthorization(options =>
|
|
{
|
|
options.FallbackPolicy = new AuthorizationPolicyBuilder()
|
|
.RequireAuthenticatedUser()
|
|
.Build();
|
|
});
|
|
services.AddScoped<IAuthorizationHandler, WatcherIsOwnerAuthHandler>();
|
|
services.AddSingleton<IAuthorizationHandler, WatcherIsAdminAuthHandler>();
|
|
|
|
services.AddScoped<IAuthorizationHandler, UserIsSelfAuthHandler>();
|
|
services.AddSingleton<IAuthorizationHandler, UserIsAdminAuthHandler>();
|
|
}
|
|
}
|
|
}
|