Reorganized file structure and namespaces

This commit is contained in:
Veljko Tosic
2026-02-14 19:16:06 +01:00
parent 12bded085b
commit b2812feaab
11 changed files with 19 additions and 22 deletions

View File

@@ -0,0 +1,35 @@
using System.Security.Claims;
using AipsCore.Application.Abstract.UserContext;
using AipsCore.Domain.Models.User.ValueObjects;
using Microsoft.AspNetCore.Http;
namespace AipsCore.Infrastructure.Authentication.UserContext;
public class HttpUserContext : IUserContext
{
private readonly IHttpContextAccessor _httpContextAccessor;
public HttpUserContext(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public UserId GetCurrentUserId()
{
var user = _httpContextAccessor.HttpContext?.User;
if (user is null || !user.Identity!.IsAuthenticated)
{
throw new UnauthorizedAccessException("User is not authenticated");
}
var userIdClaim = user.FindFirst(ClaimTypes.NameIdentifier);
if (userIdClaim is null)
{
throw new UnauthorizedAccessException("User id claim not found");
}
return new UserId(userIdClaim.Value);
}
}