feat(backend): implement api keys; rename token -> verificationToken in paste creation api

api keys can bypass authentication and captchas/verification
This commit is contained in:
2026-02-13 01:47:50 -05:00
parent db363f0211
commit 53d0f33ff0
19 changed files with 821 additions and 9 deletions
@@ -1,5 +1,6 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using SharpbinV3.Server.Extensions;
namespace SharpbinV3.Server.Authorization
{
@@ -9,13 +10,26 @@ namespace SharpbinV3.Server.Authorization
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, NotBannedRequirement requirement)
{
var httpContext = context.Resource as HttpContext;
var isAuthenticated = context.User.Identity?.IsAuthenticated ?? false;
if (!isAuthenticated && httpContext != null)
{
var apiKey = httpContext.GetApiKeyFromContext();
if (apiKey != null)
{
isAuthenticated = true;
}
}
if (_requireAuth && !isAuthenticated)
return Task.CompletedTask;
var isBanned = context.User.Claims.Any(c => (c.Type == ClaimTypes.Role || c.Type == "role") && c.Value == "403");
if (httpContext?.GetApiKeyFromContext()?.User?.Roles?.Contains(403) == true)
isBanned = true;
if (!isBanned)
context.Succeed(requirement);