All manager classes should receive IHttpContextAccessor that could be used as follows:
public static class UserService
{
public static Guid GetCurrentUserId(IHttpContextAccessor accessor)
{
Claim claim = accessor.HttpContext.User.Claims.FirstOrDefault(c => c.Type == "id");
if (claim == null)
{
string msg = "Authorization server does not contains \"id\" property in UserInfo, ensure that you properly configured your UserProperty Mapper";
throw new InvalidOperationException(msg);
}
return Guid.Parse(claim.Value);
}
}