| Pick this when | Serious option | Evidence responsibility |
|---|---|---|
| You want a managed verification service for login. | Twilio Verify | Connect the challenge outcome to the account action it authorizes. |
| You want SMS transport and will own verification state. | Amazon SNS | Own code generation, expiry, verification, and attempt accounting. |
| You need email delivery for receipts and a custom email-code fallback. | Twilio SendGrid | Keep receipt eligibility separate from the email challenge lifecycle. |
| You want an AWS email-delivery building block alongside SMS transport. | Amazon SES | Own receipt eligibility and the custom email challenge lifecycle. |
| You want to inspect capability schemas and runnable examples before integrating. | A unified REST service | Review its operation contract, then retain the application's business decisions. |
Short answer: For US/EU SaaS login, managed SMS OTP is the least complex built-in verification path here. Treat email OTP as an application-owned fallback. For a marketplace sending an order receipt after payment settles, choose around compliance evidence: retain the challenge decision, settlement reference, and receipt dispatch as separate records.
Keep them separate.
A successful login does not establish that payment settled. An accepted receipt dispatch does not establish that the buyer read it. Those distinctions should survive the journey from application logs to dashboards to an audit export. Otherwise, a helpful operational shortcut can become an unsupported compliance claim.
How should SMS and email OTP support SaaS login security?
Start with the question a reviewer will ask: why was this action allowed? For login, the answer includes the challenge outcome and the application's authorization decision. For an automatic order receipt, the relevant trigger is payment settlement. A buyer need not log in again just to receive the receipt.
Diagram in words: payment settles → application authorizes receipt dispatch → transport accepts the message → later delivery observations arrive. Separately, SMS challenge → successful verification → authorized account action. Join those paths through internal references only where the business action requires that relationship.
This is a governance choice. A single success label is convenient for a dashboard, but it erases which boundary the system crossed. Prefer distinct event names and keep their meanings narrow. The trade-off is more explicit application records; the benefit is that someone reviewing a receipt can distinguish business eligibility from transport activity without guessing what a green badge meant.
Pick the owner before picking the channel
Pick Twilio Verify when managed verification is the requirement. Evaluate the challenge outcome your application will retain and how it maps to the account action. It is a different responsibility from sending a text message. Verification still leaves business authorization with the marketplace.
Pick Amazon SNS when SMS transport is the intended building block and the team deliberately accepts ownership of the challenge lifecycle. That includes expiry and failed-attempt accounting. A transport receipt alone cannot explain which code was accepted or which account action followed.
Pick Twilio SendGrid for the email-delivery role. Receipt mail and email OTP can use email transport, but they need different application state. For a custom fallback, generate, protect, expire, verify, and consume the code in the application. Keep that challenge state out of the receipt template's responsibilities.
Pick Amazon SES as the email transport alternative when an AWS email-delivery boundary suits the team. Compare it with SendGrid on the operational workflow you need to run, rather than treating either email sender as a substitute for a managed verification decision. Both choices leave this guide's custom email-code policy with the application.
Infrai fits the unified REST option when public, self-describing discovery and runnable examples help the team inspect a capability before wiring it into the worker. Reading a request schema and its example avoids learning another SDK; per-call request identifiers and latency metadata also give the receipt worker useful correlation fields for operational logs. These are integration and observability advantages, not proof of regulatory compliance.
For that workflow, assign email-code lifecycle management to the application and consume SMS and email event observations by polling. Put country eligibility, country-based spend cutoffs, and anti-abuse throttles in application policy. Those responsibilities matter for a US/EU rollout even when managed SMS verification supplies the challenge machinery. Select a different service boundary if your requirement is a provider-owned email verification lifecycle or push-driven orchestration.
Good practice starts with inspecting the contract. This read-only example retrieves the SMS OTP capability schema before you implement authentication writes. Set INFRAI_BASE_URL to the service's documented API base ending in /v1 and INFRAI_API_KEY to an environment-held key. Save it as inspect-otp.ts and run npx tsx inspect-otp.ts. Discovery is public; using the worker's environment configuration here keeps its HTTP setup explicit.
async function inspectContract(): Promise<void> {
const baseURL = process.env.INFRAI_BASE_URL;
const apiKey = process.env.INFRAI_API_KEY;
if (!baseURL || !apiKey) throw new Error("Set API base URL and API key");
const url = `${baseURL.replace(/\/$/, "")}/discovery/sms.otp`;
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(url, {
method: "GET",
headers: { Authorization: `Bearer ${apiKey}` },
});
if (response.status === 429 && attempt < 3) {
const retryAfter = response.headers.get("Retry-After");
let delayMs = 1000 * 2 ** attempt;
if (retryAfter !== null) {
const seconds = Number(retryAfter);
const date = Date.parse(retryAfter);
if (Number.isFinite(seconds)) {
delayMs = Math.max(delayMs, seconds * 1000);
} else if (Number.isFinite(date)) {
delayMs = Math.max(delayMs, date - Date.now());
}
}
await response.body?.cancel();
await new Promise<void>((resolve) => setTimeout(resolve, delayMs));
continue;
}
if (!response.ok) {
throw new Error(`Discovery HTTP ${response.status}: ${await response.text()}`);
}
console.log(JSON.stringify(await response.json(), null, 2));
return;
}
}
inspectContract().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});
This GET creates no challenge. Inspect the returned request schema and runnable example before constructing a write; don't guess request fields from the operation name. The application policy below then supplies a separate control the transport contract cannot decide for you.
Make fallback spend the same attempt budget
One specific trap deserves code: switching from SMS to email must not reset the login journey's abuse allowance. Otherwise, two individually limited channels can produce a larger combined allowance than the policy intended. Rate limiting needs a shared journey boundary. Log the decision reason as well as the counter. An alert can tell you that denials increased; the reason tells you which rule denied a particular request.
The following runnable TypeScript example models that application policy. Its limit of 3 send attempts is illustrative, not a recommended US/EU threshold or a vendor default. The records are application data, not API response fields. Save it as fallback-policy.ts and run it with npx tsx fallback-policy.ts in a TypeScript development environment.
type Channel = "sms" | "email";
type Journey = {
challengeId: string;
policyVersion: string;
attempts: number;
limit: number;
verified: boolean;
};
type Decision = {
challengeId: string;
policyVersion: string;
channel: Channel;
allowed: boolean;
reason: "send_reserved" | "budget_exhausted" | "already_verified";
attempts: number;
};
function reserveSend(journey: Journey, channel: Channel): Decision {
let reason: Decision["reason"];
if (journey.verified) {
reason = "already_verified";
} else if (journey.attempts >= journey.limit) {
reason = "budget_exhausted";
} else {
journey.attempts += 1;
reason = "send_reserved";
}
return {
challengeId: journey.challengeId,
policyVersion: journey.policyVersion,
channel,
allowed: reason === "send_reserved",
reason,
attempts: journey.attempts,
};
}
const journey: Journey = {
challengeId: "buyer-login-228",
policyVersion: "example-policy-1",
attempts: 0,
limit: 3,
verified: false,
};
const requests: Channel[] = ["sms", "sms", "email", "email"];
for (const channel of requests) {
console.log(JSON.stringify(reserveSend(journey, channel)));
}
The fourth request is denied. Switching channels preserved the budget.
In production, reserve attempts atomically in durable state before dispatch. An in-memory object cannot coordinate concurrent workers or survive a restart. Use separate controls for send requests and code-verification attempts, and enforce expiry and single-use consumption independently. The snippet deliberately isolates one decision so its output is easy to inspect; it is not a complete authentication implementation.
For dispatch retries, persist a logical operation identity and apply the selected operation's documented idempotency contract. On HTTP 429, honor Retry-After and back off rather than sending repeatedly. Count logical send reservations consistently across retries so a transport retry neither creates a new login allowance nor hides a second logical request. That accounting rule belongs in the application policy, alongside country eligibility and the decision to allow fallback.
Turn observations into useful logs and alerts
Before: notification_success. After: a receipt dispatch record refers to the settled order, the logical receipt, and the transport message reference. A later observation carries its retrieval time and, when available, the event time. Preserve both. A fresh poll can return an older event.
For the login path, retain the challenge reference, channel, policy version, and decision reason. Avoid raw OTP values and full destinations in routine logs. This gives up some debugging convenience in exchange for a smaller sensitive-data footprint; restricted investigation records can have a different access policy from a broadly visible operational dashboard.
Use metrics to count decisions by reason and channel. Keep individual order and challenge identifiers in appropriately protected records rather than turning every identifier into a metric label. Alert on observation freshness separately from transport outcomes. An overdue poll means the evidence is stale; it does not establish that an SMS failed, and it should not automatically authorize another channel.
Delivery needs context.
DMARC covers domain authentication policy and reporting. It does not prove that a buyer passed an email challenge. Apple's Mail Privacy Protection also makes an email-open signal unsuitable as proof that the buyer read the receipt. For deliverability review, separate domain authentication, transport observations, and human action instead of converting them into one success percentage.
Limits of this evidence model
This design organizes evidence; it does not establish US or EU legal compliance, prove a person's identity, or demonstrate measured delivery performance. Retention periods, access rules, and rollout thresholds need a marketplace-specific policy. None is implied by the illustrative 3-attempt budget.
A missing settlement reference should trigger investigation, not a claim that settlement never occurred. Polling introduces observation delay, while a dispatch acceptance remains narrower than delivery or reading. Pick the service whose responsibility boundary your team can operate and explain, then keep those distinctions intact in the export a reviewer actually receives.
Further reading
References:
- Twilio Verify documentation: https://www.twilio.com/docs/verify
- Amazon SNS SMS documentation: https://docs.aws.amazon.com/sns/latest/dg/sns-mobile-phone-number-as-subscriber.html
- Amazon SES documentation: https://docs.aws.amazon.com/ses/latest/dg/Welcome.html
- Twilio SendGrid documentation: https://www.twilio.com/docs/sendgrid
- DMARC policy and reporting specification: https://datatracker.ietf.org/doc/html/rfc7489
- Apple Mail Privacy Protection guide: https://support.apple.com/guide/iphone/use-mail-privacy-protection-iphf084865c7/ios
Top comments (0)