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 delivered 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 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)
- Your backend calls
createMailboxChallengewith an email address, a purpose such assignup,login, oremail-change, andsendEmail: true - Passlock creates the challenge, sends the email, and returns
challengeId,secret,code, and a renderedmessagewithhtmlandtextcontent - Your backend stores
challengeIdandsecretin an HTTP-only cookie or server-side session - The user enters the code
- Your backend calls
verifyMailboxChallengewithchallengeId,secret, andcode - Passlock returns a response indicating if the challenge response is authentic
Next steps
Section titled “Next steps”- Mailbox verification - 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