Skip to content

@aooth/auth-moost API Reference ​

Complete export reference for @aooth/auth-moost. See the Moost Integration Guide, AuthGuard & useAuth, REST Controllers, and Workflows for narrative documentation.

Subpath exports: . (main, ESM-only), ./atscript (bundled form models, ESM-only), ./atscript/models + ./atscript/models.as.

Classes ​

AuthWorkflow ​

ts
@Inherit()
@Controller() // SINGLETON
class AuthWorkflow {
  constructor(
    opts: Partial<AuthWorkflowOpts>,
    users: UserService,
    auth: AuthCredential,
    consentStore: ConsentStore,
  );
}

The single unified workflow class. Replaces the former LoginWorkflow / RecoveryWorkflow / InviteWorkflow quartet. Declares six @Workflow methods — four @Public(), two ARBAC-gated authenticated self-service flows (no @Public(); guarded by @ArbacResource("auth.change-password" | "auth.add-mfa") @ArbacAction("self") and excluded from DEFAULT_AUTH_WORKFLOWS):

MethodWorkflow idCovers
loginFlowauth/login/flowlogin (password, SSO or magic link) + MFA + enrollment + finalize
inviteFlowauth/invite/startadmin invite → anonymous magic-link accept
recoveryFlowauth/recovery/flowmagic-link or OTP password reset
signupFlowauth/signup/flowverify-first self-signup → set password → auto-login
changePasswordFlowauth/change-password/flowsigned-in password change (gated, POST /auth/change-password)
addMfaFlowauth/add-mfa/flowsigned-in MFA management (gated, POST /auth/add-mfa)

AuthWorkflowOpts is infrastructure-only; policy lives on protected resolveXxx(ctx) getters (each paired with a @Step("prepare-<group>")). Per-flow code discriminates by ctx-slot presence (ctx.admin / ctx.accept / ctx.postReset / ctx.signup / ctx.changePassword / ctx.addMfa), never a flow-name field. Subclass with @Inherit() @Controller(), re-declare the 4-arg constructor (so TS emits design:paramtypes), override the hooks you need, and bind via setReplaceRegistry([AuthWorkflow, MyAuth]). See Workflows and packages/auth-moost/CLAUDE.md.

