Skip to content

Config Reference ​

This page is the complete configuration reference for the Moost integration layer: AuthOptions (consumed by authGuardInterceptor, useAuth, the AuthController) plus the AuthWorkflow configuration model. The workflow has two configuration layers — infrastructure on AuthWorkflowOpts, and security policy on protected resolveXxx(ctx) getters. Full signatures live in the API reference; the override mechanics are in Workflows.

AuthOptions ​

ts
import type { AuthOptions } from "@aooth/auth-moost";

app.applyGlobalInterceptors(
  authGuardInterceptor({
    cookie: { secure: false, sameSite: "lax" },
    // "Stay signed in": the refresh cookie survives a browser restart.
    refreshCookie: { persistent: true },
  }),
);
FieldDefaultNotes
cookie.name'aooth_session'Access cookie name.
cookie.securetrueHTTPS-only — flip to false for local HTTP dev.
cookie.sameSite'lax''lax' | 'strict' | 'none'.
cookie.httpOnlytrueJS access to the cookie is blocked.
cookie.path'/'Sent on every request.
cookie.domainundefinedDefaults to the request host.
cookie.persistentfalsetrue → the cookie gets a Max-Age equal to the access token's remaining lifetime (renewed on every issue). false → a session cookie, gone when the browser closes. See persistent cookies.
refreshCookie.name'aooth_refresh'Refresh cookie name.
refreshCookie.pathauto-derived ('/auth/refresh')Narrow path so the refresh cookie isn't sent on other endpoints — CSRF-resistance. Auto-derived from AuthController's actual mounted route (see note below); set explicitly to override.
refreshCookie.secureinherited from cookie.secure
refreshCookie.sameSiteinherited from cookie.sameSite
refreshCookie.httpOnlyinherited from cookie.httpOnly
refreshCookie.domaininherited from cookie.domain
refreshCookie.persistentfalse (not inherited)true → Max-Age follows the refresh token's expiry and is renewed on every rotation.
enableCookietrueMaster switch for cookie transport. When false, writeCookies / clearCookies are no-ops.
enableBearertrueWhether requests may authenticate with Authorization: Bearer. When both transports are on, bearer wins. Does not decide whether tokens appear in response bodies — that is exposeTokensInBody.
exposeTokensInBody!enableCookiePut accessToken / refreshToken into JSON bodies (login finish data, POST /auth/refresh). With the default cookie transport this is false: tokens travel only in httpOnly cookies, so an XSS that calls /auth/refresh cannot read a fresh refresh token.

Since 0.2: no tokens in response bodies under the cookie default

Before 0.2 the login-finish data and the POST /auth/refresh body carried accessToken / refreshToken whenever enableBearer was true (the default). They are now governed by exposeTokensInBody, which defaults to !enableCookie — so a default cookie deployment returns only userId, accessExpiresAt and refreshExpiresAt. A token client (CLI, mobile app) that sends its refresh token in the POST /auth/refresh body always gets the rotated pair back in the body — it already holds token material, so this exposes nothing new. If such a client also needs tokens from the login finish, set exposeTokensInBody: true, or mount a second guard for those routes with enableCookie: false (which flips the default back to true).

Persistent cookies ("stay signed in") ​

Both cookies are session cookies by default. For an installed PWA or a "keep me signed in" device, make the refresh cookie persistent and pair it with sliding refresh rotation on AuthCredential:

ts
authGuardInterceptor({ refreshCookie: { persistent: true } });

new AuthCredential({
  store,
  accessTtl: 15 * 60_000,
  refresh: { ttl: 90 * 24 * 60 * 60_000, rotation: "sliding" },
});

The access cookie can stay session-only: after a browser restart the first request gets a 401 and createAuthedFetch refreshes silently from the persistent refresh cookie. persistent is not inherited from cookie to refreshCookie — set it where you want it. When POST /auth/refresh refuses the refresh cookie it clears both cookies, so a dead refresh cookie never outlives its session. For installed PWAs and mobile web apps also raise rotationGraceMs — see Refresh — mobile and home-screen web apps. See Refresh for the rotation modes.

The refresh-cookie path follows the controller's mount prefix automatically

You don't set refreshCookie.path by hand. The auth guard resolves it once at boot from Moost's route table — it finds AuthController's actual refresh route and scopes the cookie to it. Mount the controller at the root (@Controller("auth") → /auth/refresh) or under a prefix (registerControllers(['api/auth', AuthController]) → /api/auth/refresh) and the cookie path tracks it, so the browser always sends the refresh cookie to the real endpoint.

