MCPcopy Create free account
hub / github.com/FrodeHus/EntraRoleReaper / GetCurrentUser

Method GetCurrentUser

server/Review/UserService.cs:9–27  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7public 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 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected