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 delivered to the user by email

High level overview of the mailbox challenge flow.

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

  User->>Backend: signup
  Backend->>Server: createMailboxChallenge(sendEmail: true)
  Server-)User: email code to user
  Server-->>Backend: code, secret
  Backend->>Backend: save secret in session
  User->>Backend: enter code
  Backend->>Backend: lookup session secret
  Backend->>Server: verify challenge (id, code, secret)
  1. Your backend calls createMailboxChallenge with an email address, a purpose such as signup, login, or email-change, and sendEmail: true
  2. Passlock creates the challenge, sends the email, and returns challengeId, secret, code, and a rendered message with html and text content
  3. Your backend stores challengeId and secret in an HTTP-only cookie or server-side session
  4. The user enters the code
  5. Your backend calls verifyMailboxChallenge with challengeId, secret, and code
  6. Passlock returns a response indicating if the challenge response is authentic