Subclassed AuthControllers resolve via the prototype chain. If the route can't be resolved unambiguously (no AuthController registered, or it's mounted more than once), the guard keeps the /auth/refresh default and logs a boot-time warning naming the mismatch — it never guesses. Setting refreshCookie.path explicitly always wins and skips derivation.

Narrow refresh cookie path is deliberate

Browsers don't send the refresh cookie to any path outside its scoped path by default. That's why /auth/logout revokes the whole session family by sessionId (it can't read the refresh cookie) and only accepts a body refreshToken as a fallback. Widening the path (e.g. to /) removes the CSRF-resistance benefit, and the refresh cookie is now exposed on every request.

CSRF is your responsibility

The package does NOT bundle a CSRF strategy. SameSite=Lax on the access cookie is the default sole defence. For sensitive endpoints, add a CSRF-token interceptor that compares a custom header against a double-submitted cookie, or switch to SameSite=Strict. The bundled refresh cookie's narrow path is a CSRF mitigation specifically for token rotation, not a general defence.

AuthWorkflowOpts — infrastructure knobs ​

Infrastructure-only configuration passed to the AuthWorkflow constructor. Every field is optional; defaults are applied by mergeAuthWorkflowOpts. Security policy is NOT here — see the resolver table below. Full shape: API reference.

FieldDefaultNotes
autoLoginOnInvitetrueIssue tokens directly after invite acceptance (vs redirect to fresh login).
autoLoginOnRecoverfalseIssue tokens directly after password reset (vs redirect to fresh login).
mfa.pincodeLength6OTP digit count. 6 is OWASP-standard.
mfa.pincodeTtlMs5 * 60_000OTP code lifetime. Shorter = stronger.
mfa.pincodeResendTimeoutMs60_000Resend wait per destination and client IP, counted on the server.
mfa.pincodeMaxAttempts5Wrong-code submissions per sent code before it is used up — counted on the server in lockoutShadowStore. See one-time codes.
mfa.pincodeMaxFailures10Wrong codes per destination and client IP across all its codes before every send and check from that IP answers 429 AOOTH_CODE_LIMIT_REACHED. See one-time codes.
mfa.pincodeMaxFailuresGlobal100Wrong codes per destination from all IPs together before every send and check answers 429 AOOTH_CODE_LIMIT_REACHED.
mfa.pincodeMaxSendsGlobal10Codes sent per destination from all IPs together per pincodeFailureWindowMs; past it a request sends nothing. Caps mail-bombing and SMS pumping spread over many IPs.
mfa.pincodeFailureWindowMs60 * 60_000Window of pincodeMaxFailures, from the first wrong code.
recoveryStateTtlMs60 * 60_000Caps the window between OTP request and password reset (applied at every recovery pause).
magicLinkTtlMs15 * 60_000Lifetime of a recovery or sign-in magic link (single use either way).
loginUrl'/login'Canonical sign-in URL (post-accept / abort-to-login / post-reset redirects).
totpIssuer'aooth'TOTP provisioning issuer label (the QR's issuer).
deviceTrust.cookieName'aooth_trusted_device'Trusted-device cookie name.
deviceTrust.ttlMs24 * 60 * 60_000Trusted-device cookie + record TTL.
deviceTrust.bindsTo'cookie''cookie' or 'cookie+ip' (stricter — IP change invalidates trust).
deviceRecognition.cookieName<deviceTrust.cookieName>_seenAlways-on recognition cookie (notification suppression only — never an MFA bypass).
deviceRecognition.ttlMs180 * 24 * 60 * 60_000Recognition cookie + record TTL (slid on every verified login).
deviceRecognition.maxDevices5Per-user seenDevices ledger cap — LRU-evicted beyond it. See Device recognition.
inviteDelivery'outlet-email'How the invite link reaches the invitee: email outlet, deliver(), or 'return-link' to the issuer. See Invites.
inviteLinkUrl—(token, { userId }) => string — builds the link for 'deliver' / 'return-link' (required there).
inviteUsername'email''choose' — the invitee picks the login username at accept. See Invites.
messagesEnglish AOOTH_MESSAGESPartial map or (code, params) => text resolver for every user-facing text; wins over the moost translator. See Messages.
lockoutDisclosure'uniform' (since 0.2)What a failed sign-in reveals about locks: 'uniform' / 'generic' / 'reveal'. See lockout disclosure.
lockoutShadowStoreprocess-wide memory storeRateLimitStore for 'uniform''s shadow counters, the magic-link send cooldown and the one-time code attempt counters — pass a shared store (Redis) with several instances.
forms.<slot>bundled .as defaultsReplace any bundled form schema with your own atscript type. See Atscript Models.

Security policy — resolveXxx(ctx) getters, not opts ​

Everything that varies by request / tenant / user is a protected resolveXxx(ctx) method on AuthWorkflow, overridden in a subclass (see Workflows — policy model). Defaults below are the hardcoded resolver bodies.

ResolverDefault postureSecurity implication
resolveMfaPolicy{ mode: 'optional', availableTransports: ['sms','email','totp'] }mode: 'required' forces MFA; restrict availableTransports to drop a channel.
resolveEnrollment{ ensureEmail: false, ensurePhone: false }Force a confirmed email/phone before login completes.
resolveDeviceTrust{ enabled: false, optIn: true, skipsMfa: true }Off by default. When enabled, a trusted device skips the MFA loop unless skipsMfa: false.
resolveSessionPolicy{} — unlimitedReturn { concurrencyLimit: { max, onLimit } } to cap active sessions ('reject' vs 'kickPrompt').
resolveLockout{ mode: 'temporary' }'admin-only' for privileged accounts (lock never self-expires); 'self-service' allows reset to unlock.
resolveGuards{ passwordInitial: true, passwordExpiry: true }Force a password change on first login / expiry; add emailVerifiedRequired.
resolveFinalize{ notifyNewDevice: false, redirect: false }Fire a new-device notice (suppressed on recognized devices); set a post-login redirect target.
resolveOtpDisclosuregeneric TCPA/PECR/CASL/GDPR-safe copy per channelCustomize the disclosure paragraph shown beside the email/phone input.
resolvePostReset / resolveRecoveryAltActionspost-reset = revoke-sessions + redirectControl session revocation + redirect after a recovery reset.
resolveAdminForm / resolveAcceptinvite admin form / accept-phase policyInvite role whitelist (getAvailableRoles), post-accept confirmation + redirect.

Reset must revoke sibling sessions

A password reset that leaves other sessions valid is a known credential-theft-recovery weakness. The bundled recovery flow revokes the user's other sessions after a reset; if you override resolvePostReset, preserve that behavior in production.

There is no audit.enabled knob

The bundled AuthWorkflow does not emit audit events itself. The AuditEvent / AuditEmitter types are exported for wiring your own sink — see Audit Log.

CSRF — explicit non-feature ​

The package does not bundle a CSRF strategy:

Default defenceImplication
Access cookie SameSite=LaxForm-based CSRF works for GET-style flows but not POST from third-party origins. Most real CSRF is mitigated.
Refresh cookie path /auth/refreshRefresh cookie isn't sent on non-refresh endpoints. Protects token rotation specifically.
Bearer transportBearer tokens require explicit Authorization header — immune to CSRF entirely.

Consumers building public, browser-facing apps with cookie transport SHOULD add a CSRF-token interceptor that:

  1. Sets a non-HttpOnly cookie carrying a per-session CSRF token.
  2. Requires every POST / PUT / PATCH / DELETE to include the token in a custom header.
  3. Compares the header value against the cookie value.

This is a five-line interceptor and is best left to the consumer because the token-store backend (in-memory vs Redis vs JWT-derived) varies per deployment.

ResolvedAuthOptions — what useAuth().options returns ​

resolveAuthOptions(opts) merges the user-provided opts with the defaults table above, then attaches the resolved object to the event slot. useAuth().options returns this fully-merged shape:

ts
interface ResolvedAuthOptions {
  cookie: { name; secure; sameSite; httpOnly; path; domain?; persistent };
  refreshCookie: { name; secure; sameSite; httpOnly; path; domain?; persistent };
  enableCookie: boolean;
  enableBearer: boolean;
  exposeTokensInBody: boolean;
}

All fields are present and non-optional in the resolved shape. The refreshCookie.* fields that inherit from cookie.* at config time are resolved to their concrete values at factory time.

See also ​

Released under the MIT License.