summary refs log tree commit diff
path: root/extra/admin-api/Interop/Spacebar.Interop.Authentication.AspNetCore/SpacebarAspNetAuthenticationService.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-02-03 03:10:10 +0100
committerRory& <root@rory.gay>2026-02-03 03:15:59 +0100
commita06e8f723b5c81945d8f226e8d77d95312cb8d85 (patch)
tree3b37c13bb890620168b0b81a20e37c75de8b3241 /extra/admin-api/Interop/Spacebar.Interop.Authentication.AspNetCore/SpacebarAspNetAuthenticationService.cs
parentUpdate C# db models (diff)
downloadserver-ts-a06e8f723b5c81945d8f226e8d77d95312cb8d85.tar.xz
Abstract out C# auth
Diffstat (limited to 'extra/admin-api/Interop/Spacebar.Interop.Authentication.AspNetCore/SpacebarAspNetAuthenticationService.cs')
-rw-r--r--extra/admin-api/Interop/Spacebar.Interop.Authentication.AspNetCore/SpacebarAspNetAuthenticationService.cs26
1 files changed, 26 insertions, 0 deletions
diff --git a/extra/admin-api/Interop/Spacebar.Interop.Authentication.AspNetCore/SpacebarAspNetAuthenticationService.cs b/extra/admin-api/Interop/Spacebar.Interop.Authentication.AspNetCore/SpacebarAspNetAuthenticationService.cs
new file mode 100644

index 000000000..07abb9fed --- /dev/null +++ b/extra/admin-api/Interop/Spacebar.Interop.Authentication.AspNetCore/SpacebarAspNetAuthenticationService.cs
@@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.IdentityModel.Tokens; +using Spacebar.Models.Db.Models; + +namespace Spacebar.Interop.Authentication.AspNetCore; + +public class SpacebarAspNetAuthenticationService(SpacebarAuthenticationService authService) { + public string GetTokenAsync(HttpRequest request) { + if (!request.Headers.ContainsKey("Authorization")) { + Console.WriteLine(string.Join(", ", request.Headers.Keys)); + throw new UnauthorizedAccessException(); + } + + return request.Headers["Authorization"].ToString().Split(' ').Last(); + } + + public async Task<TokenValidationResult?> ValidateTokenAsync(HttpRequest request) { + var token = GetTokenAsync(request); + return await authService.ValidateTokenAsync(token); + } + + public async Task<User> GetCurrentUserAsync(HttpRequest request) { + var token = GetTokenAsync(request); + return await authService.GetCurrentUserAsync(token); + } +} \ No newline at end of file