User impersonation for staff support workflows
| Tier | identity |
| Role | unclassified (baselined) |
| Path | crates/identity/impersonation |
| Edition | 2021 |
| Targets | identity_impersonation |
| Public items | 0 across 0 modules |
| Tests | 19 |
What it is for
User impersonation library crates for staff support workflows.
This crate provides a secure way for staff members to "view as" customers for support and debugging purposes, with full audit logging.
# Features
- Extended JWT claims with impersonator tracking
- Permission checks (staff can't impersonate other staff)
- Shorter token expiry for impersonation sessions
- Audit event generation for compliance
# Example
use identity_impersonation::{ImpersonationClaims, ImpersonationRequest, ImpersonationService};
// Staff initiates impersonation
let request = ImpersonationRequest {
staff_user_id: staff_id,
target_user_id: customer_id,
};
let result = service.start_impersonation(request).await?;
// result.token contains JWT with impersonator_id set
// result.audit_event can be persisted to audit log
Capabilities
No public items.
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
No public items.
Re-exports. Exported here, defined elsewhere.
| Export | Defined in |
|---|---|
ImpersonationError | error::ImpersonationError |
{ClaimsExt,ImpersonationClaims,IMPERSONATION_AUDIENCE,IMPERSONATION_ISSUER} | claims::{ClaimsExt,ImpersonationClaims,IMPERSONATION_AUDIENCE,IMPERSONATION_ISSUER} |
{ImpersonationConfig,ImpersonationService} | service::{ImpersonationConfig,ImpersonationService} |
{ImpersonationEvent,ImpersonationEventType} | event::{ImpersonationEvent,ImpersonationEventType} |
{ImpersonationRequest,StopImpersonationRequest} | request::{ImpersonationRequest,StopImpersonationRequest} |
Boundary
Reaches into foundation.
Shares tier identity with 7 other crates: identity-auth, identity-identifiers, identity-parties, identity-party-places, identity-rbac, identity-tenant, identity-user-prefs.
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | identity |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/identity/impersonation |
| Vocabulary in force (lexicon) | current |
Tier flow. Which tiers this crate's own edges cross.
flowchart LR n_identity["identity"] --> n_foundation["foundation"]
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `foundation-audit-log` | foundation | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
chrono | ^0.4 | serde | no | always |
jsonwebtoken | ^9.0 | — | no | always |
serde | ^1.0 | derive | no | always |
serde_json | ^1.0 | — | no | always |
thiserror | ^1.0 | — | no | always |
uuid | ^1.0 | v4, serde | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio | ^1.0 | rt-multi-thread, macros | no | always |
Build. None.
Depended on by. 1 workspace crate.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_impersonation["application-impersonation"] -->|uses| SELF SELF["identity-impersonation"] SELF -->|runtime| n_foundation_audit_log["foundation-audit-log"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | identity_impersonation | `src/lib.rs` |
Error model
No public error type was detected: no public item declares a type named *Error, and no public signature returns one.
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
1 workspace crate depends on this one: application-impersonation.
Verification
| Kind | Count |
|---|---|
| Unit tests | 19 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
What the tests establish, by name:
test_claims_is_impersonating—src/lib.rstest_claims_not_impersonating—src/lib.rstest_config_custom—src/lib.rstest_config_defaults—src/lib.rstest_impersonation_event_creation—src/lib.rstest_impersonation_request_reject_admin_target—src/lib.rstest_impersonation_request_reject_non_staff_initiator—src/lib.rstest_impersonation_request_reject_staff_target—src/lib.rstest_impersonation_request_validation—src/lib.rsaccepts_real_secret_and_round_trips—src/service.rsrejects_alg_confusion—src/service.rsrejects_default_secret—src/service.rsrejects_empty_secret—src/service.rsrejects_expired_token—src/service.rsrejects_missing_audience_and_issuer—src/service.rsrejects_token_omitting_audience_and_issuer—src/service.rsrejects_token_omitting_audience_only—src/service.rsrejects_token_omitting_issuer_only—src/service.rsrejects_wrong_audience—src/service.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 0 | 0 |
Public modules with a //! block | 0 | 0 |
Metrics
| Metric | Value |
|---|---|
| Rust source files | 6 |
| Source lines | 1113 |
| Code lines | 755 |
| Public API items | 0 |
| Public modules | 0 |
| Tests | 19 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 7 |
| Workspace reverse dependencies | 1 |
pie showData
title Rust source composition
"Code" : 755
"Blank or comment" : 358
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.