Add member routes to API

This commit is contained in:
Ske
2019-07-10 00:19:18 +02:00
parent 4874879979
commit 9a5152a74c
8 changed files with 96 additions and 4 deletions

View File

@@ -0,0 +1,23 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
namespace PluralKit.API
{
public class RequiresSystemAttribute: ActionFilterAttribute
{
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
var auth = context.HttpContext.RequestServices.GetRequiredService<TokenAuthService>();
if (auth.CurrentSystem == null)
{
context.Result = new UnauthorizedObjectResult("Invalid or missing token in Authorization header.");
return;
}
await base.OnActionExecutionAsync(context, next);
}
}
}