The helper class and interface for getting information about an authorized user. Included in the general set of auxiliary libraries: Alva.ServiceKit.*
$ dotnet add package Alva.ServiceKit.IdentityServiceВспомогательный класс и интерфейс для получения информации об авторизированном пользователе. Входит в состав общего набора вспомогательных библиотек: Alva.ServiceKit.*
Interface
public interface IUserService
{
public string GetCurrentUserName();
public ClaimsPrincipal GetCurrentUser();
}
Implementation
public string GetCurrentUserName()
{
return _context.HttpContext?.User?.Identity?.Name;
}
public ClaimsPrincipal GetCurrentUser()
{
return _context.HttpContext?.User;
}