From 48697c4900a5b7386cd69432faa0c79e809d6b88 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 2 Apr 2025 11:18:09 +1000 Subject: [PATCH] Only parse guids on demand --- .../Authorization/ClaimsExtensions.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Api/AdminConsole/Authorization/ClaimsExtensions.cs b/src/Api/AdminConsole/Authorization/ClaimsExtensions.cs index fab601aa89..99040bc0c6 100644 --- a/src/Api/AdminConsole/Authorization/ClaimsExtensions.cs +++ b/src/Api/AdminConsole/Authorization/ClaimsExtensions.cs @@ -51,30 +51,31 @@ public static class ClaimsExtensions /// private static HasClaim GetClaimsParser(ClaimsPrincipal user, Guid organizationId) { - // Transform into a dict based on the claim type + // Group claims by ClaimType var claimsDict = user.Claims - .GetGuidClaims() .GroupBy(c => c.Type) .ToDictionary( c => c.Key, - c => c.Select(v => v.Value)); + c => c.ToList()); return claimType - => claimsDict.TryGetValue(claimType, out var claimValue) && - claimValue.Any(v => v == organizationId); + => claimsDict.TryGetValue(claimType, out var claims) && + claims + .ParseGuids() + .Any(v => v == organizationId); } /// - /// Parses all claims into proper Guids, or ignore them if they are not valid guids. + /// Parses the provided claims into proper Guids, or ignore them if they are not valid guids. /// - private static List<(string Type, Guid Value)> GetGuidClaims(this IEnumerable claims) + private static List ParseGuids(this IEnumerable claims) { - List<(string Type, Guid Value)> result = []; + List result = []; foreach (var claim in claims) { if (Guid.TryParse(claim.Value, out var guid)) { - result.Add((claim.Type, guid)); + result.Add(guid); } }