BitzOrcas supports operator impersonation through the Delegation subsystem. Authorized operators can temporarily act on behalf of another user — useful for customer support and administration.
Architecture
Operator (admin) → DelegationTokenService → Generate Token │Target User ←──── DelegationTokenMiddleware ←───┘ │ ▼Request executes as target user │ ▼Audit trail: operator_id + target_user_idComponents
| Component | Purpose |
|---|---|
DelegationTokenService | Generate and validate impersonation tokens |
DelegationTokenMiddleware | Intercepts and validates delegation tokens |
IDelegationGrantRepository | SqlSugar-backed grant storage |
DelegationGrantEntity | Grant record (operator, target, TTL, scope) |
ICurrentUserAccessor.BeginScope() | Run-as context for background jobs |
Delegation grant entity
public class DelegationGrantEntity : EntityBase{ public string OperatorId { get; set; } public string TargetUserId { get; set; } public string TenantId { get; set; } public DateTimeOffset ExpiresAt { get; set; } public string? Scope { get; set; } public bool IsRevoked { get; set; }}Token lifecycle
- Grant creation: Operator requests impersonation of a target user
- Token generation:
DelegationTokenServicecreates a time-limited token - Token validation:
DelegationTokenMiddlewarevalidates token in each request - Context injection:
ICurrentUserreflects the target user’s identity - Audit: All actions logged with both operator and target user
- Expiry: Token automatically expires after TTL
Middleware position
ExceptionHandler → CorrelationId → Authentication → DelegationToken→ TenantResolution → Audit → Authorization → RateLimiter → EndpointsDelegation validation occurs after authentication but before tenant resolution — the operator must be authenticated first.
Security considerations
- Grants have configurable TTL (default: 1 hour)
- Grants can be revoked immediately
- Scope restrictions limit what the operator can do
- All impersonated actions are audited
- Only operators with
delegation.grantpermission can create grants
Current limitations
- EF Core path does not support delegation yet (SqlSugar only)
- Background job impersonation uses
BeginScopeinstead of middleware
See also
- Identity module — Permission model
- Multitenancy deep dive — Tenant context