Verifying user contact details
Verifying user contact details
Contents
- Overview
- Verification methods
- Enabling verification for a chain
- Verifying an email address with a one-time passcode
- Verifying an email address with a verification link
- Verifying a phone number
- Verification status fields
- Rate limits and code validity
- Related pages
Overview
A user account holds two contact details which can be confirmed as belonging to the account holder:
- the user's email address, held in the
usernamefield - the user's phone number, held in the
phone_numberfield
Verification confirms that the person using the account actually controls the address or number on it. This matters for password resets, transactional messaging, marketing consent and for de-duplicating accounts.
Each contact detail has its own verification status field on the user (email_status and phone_number_status),
and each is verified through its own delivery channel: email addresses are verified by email, phone numbers by SMS.
Verification is always started by the client application (for example your webshop, app or the Spaaza white-label
mobile app) on behalf of a signed-in user, and is enabled per business.
Verification methods
| Contact detail | Method | Delivered by | Endpoints |
|---|---|---|---|
| Email address | One-time passcode | otp-request then otp-verify | |
| Email address | Verification link | email-verify-request then email-verify | |
| Phone number | One-time passcode | SMS | otp-request then otp-verify |
A one-time passcode ("OTP") is a 6-digit code which the user reads from the message and types back into your application, which then submits it to Spaaza. A verification link is a signed, single-use link which verifies the address when the user opens it, with nothing for the user to type.
Enabling verification for a chain
Verification is switched on per chain, and the chain setting is the single source of truth for which flow applies. Both settings can be read with get-chain and set with alter-chain:
| Setting | Values | Effect |
|---|---|---|
email_verification_method | off, otp or deeplink | Selects the email verification flow. off (the default) disables email verification. |
verify_phone_numbers | true or false | Enables phone number verification by SMS OTP. Default is false. |
Because the chain setting is enforced by the endpoints, a chain configured for otp cannot use the verification-link
endpoints, and a chain configured for deeplink cannot use the email OTP purpose on otp-request.
Requests to the wrong flow are rejected with the email_verification_not_enabled error (code 559). Clients can read
email_verification_method from get-chain to decide which flow to present to the user.
Sending the messages themselves also has to be configured for the chain: the verification email and SMS messages are delivered by Spaaza's notification service, and SMS additionally requires an SMS provider (see SMS Service Integrations). Contact Spaaza to have email or SMS verification switched on for your business.
Verifying an email address with a one-time passcode
Used when the chain's email_verification_method is otp.
- Request a code. Call otp-request with
purposeset toemail_verification_rate_limit, the user'semail, anduser_idandchain_id. The email address supplied must match the email address on the account. The response contains averification_code_key, the expiry date of the code, and the number of seconds until another code can be requested. - Spaaza emails the code. The user receives an email containing the 6-digit code.
- Verify the code. Collect the code from the user and call otp-verify with the
verification_codeand theverification_code_keyfrom step 1. On success the user'semail_statusis set to1(verified).
Verifying an email address with a verification link
Used when the chain's email_verification_method is deeplink.
- Request a verification email. Call email-verify-request with
user_idandchain_id. No email address is passed: the address used is the one on the account. - Spaaza emails the link. The user receives an email containing a "Verify email" button. The link carries a signed, single-use verification token, is valid for 3 days, and points at a Spaaza verification page which completes the flow.
- Verify the link. The page which the user lands on calls email-verify with the user's
usernameand the token from the link. On success the user'semail_statusis set to1(verified).
Requesting a new verification email does not invalidate links from earlier emails: each link stays valid until it is used or expires.
Verifying a phone number
Used when the chain has verify_phone_numbers enabled. The flow is the same OTP flow as for email addresses, with the
code delivered by SMS:
- A phone number is saved. When add-user or alter-user stores a new or changed
phone number for a chain with verification enabled, the response includes a
phone_resultsobject containing averification_code_key, and Spaaza sends a verification code by SMS. - Request a further code if needed. Call otp-request with
purposeset tophone_number_verification_rate_limit, the number ine164PhoneNumber, anduser_idandchain_id. - Verify the code. Call otp-verify with the
verification_codeandverification_code_key. On success the user'sphone_number_statusis set to3(verified).
For the SMS providers available and how sending is configured, see SMS Service Integrations.
Verification is separate from uniqueness. A chain can also require that a phone number is used by only one account, by
setting require_unique_phone_number to true with alter-chain. When that setting is enabled,
add-user and alter-user reject a phone number which is already held by another
active account with the phone_number_already_exists error (code 555), instead of only flagging it through
phone_number_duplicate. There is no equivalent setting for email addresses, because a duplicate email address
(username) is always rejected with the user_already_exists error (code 234).
Verification status fields
Both status fields are returned in the user_info object by get-user,
add-user and alter-user.
email_status — integer:
0(unverified) — the email address has not been confirmed by the user. This is the default for new and existing accounts.1(verified) — the email address was confirmed by the user, using either email verification method.
phone_number_status — integer:
0(unchecked) — the phone number has not been validated.1(invalid) — the phone number failed validation (legacy API versions only).2(validated) — the phone number is a valid, correctly formatted number, but has not been confirmed by the user.3(verified) — the phone number was confirmed by the user with an OTP code.
Changing the contact detail resets its status, because a previous verification no longer applies to the new value:
- Changing a user's email address (
username) resetsemail_statusto0. This applies to every way an email address can change, including add-user, alter-user, user imports and webshop synchronisation. - Changing a user's phone number re-evaluates
phone_number_status. Re-submitting the same, already-verified number keeps theVERIFIEDstatus.
Rate limits and code validity
| Limit | Value |
|---|---|
| Requests for a code or verification email | 1 per 60 seconds, counted per contact detail and per user |
| One-time passcode validity | 5 minutes |
| One-time passcode attempts | 5, after which the code is invalidated and a new one is needed |
| Verification link validity | 3 days, single use |
Exceeding the request limit returns email_verification_rate_limit_exceeded (code 557) for email verification, or
phone_number_verification_rate_limit_exceeded (code 548) for phone number verification.
Related pages
| Page | Description |
|---|---|
| otp-request | Request a one-time passcode for an email address or a phone number. |
| otp-verify | Verify a one-time passcode. |
| email-verify-request | Request a verification link to be emailed to a user. |
| email-verify | Verify an email address from a verification link. |
| alter-chain | Configure email_verification_method and verify_phone_numbers for a chain. |
| SMS Service Integrations | SMS providers used to deliver phone number verification codes. |