OTP and Verify
Bonga Verify creates and checks one-time codes without exposing the code to your logs or the browser.
Projects and keys
A project groups challenges and credentials. The sandbox is synthetic and free. Live delivery is limited to approved projects on deployments running the customer preview.
Issuing a project key returns it once. Use it as Authorization: Bearer <key> on the verification routes; a dashboard JWT cannot stand in for a project key.
Start a sandbox challenge
curl -X POST 'https://api.bonga.africa/api/v1/otp/verifications' \
-H "Authorization: Bearer $VERIFY_SANDBOX_KEY" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: signin-4821' \
--data '{
"goal": "email_possession",
"purpose": "sign_in",
"subject_id": "opaque-session-4821",
"destination": { "type": "email", "value": "verify-fixture@example.test" }
}'
The sandbox accepts only email_possession, sign_in and verify-fixture@example.test. The response returns an opaque ver_… ID and an expiry, never the code.
Read the fixture code
The sandbox is deterministic so CI can verify without a mailbox. For the returned ID, compute the expected six-digit code as RFC 4226 HOTP (SHA-1, counter zero, six digits) using the 32-byte SHA-256 digest of the UTF-8 string bonga:verify:sandbox-fixture:v1:<id> as the secret. Leading zeroes are significant.
import hashlib, hmac, struct
def fixture_code(verification_id: str) -> str:
digest = hashlib.sha256(f"bonga:verify:sandbox-fixture:v1:{verification_id}".encode()).digest()
counter = struct.pack(">Q", 0)
mac = hmac.new(digest, counter, hashlib.sha1).digest()
offset = mac[-1] & 0x0F
value = struct.unpack(">I", mac[offset:offset + 4])[0] & 0x7FFFFFFF
return f"{value % 1_000_000:06d}"
This fixture algorithm is for the sandbox only. Never use it for live authentication.
Check
curl -X POST "https://api.bonga.africa/api/v1/otp/verifications/$VERIFICATION_ID/check" \
-H "Authorization: Bearer $VERIFY_SANDBOX_KEY" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: signin-4821-check' \
--data "{\"purpose\":\"sign_in\",\"subject_id\":\"opaque-session-4821\",\"code\":\"$SANDBOX_CODE\"}"
A correct code consumes the challenge. Retrying the same check with the same idempotency key returns its stored result. A new check on a consumed challenge is refused.
Expiry, resend and attempts
- Each challenge has a bounded expiry, five minutes in the sandbox and in the live preview.
- Resend has a 30-second cooldown and a three-handoff cap; each live resend is charged.
- A consumed or cancelled challenge cannot be checked again.
- Supersede and signed terminal-event callbacks are not part of the live preview. They are specified for a later slice; do not build against them yet. Start a new verification instead of superseding one.
Live customer preview
Live delivery is off by default. Request approval in your dashboard, then a Bonga operator approves the project in the admin console. Keep your existing signup or recovery method available until you have confirmed real receipt and successful code checks with controlled destinations.
- In OTP & Verify, create a live project and open its delivery settings.
- Submit a delivery request with the channels you need, an approved brand, the customer email sender (for email) and the destination countries (for SMS).
- A Bonga operator reviews the request and approves an effective policy: channels, brand, a daily limit, the email source and the exact SMS routes. Approval and the reviewer are recorded. A rejected request keeps any existing policy in place.
- Fund the workspace with units for the channel you intend to use. Each start reserves one unit, and each later resend reserves another. A proven-unsent handoff releases its unit; an accepted or uncertain handoff uses it.
- Issue a scoped live key. Store it on your server. Your browser or mobile app should call your own server to start or check a verification.
The approved brand appears in the message text: the SMS reads "<code> is your <brand> verification code. Do not share it.", and the email subject and body use the same brand. Bonga keeps the SMS to a single GSM-7 segment.
Two email sources are available. Customer domain sends from an address on your own verified, Bonga-managed sending domain. Platform sends from Bonga's managed platform sender; it requires managed email delivery to be configured and the from address is chosen for you, so you cannot spoof another identity. When managed email delivery is not configured, the email channel is simply unavailable rather than failing your deployment. SMS always uses an approved managed HTTP route whose sender is assigned to you.
A suspended or revoked project stops delivering immediately: a new start is refused, and a queued handoff that has not yet reached the provider is discarded and its unit released. Editing the policy's daily limit or brand does not invalidate a challenge already in flight.
For an enabled preview deployment, POST /api/v2/otp/verifications takes a live Bearer key and an Idempotency-Key, plus a JSON body:
{
"goal": "phone_possession",
"purpose": "sign_up",
"subject_id": "opaque-signup-session",
"destination": { "type": "phone", "value": "+254712345678" }
}
Use your own controlled test number in E.164 format. For email, use email_possession with {"type":"email","value":"<your controlled mailbox>"}. Supported purposes are sign_up, sign_in and password_reset.
The start and read responses include handoffs_remaining and, while another handoff is still allowed, resend_available_at.
- Start:
202means work was saved for delivery. Save the returned ID andexpires_atalongside your own subject, purpose and destination. For a network error or503, retry the same command key and body. A changed request with a previously used key returns409. - Status:
GET /api/v2/otp/verifications/:iduses anotp:readkey andX-Verify-Purpose/X-Verify-Subjectheaders.acceptedmeans the provider accepted a handoff.submission_unknownmeans the provider may have accepted it; keep the code entry open until expiry. A handoff status never proves the code arrived or the destination was verified. - Check:
POST /api/v2/otp/verifications/:id/checkuses anotp:verifykey and a different idempotency key for each user-entered answer. Send{"purpose":"sign_up","subject_id":"opaque-signup-session","code":"004271"}. A check is allowed once any handoff was accepted or is uncertain. If delivery is still being processed, retry the same check afterRetry-After. Onlyapprovedfrom a code check authorizes the action on your server. Preserve leading zeroes. - Cancel:
POST /api/v2/otp/verifications/:id/canceluses anotp:cancelkey, an idempotency key and the same subject and purpose. It can stop queued work; it cannot recall a message already handed to a provider. - Resend:
POST /api/v2/otp/verifications/:id/resenduses anotp:sendkey and an idempotency key. It sends the same code with the same expiry on the same route and reserves one more unit. It is allowed only while the challenge is pending and unexpired, at least 30 seconds after the last handoff (otherwise429 RESEND_COOLDOWNwithRetry-After), when the previous handoff is no longer queued or claimed (otherwise409 OTP_DELIVERY_PENDING), and for at most three handoffs in total (otherwise409 OTP_RESEND_LIMIT). Bonga never resends on its own. A replay with the same key and body returns the stored result without another send or charge.
Live codes expire after five minutes and lock after five incorrect answers. A timeout or submission_unknown never triggers an automatic retry, resend or channel switch; a resend is an explicit, charged request. For a confirmed failure or an expired challenge, start a new verification with a new command key. Delivery-receipt confirmation, signed callbacks and WhatsApp are outside this preview; the sandbox examples above still use the sandbox key and fixture.
Security rules
- Rate-limit by subject and destination, not only by IP.
- Never compare codes in your app; send the code to Bonga and use its decision.
- Bind the challenge to the subject and purpose.
- Expire the session after verification.
- Do not reveal whether an account exists.