New project file, added Aspire, moved security

This commit is contained in:
James Wampler
2026-06-03 18:44:48 -07:00
parent 4c6df1f037
commit d3b36956e4
78 changed files with 2786 additions and 21210 deletions

View File

@@ -0,0 +1,58 @@
using Microsoft.AspNetCore.Mvc;
namespace MicCheck.Api.Common.Security.Authorization;
public static class AuthEndpoints
{
public static void MapAuthEndpoints(this WebApplication app)
{
var group = app.MapGroup("/api/v1/auth").AllowAnonymous().WithTags("Auth");
group.MapPost("/login", async ([FromBody] LoginRequest request, AuthService authService, CancellationToken ct) =>
{
if (string.IsNullOrWhiteSpace(request.Email) || string.IsNullOrWhiteSpace(request.Password))
return Results.BadRequest("Email and password are required.");
var response = await authService.LoginAsync(request.Email, request.Password, ct);
return response is null
? Results.Unauthorized()
: Results.Ok(response);
}).WithName("Login");
group.MapPost("/register", async ([FromBody] RegisterRequest request, AuthService authService, CancellationToken ct) =>
{
if (string.IsNullOrWhiteSpace(request.Email) || string.IsNullOrWhiteSpace(request.Password))
return Results.BadRequest("Email and password are required.");
var response = await authService.RegisterAsync(
request.Email, request.Password,
request.FirstName, request.LastName,
request.OrganizationName, ct);
return response is null
? Results.Conflict("An account with this email already exists.")
: Results.Ok(response);
}).WithName("Register");
group.MapPost("/refresh", async ([FromBody] RefreshRequest request, AuthService authService, CancellationToken ct) =>
{
if (string.IsNullOrWhiteSpace(request.Token))
return Results.BadRequest("Refresh token is required.");
var response = await authService.RefreshAsync(request.Token, ct);
return response is null
? Results.Unauthorized()
: Results.Ok(response);
}).WithName("RefreshToken");
group.MapPost("/logout", async ([FromBody] LogoutRequest request, AuthService authService, CancellationToken ct) =>
{
await authService.LogoutAsync(request.Token, ct);
return Results.NoContent();
}).WithName("Logout");
}
}