Skip to content

Mailbox challenges / one time authentication codes

Passlock can issue mailbox challenges for email-based one-time code flows. They work well for email verification, account management and account recovery scenarios. They can also be used for passwordless login if passkeys are not available/supported.

Each challenge has three important values:

  • challengeId identifies the challenge
  • secret is kept by your app and submitted during verification
  • code is the one-time code you deliver to the user by email

High level overview of the mailbox challenge flow.

sequenceDiagram
  Actor User as 
  participant WebApp
  participant Server as @passlock/server

  User->>WebApp: signup
  WebApp->>Server: create challenge
  Server-->>WebApp: code, secret
  WebApp->>WebApp: save secret in session
  WebApp-)User: email code to user
  User->>WebApp: enter code
  WebApp->>WebApp: lookup session secret
  WebApp->>Server: verify challenge (code, secret)
  1. Your app calls createMailboxChallenge with an email address and a purpose such as signup, login, or email-change.
  2. Passlock returns a challenge containing challengeId, secret, code, and a rendered message with html and text content.
  3. Your app stores challengeId and secret in an HTTP-only cookie or server-side session, then emails the code to the user. Send the rendered message content, or use the raw code to generate your own message.
  4. The user enters the code into your app.
  5. Your app calls verifyMailboxChallenge with challengeId, secret, and code.
  6. Passlock returns a readable challenge payload that excludes the secret and code. Your app should still validate the challenge purpose and any expected local user before completing the flow.

Passlock does everything apart from actually sending the email. There are a few reasons for this:

  1. The email should come from your domain - users should immediately recognise the sender. Security emails sent “on behalf of” are a red flag.
  2. No need for SPF, DMARC and DKIM changes - if we were to send from your domain you’d need to setup these properties for our servers.
  3. Flexibility - we return HTML and plain text message content. It’s responsive, supports dark mode and is tested in major email clients. We think it’s great, but you might disagree so we give you the flexibility to generate and send your own message content.
  • [Email verification][signup] - verify mailbox ownership before creating or activating an account
  • Passwordless logins - authenticate a user with an emailed one-time code
  • Account management - verify a new mailbox before updating account details
  • Account recovery - recover access when the user can no longer use their passkeys
  • Reference - detailed @passlock/server function reference
  • REST API mailbox challenges - raw HTTP requests and response shapes