()
| 7 | public class UserService(IHttpContextAccessor httpContextAccessor, IGraphService graphService, ICacheService cacheService) : IUserService |
| 8 | { |
| 9 | public Task<UserContext> GetCurrentUser() |
| 10 | { |
| 11 | var user = httpContextAccessor.HttpContext?.User; |
| 12 | if (user == null || user.Identity?.IsAuthenticated == false) |
| 13 | { |
| 14 | throw new UnauthorizedAccessException("User is not authenticated."); |
| 15 | } |
| 16 | var userId = user.FindFirst("sub")?.Value ?? user.FindFirst(ClaimTypes.NameIdentifier)?.Value; |
| 17 | var tenantIdValue = httpContextAccessor.HttpContext?.Items["TenantId"]?.ToString(); |
| 18 | if (string.IsNullOrEmpty(userId)) |
| 19 | { |
| 20 | throw new UnauthorizedAccessException("User ID claim is missing."); |
| 21 | } |
| 22 | var tenantId = string.IsNullOrEmpty(tenantIdValue) ? Guid.Empty : Guid.Parse(tenantIdValue); |
| 23 | return Task.FromResult(new UserContext |
| 24 | { |
| 25 | UserId = userId, TenantId = tenantId |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | public async Task<UserContext> GetUserById(string userId, Guid tenantId) |
| 30 | { |
nothing calls this directly
no outgoing calls
no test coverage detected