Unkey Integration
Alpha
DSAR is currently in alpha. APIs, package surfaces, configuration, and documentation may change as the project evolves.
@dsar/auth-unkey is an optional helper package for the DSAR bearer-token lane.
It does not replace DSAR's authorization or subject-ownership checks.
Install
Runtime Wiring
Validate process.env.UNKEY_ROOT_KEY and process.env.DSAR_API_TOKEN at
startup before calling makeUnkeyBearerResolver(...) or building
staticBearerTokens. The example uses non-null assertions for brevity, but
production runtimes should fail fast with a clear configuration error when
UNKEY_ROOT_KEY or DSAR_API_TOKEN is missing instead of crashing later at
request time.
Default Mapping
makeUnkeyBearerResolver() maps verified keys into DSAR identities like this:
data.identity.externalIdordata.keyId->actorIddata.meta.tenantId->tenantIddata.meta.workspaceId->workspaceIddata.meta.roleor first role indata.roles->roledata.meta.principalKind->principalKinddata.meta.emailordata.identity.email->email
If tenantId is missing, the resolver returns no identity and DSAR rejects the
request.
Custom Mapping
Use mapIdentity when your Unkey metadata shape differs from the DSAR default:
Hosted Safety Rules
- Keep browser-held DSAR keys out of subject portals.
- Bind every accepted key to a tenant in Unkey metadata.
- Treat Unkey as credential verification only; DSAR still enforces route access.