From 4534d4dbf5f5071fa71c5dec4444bf4b2bbd040c Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 14 Dec 2025 23:18:35 +0100 Subject: admin api packaging --- .../Services/AuthenticationService.cs | 42 ---------------------- 1 file changed, 42 deletions(-) delete mode 100644 extra/admin-api/Spacebar.AdminAPI/Services/AuthenticationService.cs (limited to 'extra/admin-api/Spacebar.AdminAPI/Services/AuthenticationService.cs') diff --git a/extra/admin-api/Spacebar.AdminAPI/Services/AuthenticationService.cs b/extra/admin-api/Spacebar.AdminAPI/Services/AuthenticationService.cs deleted file mode 100644 index d402c5b96..000000000 --- a/extra/admin-api/Spacebar.AdminAPI/Services/AuthenticationService.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.IdentityModel.Tokens.Jwt; -using System.Security.Cryptography; -using Microsoft.IdentityModel.Tokens; -using Spacebar.Db.Contexts; -using Spacebar.Db.Models; - -namespace Spacebar.AdminAPI.Services; - -public class AuthenticationService(SpacebarDbContext db, Configuration config) { - private static Dictionary _userCache = new(); - private static Dictionary _userCacheExpiry = new(); - - public async Task GetCurrentUser(HttpRequest request) { - if (!request.Headers.ContainsKey("Authorization")) { - Console.WriteLine(string.Join(", ", request.Headers.Keys)); - throw new UnauthorizedAccessException(); - } - - var token = request.Headers["Authorization"].ToString().Split(' ').Last(); - - var handler = new JwtSecurityTokenHandler(); - var secretFile = File.ReadAllText("../../../jwt.key.pub"); - var key = ECDsa.Create(ECCurve.NamedCurves.nistP256); - key.ImportFromPem(secretFile); - - var res = await handler.ValidateTokenAsync(token, new TokenValidationParameters { - IssuerSigningKey = new ECDsaSecurityKey(key), - ValidAlgorithms = ["ES512"], - LogValidationExceptions = true, - // These are required to be false for the token to be valid as they aren't provided by the token - ValidateIssuer = false, - ValidateLifetime = false, - ValidateAudience = false, - }); - - if (!res.IsValid && !config.DisableAuthentication) { - throw new UnauthorizedAccessException(); - } - - return await db.Users.FindAsync(config.OverrideUid ?? res.ClaimsIdentity.Claims.First(x => x.Type == "id").Value) ?? throw new InvalidOperationException(); - } -} \ No newline at end of file -- cgit 1.5.1