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
+7
View File
@@ -11,6 +11,7 @@ namespace SharpbinV3.Server.Data
public DbSet<RefreshToken> RefreshTokens => Set<RefreshToken>();
public DbSet<UserTotp> UserTotps => Set<UserTotp>();
public DbSet<Report> Reports => Set<Report>();
public DbSet<ApiKey> ApiKeys => Set<ApiKey>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -56,6 +57,12 @@ namespace SharpbinV3.Server.Data
.WithMany(u => u.Reports)
.HasForeignKey(r => r.UserUUID)
.OnDelete(DeleteBehavior.SetNull);
modelBuilder.Entity<ApiKey>()
.HasOne(a => a.User)
.WithMany(u => u.ApiKeys)
.HasForeignKey(a => a.UserUUID)
.OnDelete(DeleteBehavior.Cascade);
}
}
}
+16
View File
@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;
namespace SharpbinV3.Server.Data.Entities
{
public sealed class ApiKey
{
[Key]
public Guid UUID { get; set; } = Guid.CreateVersion7();
public required Guid UserUUID { get; set; }
public User? User { get; set; }
public required string KeyHash { get; set; }
public required string Name { get; set; }
public long CreatedAt { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
public long? LastUsedAt { get; set; }
}
}
+1
View File
@@ -23,6 +23,7 @@ namespace SharpbinV3.Server.Data.Entities
public List<Paste> Pastes { get; set; } = [];
public List<RefreshToken> RefreshTokens { get; set; } = [];
public List<Report> Reports { get; set; } = [];
public List<ApiKey> ApiKeys { get; set; } = [];
public UserTotp? Totp { get; set; }
}
}