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
+18
View File
@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.DataProtection;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi;
using SharpbinV3.Server.Authorization;
using SharpbinV3.Server.Data;
using SharpbinV3.Server.Extensions;
@@ -38,7 +39,21 @@ namespace SharpbinV3.Server
options.AddDocumentTransformer(
(document, context, cancellationToken) =>
{
document?.Components ??= new();
document?.Servers?.Clear();
document?.Components?.SecuritySchemes ??= new Dictionary<string, IOpenApiSecurityScheme>();
document
?.Components
?.SecuritySchemes
?["ApiKey"] = new OpenApiSecurityScheme
{
Type = SecuritySchemeType.ApiKey,
Name = "X-API-Key",
In = ParameterLocation.Header,
Description = "Bypass authentication and captcha by providing a valid API key.",
};
return Task.CompletedTask;
}
);
@@ -54,6 +69,7 @@ namespace SharpbinV3.Server
builder.Services.AddScoped<UserService>();
builder.Services.AddScoped<AuthService>();
builder.Services.AddScoped<PasteService>();
builder.Services.AddScoped<ApiKeyService>();
builder.Services.AddScoped<VerificationService>();
builder.Services.AddScoped<TotpVerificationProvider>();
builder.Services.AddHttpClient<IVerificationProvider, TurnstileVerificationProvider>();
@@ -220,6 +236,8 @@ namespace SharpbinV3.Server
app.UseHttpsRedirection();
app.UseCors();
app.UseMiddleware<Middleware.ApiKeyAuthenticationMiddleware>();
app.UseAuthentication();
app.UseAuthorization();