Added refresh tokens and reorganized file structure

This commit is contained in:
Veljko Tosic
2026-02-14 18:48:39 +01:00
parent 888db766a3
commit 6b0a97e617
8 changed files with 152 additions and 6 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.Persistence.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);
}
}