Skip to content
Back to skills

Server Auth Email

ASecurity

How to use @owlmeans/server-auth-email — the server half of OwlMeans e-mail sign-in. appendEmailAuth / appendEmailAuthResources / serveEmailAuthEntrypoints; the PIN and password sign-in through PRIVATE auth plugins run by makeAuthModel's exclusive list; tokens stamped email-pin / email-password carrying a short spend key; remembered devices (hashed browser id, 30 days, newest 10); the new-device PIN (deployment default devicePin, per-account switch confirmed by a mailed PIN); scrypt passwords...

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 9, 2026
developmenttypescriptrustgonodetestingdebuggingapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 14, 2026

npx -y skills add owlmeans/common --skill server-auth-email --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Server Auth Email?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Server Auth Email
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/owlmeans-server-auth-email/badge)](https://www.skillsdirectory.com/skills/owlmeans-server-auth-email)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: server-auth-email
description: How to use @owlmeans/server-auth-email — the server half of OwlMeans e-mail sign-in. appendEmailAuth / appendEmailAuthResources / serveEmailAuthEntrypoints; the PIN and password sign-in through PRIVATE auth plugins run by makeAuthModel's exclusive list; tokens stamped email-pin / email-password carrying a short spend key; remembered devices (hashed browser id, 30 days, newest 10); the new-device PIN (deployment default devicePin, per-account switch confirmed by a mailed PIN); scrypt passwords; the strict captcha; throttles; the offer ticket; email-confirm confirmations; the developer tech routes (PIN rewrite, captcha/throttle waiver) behind GUARD_ED25519 and a signer allowlist; localized PIN mails. Auto-invoked when wiring e-mail sign-in into a server context, changing its routes, flags, stores or throttles, or debugging a refused e-mail sign-in.
user-invocable: false
---

# @owlmeans/server-auth-email

**Layer:** Server (L10)
**Install:** `"@owlmeans/server-auth-email": "^0.2.0-alpha.0"` in `dependencies` (`mongodb` peer)
**Contracts:** `@owlmeans/auth-email` (tree, schemas, constants) · **Browser:** `@owlmeans/web-auth-email`

## Wiring

```typescript
// shared package: the guest routes unguarded, the password routes behind the app's session
export const emailAuthProtocols = makeEmailAuthProtocols({ guards: [DEFAULT_GUARD], gate: { alias: APP_GATE } })

// server context — AUTH_SRV_KEY trusted record (with its secret) and a shared AUTH_CACHE first
context.registerResource(makeRedisResource('app-email-auth'))
context.registerService(makeRedisOtpChallengeStore('app-email-challenges', 'app-email-auth'))
context.registerService(makeRedisThrottleService('app-email-throttle', 'app-email-auth'))
context.registerService(myMailer)                                   // the alias cfg.otp.mailerAlias names
context.cfg.otp = { mailerAlias, challengeStoreAlias: 'app-email-challenges', identityAlias }   // NO throttleRules
context.registerService(makeOtpService())
appendEmailAuthResources(context, AUTH_IDENTITY_DB_ALIAS)
appendRecaptcha(context, { secret, siteKey })                       // a captcha provider (connect), only when captcha is on
appendEmailAuth(context, {
  password: true,
  devicePin: true,                                                 // false = a password alone signs a new device in
  captcha: { provider: RECAPTCHA_PROVIDER, hostnames, minScore },  // null = off
  tech: { enabled: () => cfg.debug?.supervisor === true, signers: ['shared-key'] },
  ipOf: req => clientIpOf(req),
  throttleAlias: 'app-email-throttle',
  ticketResourceAlias: 'app-email-auth',
})

// API process
context.registerEntrypoints(serveEmailAuthEntrypoints(emailAuthProtocols))
```

- `serveEmailAuthEntrypoints` binds the three parent routes and every server route, whatever the
  flags: the password routes answer `EmailPasswordDisabled` and the tech routes `EmailTechDisabled`
  (both 404) while off. The `offer` screen is the browser's. The new-device PIN switch is the tree's
  `password.devicePin` (`POST /password/device-pin`, `EMAIL_AUTH_PASSWORD_DEVICE_PIN`), bound like
  every other password route.
- **Never set `cfg.otp.throttleRules`** on the OTP service this package uses: the OTP service would
  then throttle every issuance itself, under a developer waiver too. This package throttles each
  route on its own keys.
- Give it stores of its own (Redis resource, challenge store, throttle, mail alias) when the process
  also hosts another OTP flow — an IAM's `OTP_RESOURCE` or a guest-route throttle must not share
  windows with sign-in.
- `appendEmailAuthResources` registers Mongo `auth-email:password` (`email-password`, `accountId`
  unique) and `auth-email:device` (`email-device`, `(accountId, key)` unique, TTL on `expiresAt`) —
  usually on the identity store's db config, whose `resourcePrefix` prefixes the collections too.

## Options — `EmailAuthServerOptions`

| Option | Default | Meaning |
|---|---|---|
| `password` | off | `true` or `{ minLength?, maxLength? }` (8…128, NFKC, not the address) |
| `captcha` | off | `CaptchaSettings` (`provider?`, `hostnames`, `minScore` — no keys) — built into `makeCaptchaCheck` at the service's init, after mounted paths resolve; the provider it names (or the only one) must be registered in the captcha host, or init fails |
| `tech` | off | `{ enabled: boolean \| () => boolean, signers }` — `signers` are `TRUSTED` record NAMES; `enabled` re-read per request |
| `ipOf` | none | client address; without it no IP throttles and no `remoteIp` for the captcha |
| `identityAlias` | `cfg.otp.identityAlias ?? AUTH_IDENTITY_LINKING` | the `IdentityLinkingService` |
| `otpAlias` | `OTP_SERVICE` | |
| `throttleAlias` | none | an `AuthThrottleService`; absent = no throttles at all |
| `throttle` | `EMAIL_AUTH_THROTTLE_RULES` | `pinEmail` 1/60 s + 10/h, `pinIp` 20/600 s, `pinGlobal` 600/60 s, `passwordEmail` 10/900 s, `passwordIp` 50/900 s, `confirmAccount` 1/60 s + 10/h |
| `ticketResourceAlias` | in-process | Redis resource for offer tickets — required with more than one replica |
| `devices` | `{ ttlDays: 30, limit: 10 }` | |
| `devicePin` | `true` | a password sign-in on a device the account does not remember is answered with a mailed PIN; `false` lets the password alone sign it in. An account's own choice overrides it (below) |
| `mail` | built-in | `{ [purpose]: { [locale]: OtpMessage } }`; purposes `sign-in`, `confirm-set`, `confirm-change`, `confirm-remove`, `confirm-device-pin` |

## Invariants

- **Private plugins.** Each sign-in runs `makeAuthModel(ctx, { plugins })`
  (`@owlmeans/server-auth/manager`) with this request's `email-pin` / `email-password` plugins as an
  EXCLUSIVE list, built per request (device id and resolved account in the closure). They are never
  `registerPlugin`-ed, so the manager's ungated `/authentication/*` cannot reach them, and a
  challenge of a global type (`email-otp`, `pk-supervisor`, `captcha`) is refused here.
- **Token types.** A token is stamped `email-pin` or `email-password` (type, role, scopes, `userId`,
  `profileId`, `entitySlug` all overwritten from the linked identity) — never `email-otp` or
  `one-time-token`, so an integrated IAM's finalizer and gate keep refusing it. The identity
  credential is still `{ type: 'email-otp', service: 'email', userId: <address> }`: OTP and e-mail
  sign-in land on ONE account per address.
- **The token carries a spend key, not the challenge.** The plugins return
  `emailAuthKeyHelper.spendKey(challenge)` — a short digest — as their `token`, which the model
  puts where the challenge would go. The wrapped PIN challenge does not fit the shared 1024-character
  `AuthTokenSchema` the bearer exchange validates; the digest is also the single-use key the
  exchange spends in `AUTH_CACHE`.
- **No oracle.** Send-PIN answers the same for every address. A wrong password and an address with
  no account always get the answer of the deployment's `devicePin`: while it is on, a password
  sign-in on an unknown device answers `{ challenge, reason: 'device' }` without checking the
  password; while it is off, `AuthenFailed('email:password')`. On a known device, "no password" and
  "wrong password" are the same `AuthenFailed('email:password')` after the same scrypt work. Password
  sign-in never registers an account.
- **New-device PIN.** In effect for an account: its own choice (`EmailPasswordRecord.devicePin`), else
  the deployment's `devicePin`. The account's choice counts only behind its correct password: on
  over an off deployment it mails a PIN after that password (the PIN then signs in as any sign-in
  PIN); off over an on deployment its password signs the new device in. The hash is computed before
  the device answer only when the account's choice differs from the deployment's, so the default
  path does no scrypt work. Without a PIN the device is remembered as on a known one. The choice
  survives a password set or change and is dropped with the password. `status` (and every password
  route's status) carries `devicePin` while passwords are on.
- **The switch.** `POST password/device-pin` (`setDevicePin`) needs a set password (else `AuthUnknown`
  `email:unset`, 400). `{ enabled }` mails a confirmation PIN (purpose `device-pin`, mail
  `confirm-device-pin`, throttle `confirmAccount`) and answers `{ challenge }`; `{ enabled, challenge,
  pin }` stores the choice and answers `{ status }`. Only one of `challenge` and `pin` → 400.
- **Order per request:** IP and global throttles → captcha → per-address throttle → account and
  device lookup → scrypt. A failed captcha never spends a person's per-address budget.
- **Captcha.** `options` advertises the provider's own `clientSettings()` (`{ provider, siteKey }`,
  the browser picks its client by `provider`) or `null` when off. A refused token is `captcha:<reason>`
  → `EmailVerificationRefused` (403); a missing provider or incomplete settings
  `AuthUnavailable('captcha:config')` (503) — and, at boot, settings whose provider is not registered
  stop the service's init. There is no built-in provider.
- **Devices.** Key `sha256("{accountId}:{device id}")` (the browser's id is never stored); remembered
  only inside a successful sign-in; reads filter `expiresAt > now`; upsert then trim to the newest
  `limit`. A password set, change or removal forgets every other device but the request's `device`;
  sessions are NOT revoked.
- **Passwords.** `node:crypto` scrypt N=2^15 r=8 p=1, 32-byte key, 16-byte salt, 64 MB `maxmem`,
  stored `scrypt$32768$8$1$<salt>$<key>` (base64url), compared with `timingSafeEqual`.
- **Confirmations.** `password.pin` mails a PIN to the ACCOUNT's own address and answers an
  `email-confirm` envelope (signed with `AUTH_SRV_KEY`) binding purpose, account, address and the
  PIN's issuance, living as long as the PIN. `set` accepts it with purpose `set` when no password
  exists, `change` when one does; `remove` with `remove`; the switch only its own `device-pin`
  confirmation, which `password.pin` never mails. A sign-in challenge is no confirmation and
  vice versa. Refusals are `EmailVerificationRefused` (403 — never 401, so a signed-in client keeps
  its session).
- **Offer ticket.** 32 random bytes, stored as a digest, bound to its account for 15 minutes,
  returned only by a PIN sign-in of an account with no password that has not declined; spent once by
  `set` (no PIN) or `decline`, and only while the account still has no password. Another account's
  attempt leaves it unspent.
- **Developer routes.** `GUARD_ED25519` + the `EMAIL_AUTH_TECH_GATE` gate: Service role, signer
  name in `tech.signers`, `tech.enabled` true at that moment. `tech.pin` rewrites the PIN of a
  pending sign-in or confirmation challenge (`OtpService.rewriteChallenge`: lifetime kept, attempts
  reset). `tech.waiver` signs an `email-waiver` envelope (~2 h) sent in `x-owlmeans-email-waiver`:
  honoured only while tech is on, it skips the captcha and the send/password/confirm throttles —
  never the five-attempt PIN limit — and `options` answers `captcha: null` under it.
- **Mails.** Templates per purpose × `EMAIL_AUTH_LOCALES`, chosen by the request's validated
  `locale` (primary subtag), default `en`. A subject never carries `{{code}}`: console mailers log
  subjects and lock screens show them.
- **Logs** carry an address's domain only — never a PIN, password, device id, waiver or token.
  Events `auth.email.*` (password set/changed/removed, `device-pin-on` / `device-pin-off` and waiver
  issued at `info`, the rest — `device-trusted` for an unknown device let in without a PIN — `debug`)
  beside `makeAuthModel`'s `auth.signed-in` / `auth.refused`.

## Refusals

Guest routes: wrong PIN, password or challenge → `EmailCredentialRefused` (`AuthenFailed`, 401);
refused captcha or confirmation → `EmailVerificationRefused` (403); throttled → `OtpThrottled` (429,
`retryAfter`); not exactly one sign-in mode, or a challenge of another method → `AuthUnknown` (400);
the `auth-email` errors (404 / 409 / 422 / 503) as the contracts package lists them.

## Tests

`bun test ./tests`: unit specs over memory stores and a stand-in captcha provider registered in the
captcha host (`ensureCaptchaService(ctx).register(…)`); `mongo.spec.ts`
and `redis.spec.ts` are env-gated (`mongoGate` / `redisGate`, `/testing-integration`) — devices, TTL
filter, rotation, password records, Redis tickets and OTP rewrite. Signed tech calls are made with
`signBasicEd25519Request` (`auth-common`).

## Related

`auth-email` · `web-auth-email` · `server-auth` (`makeAuthModel` options) · `server-auth-otp` (the
message and rewrite seams) · `captcha` · `server-auth-identity` (linking) · `test-ui`
(`makeEmailTechClient`, `loginViaEmailForm`)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.