Method EnrichPrincipalAsync(ClaimsPrincipal, long, IEnumerable<string>, CancellationToken)
Adds group names and/or role names to the principal's identity
based on requested scopes.
public Task EnrichPrincipalAsync(ClaimsPrincipal principal, long userId, IEnumerable<string> scopes, CancellationToken ct = default)
Remarks
Group claims include both direct memberships AND ancestor groups via tree-hierarchy
(composite group inheritance — DoD §5 H2). For example, if user is in "developers"
which is a child of "engineering" which is a child of "company", the principal
receives groups: ["developers", "engineering", "company"]. Ancestor expansion
uses a single server-side recursive CTE (via TreeQuery + ToTreeListAsync) —
not an N+1 client-side walk — so it scales to deep / wide group hierarchies.
The org claim also walks the tree to find the closest organization-type
ancestor when no direct organization-type membership exists. Per-membership
Role labels () are NOT inherited — they describe
the user's role within a specific group, not a transitive concept.