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:
challengeIdidentifies the challengesecretis kept by your app and submitted during verificationcodeis the one-time code you deliver to the user by email
How it works
Section titled “How it works”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)
- Your app calls
createMailboxChallengewith an email address and a purpose such assignup,login, oremail-change. - Passlock returns a challenge containing
challengeId,secret,code, and a renderedmessagewithhtmlandtextcontent. - Your app stores
challengeIdandsecretin an HTTP-only cookie or server-side session, then emails the code to the user. Send the renderedmessagecontent, or use the rawcodeto generate your own message. - The user enters the code into your app.
- Your app calls
verifyMailboxChallengewithchallengeId,secret, andcode. - Passlock returns a readable challenge payload that excludes the secret and code. Your app should still validate the challenge
purposeand any expected local user before completing the flow.
Why doesn’t Passlock email the codes?
Section titled “Why doesn’t Passlock email the codes?”Passlock does everything apart from actually sending the email. There are a few reasons for this:
- The email should come from your domain - users should immediately recognise the sender. Security emails sent “on behalf of” are a red flag.
- 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.
- 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.
Next steps
Section titled “Next steps”- [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/serverfunction reference - REST API mailbox challenges - raw HTTP requests and response shapes