feat(api): integrate abstracted token generation and update login endpoint

This commit is contained in:
Stevan Freeborn
2026-02-03 04:38:40 -06:00
parent a1b993bd62
commit b05cc06dff
3 changed files with 8 additions and 10 deletions
-1
View File
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+5 -8
View File
@@ -1,5 +1,4 @@
using FiscalOS.Core.Identity;
using FiscalOS.Core.Authentication;
namespace FiscalOS.API.Login;
@@ -13,11 +12,11 @@ internal static class Endpoint
}
private static async Task<IResult> HandleAsync(
HttpContext httpContext,
[FromBody] LoginRequest loginRequest,
[FromServices] HttpContext httpContext,
[FromServices] AppDbContext appDbContext,
[FromServices] IPasswordHasher passwordHasher,
[FromServices] TokenService tokenService
[FromServices] ITokenGenerator tokenService
)
{
var user = await appDbContext.Users.SingleOrDefaultAsync(u => u.Username == loginRequest.Username);
@@ -47,13 +46,11 @@ internal static class Endpoint
{
HttpOnly = true,
Expires = refreshToken.ExpiresAt,
// TODO: Revisit when decided
// on hosting setup
SameSite = SameSiteMode.None,
SameSite = SameSiteMode.Strict,
Secure = true
}
);
return Results.Ok(new Response(accessToken));
return Results.Ok(Response.From(accessToken));
}
}
@@ -4,7 +4,9 @@ public static class ServiceCollectionExtensions
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
{
services.AddSingleton<IPasswordHasher, PasswordHasher>(static (_) => PasswordHasher.New());
services.AddSingleton(TimeProvider.System);
services.AddSingleton<ITokenGenerator, TokenGenerator>(TokenGenerator.From);
services.AddSingleton<IPasswordHasher, PasswordHasher>(PasswordHasher.From);
services.ConfigureOptions<AppDbContextOptionsSetup>();
services.AddDbContext<AppDbContext>();
services.AddHostedService<MigrationService>();