Skip to content

Identity Package

The identity packages verify Caracal mandate JWTs. Use them when you are building an adapter or custom resource-server boundary that accepts mandates directly.

Do not use identity verification alone as a production authorization boundary when revocation must take effect before token expiry; compose it through Verify Package with a shared revocation store.

EcosystemPackage
TypeScriptnpm install @caracalai/identity
Pythonpip install caracalai-identity
Gogo get github.com/garudex-labs/caracal/packages/identity/go

Node packages target Node >=22; Python packages require Python >=3.12.

OptionMeaning
issuer / IssuerExpected STS issuer.
audience / AudienceExpected audience for the mandate.
zoneId / expected_zone_id / ZoneIDRequired zone trust anchor. It fixes which zone’s signing keyset verifies the token and must equal the zone_id claim, so key selection is never influenced by the unverified token. Verification fails closed when it is missing.
requiredScopes / required_scopes / RequiredScopesScopes every accepted mandate must contain.
requiredTargets / required_targets / RequiredTargetsTarget resources every accepted mandate must include.
requiredUse / required_use / RequiredUseToken use, usually resource.
requireSession / require_session / RequireSessionRequire a governed Session identity.
requireDelegation / require_delegation / RequireDelegationRequire a Delegation claim (delegation_edge_id on the wire).
requireChainContains / require_chain_contains / RequireChainContainsRequire an application in the delegation chain.
maxHopCount / max_hop_count / MaxHopCountCap delegation chain depth.
import { verify } from '@caracalai/identity'
const claims = await verify(token, {
issuer: 'https://sts.pipernet.example',
audience: 'https://api.pipernet.example',
zoneId: '0195f2a9-1b22-7c3d-9e4f-5a6b7c8d9e0f',
requiredScopes: ['pipernet:read'],
requiredTargets: ['resource://pipernet'],
})

The identity packages map raw JWT claims to canonical language-level fields:

MeaningTypeScriptPythonGoRaw JWT claim
Authority record IDauthorityRecordIdauthority_record_idAuthorityRecordIDsid
Root authority record IDrootAuthorityRecordIdroot_authority_record_idRootAuthorityRecordIDroot_sid
Session IDsessionIdsession_idSessionIDagent_session_id
Delegation IDdelegationIddelegation_idDelegationIDdelegation_edge_id

STS signing keysets are zone-scoped: every fetch hits {issuer}/.well-known/jwks.json?zone_id={zone} and is cached per issuer and zone. TypeScript verifiers use an in-memory JWKS cache by default. Build a cache explicitly when a resource server wants shorter local-development TTLs, a custom fetch implementation, or warmup during service boot.

import { createJwksCache, verify } from '@caracalai/identity'
const jwksCache = createJwksCache({ ttlMs: 300_000, fetchTimeoutMs: 5_000 })
await jwksCache.warm('https://sts.pipernet.example', '0195f2a9-1b22-7c3d-9e4f-5a6b7c8d9e0f')
const claims = await verify(token, {
issuer: 'https://sts.pipernet.example',
audience: 'https://api.pipernet.example',
zoneId: '0195f2a9-1b22-7c3d-9e4f-5a6b7c8d9e0f',
jwksCache,
})

Go and Python identity packages also cache issuer JWKS metadata in memory and cap documents at 256 KiB. Python JwksCache(http_client=...) accepts an injected async client for private CAs, proxies, or mTLS. Go callers use NewJWKSCache(httpClient, ttl) and pass it through Config.JWKSCache; GetJWKSContext retains the bounded default. Python exposes warm_jwks(issuer, zone_id) for service boot.

ErrorMeaning
TokenInvalidErrorSignature, issuer, audience, expiry, use, or claim validation failed.
ZoneInvalidErrorThe token zone did not match the expected zone.
ScopeInsufficientErrorA required scope is missing.
SessionRequiredErrorThe verifier requires a governed Session identity.
DelegationRequiredErrorThe verifier requires delegated authority.
ChainMismatchErrorThe delegation chain is missing a required application.
HopCountExceededErrorThe mandate exceeds the configured hop limit.

Verification is local except for JWKS retrieval. It does not call STS to refresh or exchange a token, and it does not retry application work. Zone ID, issuer, audience, required use, scopes, targets, Session, Delegation, chain, and hop requirements are security inputs and must come from trusted service configuration.

Use Verify Package when you also need revocation checks, reusable verifier defaults, bearer-header parsing, and safe debugging hints. Use the identity package directly when you are composing your own verifier or adapter boundary.