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

This commit is contained in:
Stevan Freeborn
2026-02-02 13:18:15 -06:00
parent b3bfa64b96
commit 178f03459b
3 changed files with 8 additions and 10 deletions
-1
View File
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" /> <PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+5 -8
View File
@@ -1,5 +1,4 @@
using FiscalOS.Core.Authentication;
using FiscalOS.Core.Identity;
namespace FiscalOS.API.Login; namespace FiscalOS.API.Login;
@@ -13,11 +12,11 @@ internal static class Endpoint
} }
private static async Task<IResult> HandleAsync( private static async Task<IResult> HandleAsync(
HttpContext httpContext,
[FromBody] LoginRequest loginRequest, [FromBody] LoginRequest loginRequest,
[FromServices] HttpContext httpContext,
[FromServices] AppDbContext appDbContext, [FromServices] AppDbContext appDbContext,
[FromServices] IPasswordHasher passwordHasher, [FromServices] IPasswordHasher passwordHasher,
[FromServices] TokenService tokenService [FromServices] ITokenGenerator tokenService
) )
{ {
var user = await appDbContext.Users.SingleOrDefaultAsync(u => u.Username == loginRequest.Username); var user = await appDbContext.Users.SingleOrDefaultAsync(u => u.Username == loginRequest.Username);
@@ -47,13 +46,11 @@ internal static class Endpoint
{ {
HttpOnly = true, HttpOnly = true,
Expires = refreshToken.ExpiresAt, Expires = refreshToken.ExpiresAt,
// TODO: Revisit when decided SameSite = SameSiteMode.Strict,
// on hosting setup
SameSite = SameSiteMode.None,
Secure = true 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) 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.ConfigureOptions<AppDbContextOptionsSetup>();
services.AddDbContext<AppDbContext>(); services.AddDbContext<AppDbContext>();
services.AddHostedService<MigrationService>(); services.AddHostedService<MigrationService>();