summary refs log tree commit diff
path: root/extra/admin-api/Interop/Spacebar.Interop.Authentication/SpacebarAuthenticationService.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-02-06 05:21:31 +0100
committerRory& <root@rory.gay>2026-02-06 05:21:31 +0100
commit862bfd78038e0f35581ebe5d5416bb6f9bca999e (patch)
tree04c765c5a3cbacce67df0a73a1d970082985fdc2 /extra/admin-api/Interop/Spacebar.Interop.Authentication/SpacebarAuthenticationService.cs
parentshoot, screwed up the merge conflict (diff)
downloadserver-ts-862bfd78038e0f35581ebe5d5416bb6f9bca999e.tar.xz
C# gw offload work, schema-izing stuff
Diffstat (limited to 'extra/admin-api/Interop/Spacebar.Interop.Authentication/SpacebarAuthenticationService.cs')
-rw-r--r--extra/admin-api/Interop/Spacebar.Interop.Authentication/SpacebarAuthenticationService.cs11
1 files changed, 11 insertions, 0 deletions
diff --git a/extra/admin-api/Interop/Spacebar.Interop.Authentication/SpacebarAuthenticationService.cs b/extra/admin-api/Interop/Spacebar.Interop.Authentication/SpacebarAuthenticationService.cs

index 7b4ad1c8..5f9ff500 100644 --- a/extra/admin-api/Interop/Spacebar.Interop.Authentication/SpacebarAuthenticationService.cs +++ b/extra/admin-api/Interop/Spacebar.Interop.Authentication/SpacebarAuthenticationService.cs
@@ -46,4 +46,15 @@ public class SpacebarAuthenticationService(ILogger<SpacebarAuthenticationService }, config.AuthCacheExpiry); } + + public async Task<User> GetCurrentSessionAsync(string token) { + var res = await ValidateTokenAsync(token); + return await UserCache.GetOrAdd(token, + async () => { + var uid = config.OverrideUid ?? res?.ClaimsIdentity.Claims.First(x => x.Type == "id").Value; + if (string.IsNullOrWhiteSpace(uid)) throw new InvalidOperationException("No user ID specified, is the access token valid?"); + return await db.Users.FindAsync(uid) ?? throw new InvalidOperationException(); + }, + config.AuthCacheExpiry); + } } \ No newline at end of file