Add basic API, only with system endpoints
This commit is contained in:
31
PluralKit.API/TokenAuthService.cs
Normal file
31
PluralKit.API/TokenAuthService.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace PluralKit.API
|
||||
{
|
||||
public class TokenAuthService: IMiddleware
|
||||
{
|
||||
public PKSystem CurrentSystem { get; set; }
|
||||
|
||||
private SystemStore _systems;
|
||||
|
||||
public TokenAuthService(SystemStore systems)
|
||||
{
|
||||
_systems = systems;
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
|
||||
{
|
||||
var token = context.Request.Headers["Authorization"].FirstOrDefault();
|
||||
if (token != null)
|
||||
{
|
||||
CurrentSystem = await _systems.GetByToken(token);
|
||||
}
|
||||
|
||||
await next.Invoke(context);
|
||||
CurrentSystem = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user