Auth
@aooth/auth is the method layer in the aoothjs stack — it owns issuance, validation, refresh and revocation of bearer credentials, plus magic-link helpers and the email/SMS transport contracts. It does not own credentials themselves (that's @aooth/user) and it does not own HTTP wiring (that's @aooth/auth-moost).
This page is the map. Every concept here has a dedicated child page.
Where it sits
┌─────────────────────────────────────────────────────────────┐
│ Framework integration │
│ @aooth/auth-moost · guards · workflows · controllers │
└────────────────────────┬────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Method layer │
│ @aooth/auth │
│ AuthCredential<TClaims> │
│ issue · validate · refresh · revoke │
│ revokeAllForUser · listForUser │
│ CredentialStore<TClaims> DenylistStore │
│ EmailSender · SmsSender · generateMagicLinkToken │
└────────────────────────┬────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Identity layer │
│ @aooth/user · password · MFA secret · lockout │
└─────────────────────────────────────────────────────────────┘The orchestrator is store-agnostic. Pick the store that matches your deployment along two axes.
The two store axes
| Axis | Stores | Token shape | Enumerable | Revocation |
|---|---|---|---|---|
| Stateful | CredentialStoreMemory, CredentialStoreRedis, CredentialStoreAtscriptDb | opaque UUID | yes (listForUser) | row delete |
| Stateless | CredentialStoreJwt, CredentialStoreEncapsulated | signed/encrypted | no | denylist by jti + per-user revocation epoch |
Stateless stores require a DenylistStore to support single-use operations (consume, revoke, update). Without one, those methods throw STATELESS_OPERATION_UNSUPPORTED. See Stores.
Minimal example
import { AuthCredential, CredentialStoreMemory } from "@aooth/auth";
const auth = new AuthCredential<{ roles: string[] }>({
store: new CredentialStoreMemory(),
accessTtl: 60 * 60 * 1000,
});
const { accessToken } = await auth.issue("alice", {
claims: { roles: ["admin"] },
metadata: { ip: "1.1.1.1" },
});
const ctx = await auth.validate(accessToken);
// { userId: 'alice', method: 'token', credentialId: '<sha256>', expiresAt, claims: { roles: ['admin'] } }That's the whole API on the hot path: issue, validate, plus refresh / revoke / revokeAllForUser / listForUser for the rest of the lifecycle.
What each page covers
- Credentials & Sessions —
AuthCredential<TClaims>orchestrator: every constructor option, every public method, theAuthContextshape, and howcredentialIdworks as a non-replayable fingerprint. The choice betweenmethod: 'session'andmethod: 'token'. - Tokens (JWT) —
CredentialStoreJwtsetup withjose: algorithm choice (HS* vs. asymmetric), key management, the claim layout, and the algorithm-confusion defense. PlusCredentialStoreEncapsulated(AES-256-GCM) and when to prefer stateless over stateful. - Refresh & Rotation —
RefreshConfigwith all three rotation modes ('none','always','sliding'), the grace window, reuse detection and the user-wide revocation cascade.maxConcurrentenforcement andonLimitstrategies. - Magic Links —
generateMagicLinkToken()andBuildMagicLinkUrl. Storing magic-link tokens asCredentialStatefor atomic single-use consumption. - Password Reset — How the primitives in this package compose into a recovery flow. The same-millisecond epoch gate that enables auto-login after reset. The full workflow lives in
@aooth/auth-moost. - Email & SMS Senders — The
EmailSenderandSmsSendercontracts. The kind unions for templated delivery (recovery.magicLink,mfa.code,login.pincode, etc). - Stores — Implementation matrix for
CredentialStore<TClaims>andDenylistStore:Memory,Redisadapter, atscript-db adapter (with the shipped.asmodel), and how to write your own. - Errors —
AuthErrorand every variant ofAuthErrorTypewith trigger, payload and recommended HTTP mapping.
Installation
pnpm add @aooth/auth josejose is a hard peer dependency only when you use CredentialStoreJwt. The other stores have no extra peers. For the Redis or atscript-db adapter, add the relevant client:
# Redis adapter
pnpm add @aooth/auth ioredis
# atscript-db adapter
pnpm add @aooth/auth @atscript/dbConventions used across these pages
- All TTLs are in milliseconds. JWT
iat/expare seconds (RFC 7519), but the store mirrors them at ms precision in a customstateclaim — see Tokens. TClaimsis a free generic parameter onAuthCredential<TClaims>,CredentialStore<TClaims>andCredentialState<TClaims>. Pick a single shape per app and keep it stable.CredentialMetadatais open to TypeScript declaration merging. Augment it withdeclare module '@aooth/auth'to type your IP / UA / fingerprint / label keys end-to-end.- The package never returns secrets through
validate—AuthContext.credentialIdissha256(accessToken), not the token itself.