Protected override surface (defaults are no-ops or hardcoded policy):

  • deliver(payload: AuthDeliveryPayload): void | Promise<void> — outbound dispatch for direct sends (MFA / recovery / enroll pincodes, new-device notice, security alerts). Route by payload.kind + payload.channel. NOT used for the invite magic link (emitted via the wf outlet). There is no audit() method.
  • magicLinkAddress(ctx, link): Promise<string | undefined> — where a recovery or sign-in magic link goes: the typed address for recovery M1 (email channel), else the account's proven inbox (account.verifiedEmail, then a confirmed email MFA method); undefined sends nothing. The account must be active; a sign-in link also needs UserService.assertCanSignIn to pass. magicLinkBrowserCookie(): string names the opt-in browser-binding cookie (default aooth_magic_link, set when resolveAlternateCredentials returns magicLinkSameBrowser: true). See Magic links.
  • sendSecurityAlert(ctx: AuthWfCtx, reason: string, context?: Record<string, unknown>): Promise<void> — the blessed one-call alert path for risk overrides (e.g. impossible-travel from resolveRiskStepUp): emits a security-alert payload through deliver(). Recipient is ctx.notice.email (the proven-first correspondence chain); silent no-op when no provable inbox exists. Never called by the base class. See Geo anomalies & impossible travel.
  • resolveXxx(ctx: AuthWfCtx) policy getters — the override seam for context-varying policy. Return T | Promise<T> (never async on the default). The set: resolveDeviceTrust, resolveMfaPolicy, resolveEnrollment, resolveSessionPolicy, resolveFinalize, resolveGuards, resolveLockout, resolveAlternateCredentials, resolveSignupPolicy, resolveChangePasswordPolicy, resolveOtpDisclosure, resolveRiskStepUp, resolveRedirect, resolveRecoveryUrl, resolveRecoveryAltActions, resolveAdminForm, resolveAccept, resolvePostReset, resolvePincodeForm / resolvePincodeTarget (in recovery also called for an unknown or inactive identifier, with the placeholder subject 00000000-0000-4000-8000-000000000000; its result or error is discarded there) / resolvePincodeAltAction, resolveRecoveryChannel (M1 OTP transport for the typed identifier), resolveRecoveryDeliverySource (M1 typed vs M2 registered), resolveRecoveryDeliveryMode (recovery by one-time code 'otp' — default —, magic link 'magicLink', or the user's pick 'choice'; see Magic links), resolvePromoteHandleField (confirmed channel → login-handle column), resolveEnrollPreConfirmed (ctx-first extra args (ctx, method, address) — vouch a verified-by-construction enrolment address so enroll-send skips the pincode and enroll-confirm writes the confirmed factor with no code-entry pause; default false, see Pre-seeded enrolment), resolveEnrollAddress (ctx-first (ctx, method) — return a string to pin the sms/email enrolment address so the free-text form never renders, 'collect' (default) to keep it; see Pin the enrolment address), resolveTotpAccountLabel (the account half of the authenticator's "issuer: account" TOTP label, baked into the otpauth:// URI at provisioning time; default ctx.email, else the stored username), resolveStepUpConfirmBeforeSend (whether the manage-MFA step-up pauses for explicit consent before dispatching its sms/email pincode; default true — see Manage MFA), resolveLockedMfaTransports, resolveFederatedEmailTrust (does a provider's email claim count as correspondence inbox proof — default trusts exactly email_verified === true; see Where security notices go), resolveAuthzReauthPolicy (returns AuthzReauthPolicy { mode: 'consent-only' | 'always-reauth'; maxSessionAgeMs?; requireMfa? } — whether an authorization-server login with a live browser session skips straight to the consent screen; consulted inline by init-login on authz STARTs only; default { mode: 'always-reauth' }, see Consent-only for live sessions). resolveSignupPolicy returns { allowSignup, collectUsername } — allowSignup defaults false (self-signup off / invite-only); prepareUser is shared with invite (signup passes empty roles + no invitedBy). The sync helper selectRecoveryRegisteredMethod(user) (not a resolveXxx) picks the M2 OTP recipient (SMS-first, then email). Recovery-channel / handle-promotion seams are documented in Phone, recovery channels & handle promotion.
  • claimCodeSend(target: string, account?: string): Promise<boolean> — the server-side gate a custom code send calls before minting: answers 429 AOOTH_CODE_LIMIT_REACHED once the destination's failure budget is spent (this client IP's, or all IPs' together), applies aooth.send-user when account is given, and claims this client IP's resend wait plus a slot of the destination's send cap (pincodeMaxSendsGlobal) — false means "inside the wait or past the cap: mint, send nothing". mintPin(ctx, binding, length?, ttlMs?) / verifyPin(ctx, code, binding, target) mint and check the code (length and TTL default to mfa.pincodeLength / mfa.pincodeTtlMs). See one-time codes.
  • pincodeKey(): Buffer — key of the one-time code digests. Default: the key WfTriggerProvider derives from its pincodeSecret() for the request, else the same key a default provider derives (a subkey of auth.deriveStateKey("wf-state"), never the state secret itself), so a code minted on one path verifies on the other. Outside a provider, a credential store with no derivable secret throws INVALID_CONFIG. Override it when the workflow runs outside a WfTriggerProvider whose wfStateSecret() or pincodeSecret() is overridden: return that provider's key. Every instance must return the same key.
  • getAvailableRoles(): string[] | undefined — selectable role whitelist for the admin invite form (default undefined = no whitelist).
  • duplicateInviteCheck(input: { email: string; existingUser: UserCredentials | null; invitedBy?: string; app?: Record<string, unknown>; form?: Record<string, unknown>; pending?: { invitedBy?: string } }): 'allow' | 'reject' | 'reuse' | Promise<…> — structural duplicate rule for the invite admin form. Default: a pendingInvitation row → 'reuse' (re-invite: the row's roles/extras are replaced, a fresh full-TTL link is dispatched and every earlier link answers 410 INVITE_REPLACED), any other existing row → 'reject', none → 'allow'. pending.invitedBy is the issuer of the invite already on the row (compare with invitedBy to refuse cross-issuer takeovers). See Invites — re-invites.
  • resolveInviteContext(ctx: AuthWfCtx, startFormData: Record<string, unknown> | undefined): Record<string, unknown> | undefined | Promise<…> — since 0.2. App context of an invite (e.g. { tenantId }), resolved at init-invite-admin from the trigger's start input ({ wfid, input: { formData } }); kept server-side as ctx.admin.app. Throw an HttpError to refuse. Default undefined. See Invites.
  • validateChosenUsername(ctx: AuthWfCtx, username: string): AoothMessageCode | undefined — since 0.2. Policy for inviteUsername: 'choose', applied to the normalised (NFKC, trimmed) pick; return a code (e.g. "USERNAME_NOT_ALLOWED") to refuse. Default: ≤ 256 characters, no whitespace / control characters, no @ unless it is the invited address. See Invites.
  • prepareUser(input: { email?: string; roles: string[]; invitedBy?: string; app?: Record<string, unknown>; form?: Record<string, unknown> }) / inferAdminRoles(input: { email: string; invitedBy?: string; app?: Record<string, unknown>; form?: Record<string, unknown> }) — invite / signup row extras and server-derived invite roles. app = the resolveInviteContext result, form = extra fields of an extended forms.invite (both since 0.2). A falsy prepareUser result means "no extras".
  • resolveSetPasswordCopy(ctx): SetPasswordCopy | Promise<SetPasswordCopy> — the set-password screen's heading and intro: { heading?, intro?, headingCode?, introCode? }. Default (since 0.2.5): the SET_PASSWORD_* codes, rendered per response in the request's language; heading / intro text you return is shown as is and wins over the codes. See Messages.
  • msg(code: AoothMessageCode, params?: AoothMessageParams): string — since 0.2. Resolves every user-facing text: opts.messages, then the moost translator in the request's locale (since 0.2.5), then the English template; override for full control. See Messages.
  • loadActiveSessionsCount(username) — async data fetcher for concurrency-limit policy.
  • validateMfaAddress(ctx: AuthWfCtx, method: MfaTransport, value: string): string | undefined | Promise<string | undefined> — server-side validation of the user-typed enrolment address (returned string = the form error). Ctx-first + async-capable so record-based rules (domain allowlists, match-the-account-email) load the row directly. Default: email-shape check / permissive E.164. To pin the address outright use resolveEnrollAddress instead.
  • buildAddMfaFinishEnvelope(ctx): WfFinished — pure construction of finish-add-mfa's outcome envelope (priority: removed → changed → added → blocked → nothing-available → cancelled); override to customize the manage-flow terminal copy/data.
  • Event hooks afterLogin / afterInvitationAccepted / afterSignup / afterPasswordReset / afterPasswordChanged / afterMfaChanged (ctx: AuthWfCtx): void | Promise<void> — fired once at each flow's single completion point (default no-op); awaited, a throw propagates (login hooks fire before delivery → atomic). afterLogin is the record-login funnel every login routes through (interactive / federated / auto-login), firing after account.lastLogin is stamped and before the session/code is issued — it does not fire for the no-session fresh-login redirect, change-password rotation, or an auto-login whose account is no longer active (the auto-login-check step finishes that run without a session). See Workflows — Event hooks.

Error posture — @Step bodies throw exactly two shapes: throw wf.requireInput({ errors, formMessage? }) for retriable input errors (engine re-renders the form under the SAME wfs handle; token survives), and throw new HttpError(<status>, <msg>) for terminal failures (token consumed). See Error patterns.

WfTriggerProvider ​

ts
@Injectable()
class WfTriggerProvider {
  constructor(wf: MoostWf, auth: AuthCredential);
  handle(opts?: WfTriggerOpts): Promise<unknown>; // allow governs start AND resume
  peek(token: string): Promise<WfState | null>; // since 0.2.7 — read a resume token's state, never consumes
  // override seams:
  protected triggerHooks(): WfTriggerHooks; // default {} — app-wide trigger hooks
  protected storeStrategy(): WfStateStrategy;
  protected wfStateSecret(): string | Buffer;
  protected pincodeSecret(): string | Buffer; // default: wfStateSecret() — keys one-time code digests
  protected wfStateEncapsulatedTtlMs(): number | undefined;
  protected magicLinkStore(): WfStateStore; // default: in-memory, one process
  // protected fields:
  protected outlets: WfOutlet[]; // default [HTTP outlet, createInviteOutlet(), createMagicLinkOutlet(…)]
  protected token: WfOutletTokenConfig;
}
ts
type WfTriggerHooks = Pick<
  WfOutletTriggerConfig, // from @moostjs/event-wf
  "around" | "beforePersist" | "renderEnvelope" | "restoreOnError" | "maxRestores"
>;

interface WfTriggerOpts extends WfTriggerHooks {
  allow?: string[]; // start + resume
  resumeOnly?: string[]; // resume only (since 0.2.7)
  block?: string[]; // neither; wins over both (since 0.2.7)
  token?: WfOutletTokenConfig;
}

triggerHooks() returns the workflow-trigger hooks applied to every trigger request; a hook set in handle(opts) / @WfTrigger(opts) replaces the provider's hook of the same name. restoreOnError is opt-in (default off). See Workflows — trigger hooks.

peek(token) (since 0.2.7) reads the paused state behind a resume token without consuming it, resolving the token exactly as a resume does (strategy prefix, hashed handles, strategy tag); unknown, expired, malformed or foreign tokens are null. The state holds server-only context — project it. For invite links use peekInvite.

handle({ allow }) checks the workflow id on start and resume (since 0.2): a wfs minted for a workflow outside allow is refused with 403 before it is consumed. Ids match with or without a leading /; omitted allow = unrestricted, allow: [] = deny every workflow. Since 0.2.7 the wooks trigger judges the registered flow a request resolves to (an onNotFound flow or a parametric route counts as that flow), resumeOnly flows can be resumed but never started, block wins; a refused start is 403 AOOTH_WORKFLOW_NOT_ALLOWED, a refused resume 403 AOOTH_WORKFLOW_RESUME_NOT_ALLOWED (no params). See Workflows — trigger allow lists.

Singleton owning workflow-state persistence, outlets, and the token wire. State is a named-strategy registry, not a single strategy: every workflow starts on the encapsulated strategy (the registry default) — state rides inside the SPA-held token, so an idle login form persists zero server-side rows and a restart can never 410 Gone it. A later step calls swapStrategy('store') to move durable.

A third entry, magic-link (MAGIC_LINK_STRATEGY), holds magic-link pauses: a HandleStateStrategy over magicLinkStore() with hashed handles — override magicLinkStore() with a shared WfStateStore (e.g. AsWfStore) when several instances serve sign-ins (the default is in memory, at most 10,000 links). Every entry is wrapped: a stored state records the strategy that stored it and resumes only through that one (a mismatch answers 410 and consumes nothing), and encapsulated payloads are padded to 256-byte buckets. A stateRegistry() override replaces all of this — keep the wrapping if you override it. The encapsulated and store entries default to EncapsulatedStateStrategy. To make store durable, override storeStrategy() to return a real HandleStateStrategy (there is no this.state field to assign). Pass hashHandles: true so the table holds no resumable handle (aooth hashes only the magic-link pauses itself). The encapsulated secret defaults to auth.deriveStateKey("wf-state") (HKDF-derived, stable across restarts); pincodeSecret() (default: the same secret) keys the one-time code digests and must match across instances. handle() forwards the strategy run-option into wfApp.start/resume — required, or the wf adapter throws Key "wf.strategyName" is not set.

ts
@Injectable()
class MyWfTriggerProvider extends WfTriggerProvider {
  constructor(wf: MoostWf, auth: AuthCredential) {
    super(wf, auth);
    this.outlets = [
      ...this.outlets,
      createAuthEmailOutlet({ emailSender, buildMagicLinkUrl, magicLinkTtlMs }),
    ];
  }
  protected override storeStrategy(): WfStateStrategy {
    return new HandleStateStrategy({ store: new AsWfStore({ table }), hashHandles: true });
  }
}
// app.setReplaceRegistry(createReplaceRegistry([WfTriggerProvider, MyWfTriggerProvider]))

HandleStateStrategy / EncapsulatedStateStrategy / WfStateStrategy come from @moostjs/event-wf; AsWfStore from @atscript/moost-wf. See Workflows — state strategy.

AuthController ​

ts
@Controller("auth")
@ArbacResource("auth")
class AuthController {
  constructor(auth: AuthCredential, @Optional() users?: UserService);
}

REST surface — see REST endpoints below for the seven routes (five @Public(), two ARBAC-gated). users is @Optional(): only GET /auth/invite/post-redemption reads it directly (returns 500 when unset); the other routes work without a UserService on the controller. Subclass and override triggerWf() to extend the workflow allow-list. See REST Controllers.

Protected seams:

ts
protected invitePostRedemptionEnabled(): boolean; // since 0.2 — default true; false → the route 404s for every id
protected resolveInvitePostRedemption(): {
  loginUrl: string;
  alreadyAcceptedRedirectUrl: string;
  messages?: AoothMessages; // since 0.2 — pass the same value as AuthWorkflowOpts.messages
};

SessionsController ​

ts
@Controller("auth")
@ArbacResource("auth.sessions")
class SessionsController {
  constructor(auth: AuthCredential, enricher: SessionEnricherProvider);
}

Optional, opt-in by registration. Mounts GET /auth/sessions (read), GET /auth/sessions/of/:userId (readAny), DELETE /auth/sessions/:sessionId (revoke), DELETE /auth/sessions?others=true (revoke) — all under the auth.sessions ARBAC resource, none @Public(). A bare DELETE /auth/sessions is 400. Both reads take ?kind= — one kind, a comma list (?kind=session,cli-session, since 0.2.7) or *; default: ordinary sessions. Requires a stateful credential store. See Sessions.

SessionEnricherProvider ​

ts
@Injectable() // SINGLETON
class SessionEnricherProvider {
  enrich(session: SessionInfo): EnrichedSession | Promise<EnrichedSession>;
}

Injectable read-time enricher used by SessionsController. Default is identity (aooth ships no UA/geo). Subclass + setReplaceRegistry([SessionEnricherProvider, MyEnricher]) to add device / browser / os / location. See Sessions.

ConsentStore ​

ts
@Injectable() // SINGLETON
class ConsentStore {
  getPendingConsents(username: string | undefined): Promise<ConsentDescriptor[]>;
  save(username: string, events: ConsentEvent[]): Promise<void>;
  read(username: string, filter?: { id?: string }): Promise<ConsentEvent[]>;
  recordOtpChannelConsent(
    username: string,
    channel: "email" | "sms",
    target: string,
    disclosure: string,
  ): Promise<void>;
}

interface ConsentDescriptor {
  id: string;
  text: string; // markdown links allowed
  required?: string; // non-empty ⇒ mandatory; the string IS the error message
  version?: string;
}

interface ConsentEvent {
  id: string;
  accepted: boolean; // false rows are persisted too (audit-grade "was asked")
  version?: string;
  at: number;
}

Customer-overridable DI seam for the consent universe + persistence. All four methods are no-op defaults — extend the class and register the replacement via setReplaceRegistry([ConsentStore, MyConsentStore]). getPendingConsents is user-scoped only — its argument is the stable user id (the workflow passes ctx.subject), and the returned set must NOT vary by workflow or channel; OTP channel-ownership disclosures are recorded separately via recordOtpChannelConsent. Pending descriptors are transported to the SPA carrier form (via @wf.context.pass) and rendered by the AsConsentArray component. See Workflows — ConsentStore.

Functions ​

authGuardInterceptor ​

ts
function authGuardInterceptor(opts?: AuthOptions): TInterceptorFn;

Factory returning a defineBeforeInterceptor at TInterceptorPriority.GUARD. HTTP-only (no-op on WF/CLI/WS). Resolves AuthOptions once and stashes onto the event slot — every later useAuth() reads from the same slot. Bearer beats cookie when both transports are enabled. On @Public() routes, sets null context and runs the handler. On protected routes, throws HttpError(401). Never auto-refreshes. See AuthGuard & useAuth.

useAuth ​

ts
function useAuth(): AuthBindings;

interface AuthBindings {
  getAuthContext<TPayload>(): AuthContext<TPayload> | null;
  getUserId(): string; // throws HttpError(401)
  isAuthenticated(): boolean;
  getSessionId(): string | undefined; // "this device" — AuthContext.sessionId
  // Session facade, scoped to the current user (see Sessions):
  listSessions(opts?: { enrich?: SessionEnricher }): Promise<SessionInfo[] | EnrichedSession[]>;
  revokeSession(sessionId: string): Promise<void>;
  revokeOtherSessions(): Promise<number>; // throws HttpError(401) if no current session
  readonly options: ResolvedAuthOptions; // throws HttpError(500) if guard missing
  extractToken(): string | undefined;
  writeCookies(issue: IssueResult): void;
  clearCookies(): void;
  buildLoginResponse(userId: string, issue: IssueResult): AuthLoginResponse;
  buildFinishedCookies(issue: IssueResult): WfFinishedResponse["cookies"];
  cookieAttrs(extra?: Partial<CookieAttrs>): CookieAttrs;
}

defineWook returning per-event memoized bindings. The options getter throws HttpError(500) if no authGuardInterceptor is on the chain — configuration error, not runtime fallback. buildLoginResponse populates token fields only when exposeTokensInBody is on (default !enableCookie; before 0.2 it followed enableBearer). writeCookies / buildFinishedCookies add a Max-Age for cookies configured persistent. The session facade (listSessions / revokeSession / revokeOtherSessions) resolves the guard-stashed AuthCredential; calling it off-request throws HttpError(500). See AuthGuard & useAuth and Sessions.

getAuthMate ​

ts
function getAuthMate(): Mate<TAuthMeta>;
interface TAuthMeta {
  authPublic?: boolean;
}

Shared moost Mate typed with TAuthMeta. Declaration-merged into TMoostMetadata. See Decorators.

rateLimitInterceptors ​

ts
function rateLimitInterceptors(opts?: RateLimitInterceptorOptions): TInterceptorDef[];

interface RateLimitInterceptorOptions {
  limiter?: RateLimiter; // default: memory-store limiter created once per factory call
  rules?: RateLimitRuleInput[]; // app-wide defaults for routes without @RateLimit metadata
  key?: RateLimitKeyStrategy; // default 'ip'
  /** @deprecated since 0.2.7, removed in 0.3 — set trustProxy on the HTTP app. Still honoured: true = one hop, app's proxyHeaders (one-time warning) */
  trustProxy?: boolean;
  headers?: boolean; // default true — draft RateLimit-* headers
  message?: string; // app-wide default 429 template
  policies?: Record<string, RateLimitRuleInput | RateLimitRuleInput[] | false>; // by policy id: replace rules, or false = off
}

Factory returning the enforcement pair — a BEFORE_GUARD interceptor for 'ip' / custom-keyed policies and an AFTER_GUARD one for named-subject ('user' / 'auto' / 'session' / …) policies; a route with stacked policies of both kinds is checked by both. Register with a spread: app.applyGlobalInterceptors(...rateLimitInterceptors(opts)). HTTP-only; emits RateLimit-* (+ Retry-After on rejection) and throws HttpError(429) whose body carries code: "RATE_LIMITED" and params: { policy, limit, window, retryAfter } (seconds; policy = the policy id) next to the rendered message. policies re-tunes declared policies by id (the decorator's id, else the default <Class>.<method> scope) — new rules replace the declared ones, false switches one off; parsed eagerly, an empty list throws. 'ip' keys use the client IP the HTTP app resolves (useRequest().getIp()) — configure proxies there (client IP behind a proxy). See Rate Limiting and Bundled limits.

useRateLimit ​

ts
function useRateLimit(): RateLimitBindings;

interface RateLimitBindings {
  decision: RateLimitDecision | null; // governing decision across policies; null: no rules / all skipped / interceptors absent
}

Reads the decision the interceptor stored on the event slot. Plain function (not a cached wook); workflow child events inherit the HTTP parent's slot. See Rate Limiting.

setRateLimitSubject / getRateLimitSubject ​

ts
function setRateLimitSubject(kind: string, subject: string, ctx?: EventContext): void;
function getRateLimitSubject(kind: string, ctx?: EventContext): string | undefined;

The named-subject seam: GUARD-priority code (a custom IAM, tenant resolver, API-key gateway) supplies the caller identity for routes keyed by kind; the post-guard rate-limit phase reads it. Values are used verbatim as the counter subject (include your own prefix). The map is read first, so an explicit write always wins over the built-in user (u:<userId>) / session (s:<sessionId>) kinds, which derive from the auth context when the map is empty. See Rate Limiting — the subject seam.

getRateLimitMate ​

ts
function getRateLimitMate(): Mate<TRateLimitMeta>;
interface TRateLimitMeta {
  // since 0.2 — one entry per stacked @RateLimit, in source order; rules normalized at decoration time
  rateLimitPolicies?: Array<{ rules: RateLimitRule[]; options?: RateLimitDecoratorOptions }>;
  rateLimitDisabled?: boolean; // @RateLimit(false)
}

Shared moost Mate typed with TRateLimitMeta. Since 0.2 rateLimitPolicies replaces rateLimitRules / rateLimitOptions — only code that reads the metadata directly is affected. Declaration-merged into TMoostMetadata. See Decorators.

createAuthEmailOutlet ​

ts
interface AuthEmailOutletDeps {
  emailSender: EmailSender;
  buildMagicLinkUrl: BuildMagicLinkUrl; // (kind, token, ctx?: { userId? }) => string
  magicLinkTtlMs: (kind: AuthEmailKind) => number;
}
function createAuthEmailOutlet(deps: AuthEmailOutletDeps): WfOutlet;

Builds the email outlet that delivers the invite magic link under the default inviteDelivery: 'outlet-email', and the recovery / sign-in magic links (recovery.magicLink / login.magicLink, via the magic-link outlet). Wraps @atscript/moost-wf's outlet primitive and translates workflow tokens into AuthEmailEvent payloads via the consumer's EmailSender + BuildMagicLinkUrl. The buildMagicLinkUrl callback receives a third { userId } arg for the invite kind (used by the post-redemption side route). Add to WfTriggerProvider.outlets. See Workflows.

createInviteOutlet / INVITE_OUTLET ​

ts
const INVITE_OUTLET = "invite";
function createInviteOutlet(): WfOutlet;

Since 0.2. The outlet AuthWorkflow pauses on for inviteDelivery: 'deliver' | 'return-link' — it turns the resume token into the link via inviteLinkUrl and delivers it or returns it to the issuer. WfTriggerProvider registers it by default; include it yourself only if you replace this.outlets. See Invites — delivery modes.

peekInvite ​

ts
function peekInvite(
  token: string,
  deps: { trigger: WfTriggerProvider; users: UserService },
): Promise<InvitePeek | null>;

interface InvitePeek {
  email: string;
  invitedBy?: string; // issuer's user id
  roles?: string[];
  expiresAt?: number; // ms since epoch
}

Since 0.2.7. Reads an invite link's token without consuming it and returns a safe projection, or null for an unknown / expired / non-invite token and for an invite that was replaced, accepted or revoked. No bundled route — mount one and rate-limit it. See Invites — showing what a link is for.

ts
const MAGIC_LINK_OUTLET = "magic-link";
const MAGIC_LINK_STRATEGY = "magic-link";
function createMagicLinkOutlet(emailOutlet: () => WfOutlet | undefined): WfOutlet;

Since 0.2.6. The outlet AuthWorkflow pauses on to send a recovery or sign-in magic link: it hands the link to the email outlet when the step decided to send, and answers { sent: true, outlet: "email" } in every case (sent, not sent, or a logged delivery failure). It throws when no email outlet is registered. WfTriggerProvider registers it by default; include it yourself only if you replace this.outlets. MAGIC_LINK_STRATEGY is the state-strategy name the link pauses are persisted under.

Workflow helpers ​

ts
function parseInviteRoles(input?: string[]): string[]; // trim + dedupe role ids
function stripReservedUserKeys(profile: Record<string, unknown>): Record<string, unknown>;
const RESERVED_USER_KEYS: ReadonlySet<string>; // keys profile forms must never carry
function humanizeUserAgent(ua: string | undefined): string | undefined; // "Safari on macOS" — seen-device labels
function haversineKm(a: { lat: number; lon: number }, b: { lat: number; lon: number }): number; // great-circle km (WGS84 mean radius) — impossible-travel thresholds
function buildInviteAlreadyAcceptedEnvelope(opts: {
  loginUrl: string;
  alreadyAcceptedRedirectUrl: string;
  messages?: AoothMessages; // since 0.2
}): FinishWfOpts; // shared "already accepted" finish envelope

Exported so subclasses (and AuthController.invitePostRedemption) reuse the same role parsing, mass-assignment guard, and idempotent-redirect envelope.

Messages ​

ts
const AOOTH_MESSAGES: { readonly INVALID_CREDENTIALS: "Invalid credentials" /* … every code */ };
type AoothMessageCode = keyof typeof AOOTH_MESSAGES;
type AoothMessageParams = Readonly<Record<string, string | number>>;
type AoothMessages =
  | Partial<Record<AoothMessageCode, string>>
  | ((code: AoothMessageCode, params: AoothMessageParams) => string | undefined);
function renderAoothMessage(template: string, params?: AoothMessageParams): string;
function resolveAoothMessage(
  code: AoothMessageCode,
  params?: AoothMessageParams,
  messages?: AoothMessages,
): string;

Since 0.2. The code-keyed catalogue of every user-facing AuthWorkflow text (English templates with {name} placeholders) and the lookup helpers. renderAoothMessage fills placeholders (unknown ones are kept); resolveAoothMessage applies messages (map or resolver; undefined from a resolver falls through), then — inside a request, since 0.2.5 — the moost translator in the request's locale, then the English template. Pass overrides as AuthWorkflowOpts.messages. Registered with moost's registerMessages on import (since 0.2.5). Code list and usage: Messages & Localization.

ts
const AOOTH_HTTP_MESSAGES: { readonly AOOTH_AUTH_REQUIRED: "Unauthorized" /* … every code */ };
type AoothHttpMessageCode = keyof typeof AOOTH_HTTP_MESSAGES;

Since 0.2.5. English templates of the coded HttpErrors auth-moost raises outside the workflow (guard, controllers, useAuth(), workflow trigger, rate limiter); each body carries code and params. Registered with registerMessages on import; MoostHttp translates the bodies by code. See Error bodies.

userAuthErrorToHttp / userAuthErrorInterceptor ​

ts
function userAuthErrorToHttp(err: UserAuthError): HttpError<UserAuthErrorBody>;
const userAuthErrorInterceptor: TInterceptorDef; // CATCH_ERROR priority

interface UserAuthErrorBody {
  message: string;
  code: UserAuthErrorType; // the UserAuthError type
  params?: Record<string, unknown>; // POLICY_VIOLATION: { policies: [{ description, passed, errorMessage, code?, params? }] }
  field?: "currentPassword" | "newPassword" | "confirmPassword";
}

Map a UserAuthError from UserService to a coded 4xx HttpError; the interceptor answers every UserAuthError a handler throws with it (other errors pass through). Status table: User errors — HTTP mapping.

deriveWfStateSecret ​

ts
function deriveWfStateSecret(secret: string): Buffer;

SHA-256-derives the exact 32-byte key EncapsulatedStateStrategy requires from an arbitrary-length app secret. Override WfTriggerProvider.wfStateSecret() with deriveWfStateSecret(env.MY_SECRET) when the credential store has no reusable secret to HKDF-derive from (i.e. the atscript-db store, the recommended default for Sessions). Deterministic — stable across restarts. See Workflows.

generateMagicLinkToken ​

Re-exported from @aooth/auth — see @aooth/auth API.

Decorators ​

@Public ​

ts
function Public(): ClassDecorator & MethodDecorator;

Writes both authPublic=true AND arbacPublic=true. Bypasses both the auth guard and the ARBAC interceptor. You cannot ARBAC-gate an @Public() route — splitting them into two decorators was a deliberately-rejected design. See Decorators.

@UserId ​

ts
function UserId(): ParameterDecorator;

Parameter decorator delegating to Resolve(() => useAuth().getUserId()). Throws HttpError(401) if no auth context. There is no @User() counterpart — AuthContext is credential context only, not a user record. See Decorators.

@AuthGuarded ​

ts
function AuthGuarded(opts?: AuthOptions): ClassDecorator & MethodDecorator;

Sugar for @Intercept(authGuardInterceptor(opts)). Attaches the guard to a single controller instead of globally. See AuthGuard & useAuth.

@RateLimit ​

ts
function RateLimit(disabled: false): ClassDecorator & MethodDecorator;
function RateLimit(
  ...rulesAndOpts: [RateLimitRuleInput, ...Array<RateLimitRuleInput | RateLimitDecoratorOptions>]
): ClassDecorator & MethodDecorator;

interface RateLimitDecoratorOptions {
  // 'ip' | 'user' | 'auto' | 'session' | 'refresh-token' | any named subject kind
  // | () => string | null | undefined | Promise<…>  (null / undefined = skip this policy)
  key?: RateLimitKeyStrategy;
  message?: string; // default 429 template for rules without an inline one
  id?: string; // shared bucket id; default scope '<ControllerClass>.<methodName>'
}

Metadata-only rule declaration; variadic rules with an optional trailing options object (detected by the absence of a limit key). Each decorator is one policy (own key strategy + bucket); stacking several on one target declares independent policies that must all pass (since 0.2 — before, the last one replaced the others). Method-level policies replace class-level ones. Rules parse eagerly — bad grammar throws at boot. Enforced by rateLimitInterceptors / @RateLimited. See Rate Limiting.

@RateLimited ​

ts
function RateLimited(opts?: RateLimitInterceptorOptions): ClassDecorator & MethodDecorator;

Attaches the rateLimitInterceptors(opts) pair via two @Intercepts — the AuthGuarded counterpart. Safe alongside a global registration that uses the same limiter (each scope is checked once per event per limiter). See Rate Limiting.

@WfTrigger ​

ts
function WfTrigger(opts?: WfTriggerOpts): MethodDecorator;

Method decorator wrapping defineAfterInterceptor at INTERCEPTOR priority. When the handler returns undefined, the interceptor instantiates WfTriggerProvider and replies with provider.handle(opts). opts.allow lists the workflow ids the route may start and resume (omitted = unrestricted, [] = deny all; since 0.2). Return a non-undefined value from the handler to short-circuit. opts.token overrides the provider's default wire (WfOutletTokenConfig from @moostjs/event-wf). The trigger hooks (around, beforePersist, renderEnvelope, restoreOnError, maxRestores) set here apply to this route only. Re-decorating an inherited handler (under @Inherit()) replaces the base route's options as a whole; the trigger still runs once per request (override semantics). See Workflows and trigger hooks.

REST endpoints ​

AuthController mounts seven routes — five @Public(), two ARBAC-gated authenticated self-service flows:

MethodPathBody / QueryResponseNotes
POST/auth/logoutAuthLogoutBodyAuthOkResponse@Public(). Defence-in-depth 401 on null context. Revokes this session's whole token family (revokeSession), token-level revokes as fallback.
POST/auth/refreshAuthRefreshBodyAuthLoginResponse@Public(). Falls back to refresh cookie. 401 on AuthError. Tokens in the body only under exposeTokensInBody. Rate limited: aooth.refresh 150/5m per IP, aooth.refresh-token 10/1m per presented token (bundled limits).
GET/auth/status—AuthContext@Public(). 401 when no context.
POST/auth/trigger{ wfs?, input?: { action?, formData? } }WfFinished envelope@Public() @WfTrigger({ allow: DEFAULT_AUTH_WORKFLOWS }). Single entry-point for the public schemas (login / invite / recovery / signup).
GET/auth/invite/post-redemption?uid=<userId>WfFinished envelope@Public() @RateLimit("30/5m", { id: "aooth.invite-post-redemption" }). Idempotent "already accepted" envelope for re-clicked invite links. Unknown id and pending invite → the same 404. Needs UserService.
POST/auth/change-password{ wfs?, input?: { action?, formData? } }WfFinished envelopeGated — @ArbacResource("auth.change-password") @ArbacAction("self") @WfTrigger({ allow: [CHANGE_PASSWORD_WORKFLOW] }). 401/403 before handler.
POST/auth/add-mfa{ wfs?, input?: { action?, formData? } }WfFinished envelopeGated — @ArbacResource("auth.add-mfa") @ArbacAction("self") @WfTrigger({ allow: [ADD_MFA_WORKFLOW] }). Authenticated "Manage MFA" flow (add / change / remove, step-up first).

See REST Controllers.

Constants ​

DEFAULT_AUTH_WORKFLOWS ​

ts
const DEFAULT_AUTH_WORKFLOWS = [
  "auth/login/flow",
  "auth/invite/start",
  "auth/recovery/flow",
  "auth/signup/flow",
] as const;

Default allow list for @WfTrigger on AuthController.triggerWf(). Subclasses override triggerWf() with a different @WfTrigger({ allow }) to extend. See REST Controllers.

CHANGE_PASSWORD_WORKFLOW / ADD_MFA_WORKFLOW ​

ts
const CHANGE_PASSWORD_WORKFLOW = "auth/change-password/flow";
const ADD_MFA_WORKFLOW = "auth/add-mfa/flow";

Workflow ids for the two gated self-service flows, exported separately and deliberately excluded from DEFAULT_AUTH_WORKFLOWS. Each is the sole entry on its own route's @WfTrigger({ allow }) (POST /auth/change-password, POST /auth/add-mfa), so neither is reachable from the public /auth/trigger. Enable a flow by granting its ARBAC resource (allow("auth.change-password", "*") / allow("auth.add-mfa", "*")); omit the grant to disable it entirely — the privilege is the switch. See Workflows — Change password and Add MFA method.

DTOs ​

AuthLogoutBody / AuthRefreshBody ​

ts
interface AuthLogoutBody {
  refreshToken?: string;
}
interface AuthRefreshBody {
  refreshToken?: string;
}

The refresh cookie's narrow /auth/refresh path means it is NOT auto-sent to /auth/logout. Explicit body field falls back to cookie. See REST Controllers.

AuthLoginResponse ​

ts
interface AuthLoginResponse {
  userId: string;
  accessExpiresAt: number;
  refreshExpiresAt?: number;
  accessToken?: string; // only when exposeTokensInBody (default !enableCookie)
  refreshToken?: string; // same
}

Token fields are present only when the guard's exposeTokensInBody is on — by default only when cookies are off. Since 0.2; before, they followed enableBearer. See REST Controllers.

AuthOkResponse ​

ts
interface AuthOkResponse {
  ok: true;
}

Used by /auth/logout. See REST Controllers.

Workflow option + payload types ​

AuthWorkflowOpts / ResolvedAuthWorkflowOpts ​

ts
interface AuthWorkflowOpts {
  autoLoginOnInvite?: boolean; // default true
  autoLoginOnRecover?: boolean; // default false
  mfa?: {
    pincodeLength?: number; // 6
    pincodeTtlMs?: number; // 5 min
    pincodeResendTimeoutMs?: number; // 60s
    pincodeMaxAttempts?: number; // 5
    pincodeMaxFailures?: number; // 10 — wrong codes per destination and client IP, across its codes
    pincodeMaxFailuresGlobal?: number; // 100 — per destination, all IPs together
    pincodeMaxSendsGlobal?: number; // 10 — codes sent per destination, all IPs together
    pincodeFailureWindowMs?: number; // 1h
  };
  recoveryStateTtlMs?: number; // 1h
  magicLinkTtlMs?: number; // 15 min — recovery / sign-in magic links (since 0.2.6)
  loginUrl?: string; // '/login'
  totpIssuer?: string; // 'aooth'
  deviceTrust?: { cookieName?: string; ttlMs?: number; bindsTo?: "cookie" | "cookie+ip" };
  deviceRecognition?: {
    cookieName?: string; // `${deviceTrust.cookieName}_seen` → 'aooth_trusted_device_seen'
    ttlMs?: number; // 180 days
    maxDevices?: number; // 5 — `seenDevices` ledger cap, LRU-evicted beyond it
  };
  // ── since 0.2 ──
  inviteDelivery?: "outlet-email" | "deliver" | "return-link"; // default 'outlet-email'
  inviteLinkUrl?: (token: string, info: { userId?: string }) => string; // required by 'deliver' / 'return-link'
  inviteUsername?: "email" | "choose"; // default 'email'
  messages?: AoothMessages; // partial map or (code, params) => text | undefined
  lockoutDisclosure?: "uniform" | "generic" | "reveal"; // default 'uniform'
  lockoutShadowStore?: RateLimitStore; // default: one process-wide memory store — also the magic-link send cooldown and the one-time code attempt counters
  forms?: {
    /* one TAtscriptAnnotatedType slot per bundled form (incl. inviteChooseUsername, recoveryModeSelect, magicLinkRequest) */
  };
}

Infrastructure-only. Every field is optional; the constructor runs mergeAuthWorkflowOpts(opts) to produce a fully-populated ResolvedAuthWorkflowOpts read as this.opts.<group>.<field> without optional chaining. Policy NEVER lives here — if a knob varies by request/tenant/user it belongs on a resolveXxx(ctx) getter. Replace any bundled form per-slot via opts.forms.<field>. See Workflows and Config Reference.

inviteDelivery / inviteLinkUrl / inviteUsername — see Invites. messages — see Messages. lockoutDisclosure decides whether a failed sign-in on an unknown handle can read "Account locked" ('uniform', a shadow counter in lockoutShadowStore — share it across instances), never does ('generic'), or only real locks do ('reveal', the pre-0.2 behaviour); see lockout disclosure. lockoutShadowStore also counts the attempts of every one-time code (mfa.pincodeMaxAttempts) — with several instances it must be shared.

deviceRecognition configures the always-on recognition cookie + seenDevices ledger — a notification suppressor only, never an MFA bypass (that is deviceTrust, which stays opt-in and strict). Recognition is cookie-only by design (never IP-bound) and requires deviceTrust.secret on the UserService — without it the device-recognition step silently no-ops. See Device recognition.

AuthDeliveryPayload ​

ts
type AuthDeliveryPayload = (
  | {
      kind: "mfa-pincode";
      channel: "sms" | "email";
      recipient: string;
      code: string;
      expiresInMs: number;
    }
  | {
      kind: "recovery-pincode";
      channel: "email";
      recipient: string;
      code: string;
      expiresInMs: number;
    }
  | {
      kind: "signup-pincode"; // verify-first self-signup email-ownership OTP
      channel: "email";
      recipient: string;
      code: string;
      expiresInMs: number;
    }
  | {
      kind: "enroll-pincode";
      channel: "sms" | "email";
      recipient: string;
      code: string;
      expiresInMs: number;
    }
  | { kind: "invite-link"; channel: "email"; recipient: string; url: string; expiresInMs: number } // inviteDelivery: 'deliver' only
  | {
      kind: "new-device-notice";
      channel: "email";
      recipient: string;
      deviceLabel?: string;
      loginAt: number;
    }
  | {
      kind: "security-alert"; // consumer-triggered (sendSecurityAlert) — never auto-sent
      channel: "email";
      recipient: string;
      reason: string; // machine-readable trigger, e.g. "impossible-travel"
      loginAt: number;
      context?: Record<string, unknown>; // free-form template data (distances, cities)
    }
) & {
  locale?: string; // since 0.2.5 — the sending request's locale
};

The discriminated union passed to AuthWorkflow.deliver(payload). Branch on kind for per-purpose templates and on channel for transport. Every variant carries locale — the locale of the request it is sent from (moost useLocale()), absent when the request has none — so a sender can localize (Localized emails and SMS). See Delivery.

Workflow context types ​

The @wf.context.pass slots and policy-resolver return shapes are exported for typing subclass overrides: AuthWfCtx, AuthWfCompletionState, AuthWfConsentsState, AuthWfMfaEnrollState, AuthWfPasswordUiState, AuthWfPincodeUiState, AuthWfSignupState, ConsentDescriptorLike, MfaSummary, MfaTransport, LoginRedirect, SsoProvider, ConcurrencyLimitOptions. AuthWfCtx has no flow field — discriminate by ctx-slot presence (ctx.admin / ctx.accept / ctx.postReset / ctx.signup).

Re-exports from @aooth/auth ​

Re-exported for convenience so consumers don't need a second import:

Audit types ​

AuditEvent / AuditEmitter ​

ts
interface AuditEvent {
  kind: string;
  userId?: string;
  workflow?: string;
  ip?: string;
  userAgent?: string;
  [k: string]: unknown;
}
interface AuditEmitter {
  emit(event: AuditEvent): Promise<void> | void;
}

These types are exported for consumers who wire their own audit sink. The bundled AuthWorkflow does not fire audit events itself (there is no audit() hook) — emit your own from a subclass step body or an interceptor. See Audit Log.

Config types ​

AuthOptions ​

ts
interface AuthOptions {
  cookie?: {
    name?: string;
    secure?: boolean;
    sameSite?: "lax" | "strict" | "none";
    httpOnly?: boolean;
    path?: string;
    domain?: string;
    persistent?: boolean; // since 0.2 — Max-Age follows the access token's expiry
  };
  refreshCookie?: {
    name?: string;
    path?: string;
    secure?: boolean;
    sameSite?: "lax" | "strict" | "none";
    httpOnly?: boolean;
    domain?: string;
    persistent?: boolean; // since 0.2 — Max-Age follows the refresh token's expiry; not inherited
  };
  enableCookie?: boolean;
  enableBearer?: boolean; // accept Authorization: Bearer on requests
  exposeTokensInBody?: boolean; // since 0.2 — default !enableCookie
}

Defaults: cookie.name='aooth_session', secure=true, sameSite='lax', httpOnly=true, path='/', persistent=false. refreshCookie.path='/auth/refresh' (narrow path), refreshCookie.persistent=false. enableCookie=true, enableBearer=true, exposeTokensInBody=!enableCookie (so false by default — tokens travel only in httpOnly cookies). Bearer wins when both transports are enabled. A persistent cookie's Max-Age is renewed on every rotation. ResolvedAuthCookieConfig / ResolvedAuthOptions are the resolved (defaults-applied) views. See Config Reference.

Federated login (OAuth2 / OIDC) ​

The Moost wiring of @aooth/idp. See Federated Login (OAuth) for the narrative.

OAuthController ​

ts
@Controller("auth/oauth")
class OAuthController {
  // ctor: (registry, auth, users, @Inject(FEDERATED_IDENTITY_STORE_TOKEN) federated)
  identities(): Promise<ConnectedAccount[]>; //                  GET identities        — self-scoped
  link(@Param provider, @Query redirect?): Promise<string>; //   GET :provider/link    — self-scoped, 302
  unlink(@Param provider, @Param subject): Promise<{ ok: true }>; // DELETE :provider/:subject
}

Mounted REST surface for federated ACCOUNT MANAGEMENT — the routes are self-scoped (@Public(), identity from useAuth().getUserId()). Anonymous LOGIN is NOT here: it's the login form's SSO button → AuthWorkflow.beginSso. identities lists the caller's connected accounts; link mints a signed state + PKCE-from-seed and 302s to the provider for an account link; unlink disconnects an identity (last-credential guard, then revokes the user's sessions). The callback is bridged by the SPA into /auth/trigger (auth/login/flow). Subclass to override defaultRedirect() or to add @ArbacAction(...).

ConnectedAccount ​

ts
interface ConnectedAccount {
  provider: string;
  subject: string; // (provider, subject) is the unlink key
  linkedAt: number;
  lastLoginAt?: number;
  email?: string;
  emailVerified?: boolean;
  displayName?: string;
  avatarUrl?: string;
}

Wire shape of GET /auth/oauth/identities — a display projection of a FederatedIdentity row (the surrogate id and the caller's own userId are dropped).

OAuthRuntime ​

ts
@Injectable()
class OAuthRuntime {
  constructor(registry: OAuthProviderRegistry, federated: FederatedLoginService);
}

DI holder bundling the two app-provided federated-login singletons the sso-callback / prove-control steps resolve (via useControllerContext().instantiate(OAuthRuntime)), so AuthWorkflow's ctor stays unchanged.

DI token + HTTP helpers ​

ts
const FEDERATED_IDENTITY_STORE_TOKEN = "aooth:FederatedIdentityStore";
const OAUTH_CSRF_COOKIE = "aooth_oauth";
function oauthCsrfCookieAttrs(opts: {
  secure: boolean;
  maxAgeSec?: number;
  path?: string;
}): TCookieAttributesInput;
function isSafeRelativeRedirect(target: string | undefined): target is string; // open-redirect §7
function resolveOAuthRedirect(requested: string | undefined, fallback: string): string;

The abstract FederatedIdentityStore binds under a string token (moost can't use an abstract class as a class-reference DI token). There is no OAuth flow store — the round-trip is stateless (PKCE verifier + nonce are derived from the signed-state seed, never persisted). OAUTH_CSRF_COOKIE is the Lax double-submit cookie; isSafeRelativeRedirect rejects the §7 open-redirect bypass list (//evil, /\evil, absolute URLs, control chars).

Federated leg of auth/login/flow + ctx.oauth ​

Federated login is merged into auth/login/flow (no separate OAuth workflow). The sso-callback step (condition: !!ctx.idpInbound) runs the verified exchange (verify state + CSRF double-submit + RE-derive verifier from the seed + verified ID-token exchange + resolveUser/linkIdentity + account-state gate); on needs-link it stashes ctx.pendingLink and diverts to the prove-control step (password or OTP-fallback proof, with resend) before setting ctx.subject, then the shared login tail runs. AuthWfCtx.oauth?: AuthWfOAuthState ({ provider, outcome?, isNew?, redirect? }; outcome includes 'interactively-linked') is the flow discriminator.

Authorization server ​

The Moost HTTP layer for the authorization server (aoothjs AS an OAuth/OIDC provider for its own clients). The framework-agnostic stores, policies, signer, and claims resolver live in @aooth/auth/authz. See Authorization Server for the narrative + wiring.

AuthorizeController ​

ts
@Controller("auth")
class AuthorizeController {
  // ctor: (auth, @Inject(CLIENT_REDIRECT_POLICY_TOKEN) policy,
  //        @Inject(PENDING_AUTHORIZATION_STORE_TOKEN) pending,
  //        @Inject(AUTH_CODE_STORE_TOKEN) codes)
  authorize(
    /* @Query response_type, client_id?, redirect_uri, state?, code_challenge,
                code_challenge_method, scope?, nonce?, resource? */
  ): Promise<string>; // GET authorize → 302
  token(
    /* @Body { grant_type, code?, code_verifier?, client_id?, client_secret?,
                   refresh_token?, resource? } */
  ): Promise<TokenSuccess | TokenError>; // POST token
  //   grant_type: "authorization_code" (code + PKCE) or "refresh_token" (rotate)
  discovery(): OidcDiscoveryDocument | TokenError; //   GET .well-known/openid-configuration (Tier 2)
  jwks(): Promise<{ keys: JWK[] }> | TokenError; //     GET jwks                             (Tier 2)
  oauthServerMetadata(): AuthorizationServerMetadata | TokenError; // GET .well-known/oauth-authorization-server
  register(/* @Body RFC 7591 metadata */): Promise<unknown>; //      POST register (404 unless DCR wired)
  //   token + register carry bundled @RateLimit policies (see Rate limits in the guide):
  //   aooth.token 150/5m per IP, aooth.token-refresh 10/1m per refresh_token, aooth.register 20/1h per IP
  // override seams (getters, NOT DI; see below):
  protected getIdTokenSigner(): IdTokenSigner | undefined; //      default: undefined → 404 / no id_token
  protected getOidcClaimsResolver(): OidcClaimsResolver; //        default: NoopOidcClaimsResolver
  protected loginPath(): string; //                               default: "/login"
  protected getIssuer(): string | undefined; //                   default: signer?.issuer — override for signer-less RFC 8414
  protected getDynamicClientRegistration(): DynamicClientRegistration | undefined; // default: undefined → DCR off
  protected scopesSupported(): string[] | undefined; //           default: undefined (RFC 8414 scopes_supported)
}

All routes are @Public(). authorize runs the trust gate (policy.resolveClient) FIRST, records the pending authorization (authority fixed here — incl. the resolved clientName for consent and the RFC 8707 resource, plus a per-request browser-binding secret), drops the aooth_authz binding cookie, and 302s /login?authz=<handle>. A repeated or oversized resource fails soft with error=invalid_target; the trust-gate 400 body is deliberately generic (with self-registered clients, distinguishing invalid_client from invalid_redirect is a client_id-existence oracle). The login workflow's authz-consent step then re-verifies the cookie and requires the user to explicitly approve the client before mint-authz-code mints a code (see Consent gate & browser binding). token with grant_type=authorization_code consumes the single-use code, verifies PKCE, authenticates the client, checks resource consistency (both legs present and different → 400 invalid_target), and mints the access token and/or id_token — off the browser — plus a rotating refresh_token when the grant's TokenPolicy.refresh opted in. With grant_type=refresh_token it authenticates the presenting client, verifies the family's metadata.authzClientId binding BEFORE anything rotates (mismatch / no stamp — e.g. a browser-session refresh token — is 400 invalid_grant with the family untouched), and rotates the pair; replay of an already-rotated token beyond the grace window revokes the whole family. See the refresh grant. discovery / jwks 404 when no signer is wired; oauthServerMetadata is signer-independent (404 only when getIssuer() is undefined) and advertises registration_endpoint when DCR is wired — as does discovery in a combined deployment. register is the RFC 7591 endpoint: JSON-only, 201 echoes all registered (server-narrowed) metadata with client_id_issued_at in seconds; a client_secret_post registration is echoed once with its minted client_secret + client_secret_expires_at: 0 (public clients get no secret fields); ClientRegistrationError → 400 { error, error_description }. See Wiring — MCP connectors.

The optional dependencies are getters, not DI tokens. An optional @Inject/@Optional dependency panics in moost's resolveMoost route-table pass (triggered by AuthController's @MoostInit refresh-cookie hook → "Class is not Injectable and not Optional"). A subclass overrides getIdTokenSigner() / getOidcClaimsResolver() / getIssuer() / getDynamicClientRegistration() / scopesSupported() and is registered in place of the base class (put @Inherit() on it so the routes carry over; if you re-declare the ctor, repeat the same @Inject tokens — a re-declared constructor uses only its own parameter metadata). Never derive getIssuer() from the Host header — the metadata document is cacheable.

AuthorizeRuntime ​

ts
@Injectable()
class AuthorizeRuntime {
  constructor(
    @Inject(PENDING_AUTHORIZATION_STORE_TOKEN) pending: PendingAuthorizationStore,
    @Inject(AUTH_CODE_STORE_TOKEN) codes: AuthCodeStore,
  );
}

DI holder bundling the two stores the login-wf mint-authz-code terminal needs (a @Step body can't @Inject a string token, so it resolves this via useControllerContext().instantiate(AuthorizeRuntime)). Mirrors OAuthRuntime.

DI tokens ​

ts
const CLIENT_REDIRECT_POLICY_TOKEN = "aooth:ClientRedirectPolicy";
const PENDING_AUTHORIZATION_STORE_TOKEN = "aooth:PendingAuthorizationStore";
const AUTH_CODE_STORE_TOKEN = "aooth:AuthCodeStore";
const DYNAMIC_CLIENT_STORE_TOKEN = "aooth:DynamicClientStore";

Provide the concrete ClientRedirectPolicy (a LoopbackClientPolicy, RegisteredClientPolicy, or CompositeClientPolicy) + the two stores under these strings — all abstract/interface deps with no class reference to inject by. DYNAMIC_CLIENT_STORE_TOKEN is for a DCR-enabling subclass: the base controller never injects it (DCR is optional, and an optional @Inject panics — see above); the subclass adds it as a required ctor param, builds a DynamicClientRegistration around it, and overrides the getter.

Discovery / DCR re-exports ​

buildAuthorizationServerMetadata, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, and DynamicClientRegistration (+ their option/document types) are re-exported from @aooth/auth/authz so a consumer can mount the root-level discovery documents (the RFC 8414 path-insertion form + the RFC 9728 PRM) and the 401 challenge from one import. See Root-mounted discovery.

ts
const AUTHZ_BINDING_COOKIE = "aooth_authz";
function authzBindingCookieAttrs(opts: {
  secure: boolean;
  maxAgeSec: number;
}): TCookieAttributesInput;

AuthorizeController sets this httpOnly; SameSite=Lax cookie at /authorize to the per-request binding secret; the authz-consent step constant-time-matches it before minting a code, so an authz handle phished into another browser is inert (parallel to the federated OAUTH_CSRF_COOKIE — the attrs delegate to oauthCsrfCookieAttrs with path=/). The controller passes maxAgeSec derived from the pending row's expiresAt (returned by PendingAuthorizationStore.create), so the cookie tracks the row's lifetime even for a store configured with a non-default ttlMs. Reference the name if a reverse proxy filters cookies by allowlist. Narrative: Consent gate & browser binding.

Subpath: @aooth/auth-moost/atscript ​

ts
import * as forms from "@aooth/auth-moost/atscript";

Re-exports the 29 bundled form types from src/atscript/models/forms.as:

WithInlineConsentForm (base), LoginCredentialsForm, MfaCodeForm, EmailIdentifierForm, SignupForm, SetPasswordForm, ChangePasswordForm, InviteForm, Select2faForm, PincodeForm, AskEmailForm, AskPhoneForm, EnrollPickMethodForm, EnrollAddressForm, EnrollTotpQrForm, EnrollConfirmForm, ManageMfaForm, RemoveMfaConfirmForm, PasswordReauthForm, StepUpConfirmForm (the manage step-up dispatch-consent notice — Manage MFA), TermsBumpForm, ConcurrencyLimitForm, MagicLinkRequestForm, MagicLinkConfirmForm (the landing step of a clicked magic link), RecoveryModeSelectForm, ProveControlForm, ProveControlOtpForm, AuthorizeConsentForm (the authorization-server consent prompt — Consent gate).

Several forms carry @ui.form.component annotations pointing at SPA components from @atscript/vue-aooth: WithInlineConsentForm.consents → AsConsentArray, SetPasswordForm.passwordRules → AsPasswordRules, EnrollConfirmForm.qrCode → AsQrCode. Replace any form per-workflow via opts.forms.<field> (typically extends the bundled one). See Atscript Models and SPA Components.

Released under the MIT License.