fix: denies unauthenticated users on policy-protected endpoints

This commit is contained in:
BinaryAlley committed 2026-08-17 11:52:31 -07:00
1 parent 7ad7ad308e
commit d10233f4e3
3 files changed
+20 -15

No files matched your search

@@ -62,8 +62,10 @@ public class AuthorizationService : IAuthorizationService
/// <returns>The user's authorization details.</returns>
private async Task<GetAuthorizationResponse> GetUserAuthorizationAsync(CancellationToken cancellationToken)
{
// get the id of the currently logged in user
string userId = _httpContextAccessor.HttpContext!.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
return await _apiHttpClient.GetAsync<GetAuthorizationResponse>($"auth/get-authorization?userId={Uri.EscapeDataString(userId.ToString())}", cancellationToken);
// anonymous users and users without an identifier claim have no role or permissions, so deny without querying the API
string? userId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
if (string.IsNullOrEmpty(userId))
return new GetAuthorizationResponse(Guid.Empty, string.Empty, []);
return await _apiHttpClient.GetAsync<GetAuthorizationResponse>($"auth/get-authorization?userId={Uri.EscapeDataString(userId)}", cancellationToken);
}
}