Twilio Verify login
Log in with a Twilio Verify code, then test an expired code, a canceled verification and too many attempts.
Try it in the demo.
The situation: your app logs people in, or confirms phone numbers, with Twilio Verify. The happy path is easy; an expired code or too many wrong tries are not.
You need: your app's Twilio client pointing at http://127.0.0.1:8026. The Verify service SID your app uses can be created in SMS > Verify > Services (or the seed file).
Steps
- In your app, start a login with a phone number. A row appears in SMS > Verify with the code and "Expires in ..." counting down. The code also arrives as an SMS in SMS.
- Copy the code and enter it in your app. The row turns Approved and your app logs in.
- Start another login. Open the row and press Expire. Enter the old code in your app: the check fails as Twilio fails it.
- Start another and press Max attempts, or enter wrong codes until the attempt limit. Your app should stop accepting codes.
For automated tests
Give the service a fixed code: in Services, edit it and set Fixed code (optional) to 123456. Every verification then uses that code, so your tests can type it without reading anything.
In your code
A test that starts a login, expires the code and checks your app refuses it.
The examples call SendMock's REST API with each language's usual HTTP client and test framework. JavaScript, Go, Java, Rust, Ruby and C# use the small call helper shown under Test helper on their page in Connect your app.
# In your app: start a login for +8801700000000
pending=$(sendmock verify list --to +8801700000000 --status pending --limit 1 --json)
verification=$(jq '.items[0]' <<<"$pending")
expired=$(sendmock verify force "$(jq -r '.sid' <<<"$verification")" expired --json)
# In your app: enter the old code; your app should refuse it
jq -e '.status == "expired"' <<<"$expired" >/dev/nullWhat you should see
Approved, expired and max-attempts rows in Verify, each with its timeline, and your app's matching messages.
Try it in the demo
- Open SMS > Verify and click a Pending verification.
- In the drawer, press Expire. The status changes to Expired and the timeline records it.