From 724860c272afb7fe5a02645ef1c1b8d208d897f3 Mon Sep 17 00:00:00 2001 From: ivar Date: Thu, 4 Dec 2025 00:17:16 +0100 Subject: POC auth in app --- api/WhatApi/Endpoints/DownloadContentEndpoint.cs | 2 +- api/WhatApi/Endpoints/GetLoginPageEndpoint.cs | 12 ++++++++++++ api/WhatApi/Endpoints/LoginEndpoint.cs | 5 +++-- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 api/WhatApi/Endpoints/GetLoginPageEndpoint.cs (limited to 'api/WhatApi/Endpoints') diff --git a/api/WhatApi/Endpoints/DownloadContentEndpoint.cs b/api/WhatApi/Endpoints/DownloadContentEndpoint.cs index 34e51e8..dbbe57f 100644 --- a/api/WhatApi/Endpoints/DownloadContentEndpoint.cs +++ b/api/WhatApi/Endpoints/DownloadContentEndpoint.cs @@ -14,4 +14,4 @@ public class DownloadContentEndpoint : BaseEndpoint return NotFound(); } } -} \ No newline at end of file +} diff --git a/api/WhatApi/Endpoints/GetLoginPageEndpoint.cs b/api/WhatApi/Endpoints/GetLoginPageEndpoint.cs new file mode 100644 index 0000000..dd17669 --- /dev/null +++ b/api/WhatApi/Endpoints/GetLoginPageEndpoint.cs @@ -0,0 +1,12 @@ +using WhatApi.Templates; + +namespace WhatApi.Endpoints; + +public class GetLoginPageEndpoint : BaseEndpoint +{ + [AllowAnonymous] + [HttpGet("~/login")] + public ActionResult Handle() { + return Content(TemplateFulfiller.WebLoginPage(), "text/html"); + } +} \ No newline at end of file diff --git a/api/WhatApi/Endpoints/LoginEndpoint.cs b/api/WhatApi/Endpoints/LoginEndpoint.cs index ee697ef..cb76696 100644 --- a/api/WhatApi/Endpoints/LoginEndpoint.cs +++ b/api/WhatApi/Endpoints/LoginEndpoint.cs @@ -13,8 +13,9 @@ public class LoginEndpoint(AppDatabase db, IConfiguration configuration) : BaseE public required string Password { get; set; } } + [AllowAnonymous] [HttpPost("~/login")] - public async Task HandleAsync(LoginRequest login, CancellationToken ct = default) { + public async Task HandleAsync([FromForm] LoginRequest login, CancellationToken ct = default) { var user = await db.Users.FirstOrDefaultAsync(c => c.Name == login.Username, ct); if (user?.PasswordHash is null) return Unauthorized(); @@ -47,6 +48,6 @@ public class LoginEndpoint(AppDatabase db, IConfiguration configuration) : BaseE var tokenString = tokenHandler.WriteToken(token); user.SetLastSeen(); await db.SaveChangesAsync(ct); - return Ok(tokenString); + return Redirect("what://lcb?code=" + tokenString); } } \ No newline at end of file -- cgit v1.3