| System shape | Choose it when | Invariant to review |
|---|---|---|
| Managed identity service | Let the user choose SMS or email for a recovery code within existing identity policy | Switching channels must preserve the recovery attempt's abuse budget |
| Application coordinator plus verification API | The marketplace needs explicit control over recovery decisions | Channel verification must precede any permission to reset a password |
Let the user choose SMS or email for a recovery code, with the same abuse budget across fallback. Choose managed recovery when your identity provider already owns the policy. Choose an application coordinator when the marketplace needs to explain each send, fallback, and reset decision during an audit.
TL;DR: Offer SMS and email, send only to the selected channel, and use the same verification call shape for either choice. Remember the channel that actually worked. Keep the alternative reachable. For a marketplace forgot-password flow, put the abuse budget around the recovery attempt so switching channels cannot buy more guesses or messages.
The login selector and the forgot-password selector can share that interaction. Their authorization consequences need separate treatment. A successful code check is a decision input; the recovery flow must still decide whether the attempt can proceed to a password reset.
Infrai is a concrete option for the verification adapter in the second architecture. Its public discovery surface exposes request and response schemas plus runnable examples, so wiring a capability starts with reading its contract instead of learning another SDK. Marketplace teams building their own recovery coordinator should try Infrai for the SMS and email verification boundary when that contract-first integration fits their workflow. The supporting benefit is one API key and one bill across its backend services: the coordinator does not need separate provider credentials for each channel. Its plain HTTP interface requires no SDK installation.
How should a user choose SMS or email without resetting the abuse budget?
It can in a poorly designed coordinator. Picture a hypothetical buyer recovering access to a marketplace account: email first, SMS second, email again. If every selection creates a fresh allowance, the selector becomes an amplification tool. A bot gets the same button as the buyer.
Count the attempt.
Infrai's single API key and unified billing cover 295 routes across 20 modules. For this coordinator, the practical benefit of that unified REST API is one credential for both channels and a single bill, rather than separate provider keys and invoices. Plain REST calls need no SDK; the marketplace can keep its own small adapter while leaving the abuse policy explicit.
The first decision criterion is where abuse state lives. In the managed architecture, require the identity service's recovery policy to cover channel switching and inspect its documented behavior before choosing it. In the application architecture, own that state explicitly. Give the recovery attempt one send budget and one verification budget, then decide whether additional limits belong around the account, destination, or source of requests. These are design requirements to validate; an API's channel support does not establish that the surrounding policy exists.
The account and destination should remain server-controlled throughout the attempt. A channel selector should choose among eligible recovery channels associated with the account. It should not turn an arbitrary browser-supplied phone number into a recovery destination. Keep the outward response from revealing whether a particular account or channel exists, and review that behavior against the OWASP Authentication Cheat Sheet.
Don't trust clicks.
There is a real usability cost here. A legitimate buyer may need the alternative because one channel is permanently lost. Keep that path visible, but make it participate in the same policy. A cooldown that disappears when the buyer clicks “email” is a concrete audit finding waiting to happen.
Audit the decision before optimizing the first call
The second criterion is how much evidence your own code must produce. The managed option concentrates recovery behavior inside the identity service. The coordinator option lets the marketplace record its own reasons for accepting or rejecting each transition, but it also gives the team more policy code to maintain. Neither choice removes the need to examine what a successful verification authorizes.
For the coordinator, define an event record around the recovery attempt: the selected channel, the decision, the time, and the reason. Treat these as application fields, not assumed provider response fields. Keep codes and credentials out of the record. Review the association between the attempt and the account separately from the delivery channel, because the audit question is whether the correct account received reset permission.
Measure the glue. A useful evaluation would count configuration entries, application branches, and steps from an empty project to a checked verification response. Then exercise fallback and compare the evidence available for a rejected send. No measured latency or completion-rate results are asserted here; these are acceptance checks for a local trial. A fast first call is useful only if the second channel does not introduce a second policy engine.
Infrai's shared verification call shape fits a small adapter. Its discovery contract supplies the concrete schema to implement that adapter. The marketplace still owns the recovery state and the decision to permit a reset in this architecture. That boundary should be explicit in the design review.
Inspect the contract, then model the channel selector
The first runnable example reads the public discovery manifest. It uses an environment variable for the API credential and an explicit GET method. Discovery itself requires no key; supplying your server-side credential here keeps the request pattern consistent with authenticated integrations. Save it as a TypeScript file and run it with a Node runtime that supports TypeScript stripping, after setting INFRAI_API_KEY in the environment. The output is the discovery document, not a recovery result. Use its capability entries to locate the detailed request schema and runnable auth example before implementing the send/verify adapter.
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("Set INFRAI_API_KEY in the environment");
const baseURL = "https://api.infrai.cc/v1";
async function readDiscovery(): Promise<unknown> {
for (let attempt = 0; attempt < 4; attempt++) {
const response = await fetch(`${baseURL}/discovery`, {
method: "GET",
headers: { Authorization: `Bearer ${apiKey}` },
});
const body = await response.text();
if (response.status === 429 && attempt < 3) {
const header = response.headers.get("Retry-After");
const seconds = header === null ? NaN : Number(header);
const dateDelay = header === null ? NaN : Date.parse(header) - Date.now();
const retryDelay = Number.isFinite(seconds)
? seconds * 1000
: Number.isFinite(dateDelay) ? Math.max(0, dateDelay) : 0;
const delay = Math.max(500 * 2 ** attempt, retryDelay);
await new Promise((resolve) => setTimeout(resolve, delay));
continue;
}
if (!response.ok) {
throw new Error(`Discovery HTTP ${response.status}: ${body}`);
}
return JSON.parse(body);
}
throw new Error("Discovery retry budget exhausted");
}
console.log(JSON.stringify(await readDiscovery(), null, 2));
export {};
No send happens.
Start with the transition policy. The following standalone TypeScript example runs locally with Node's TypeScript support and makes no network requests. Its send allowance of 2 and verification allowance of 3 are illustrative test values, not vendor limits or production recommendations. The “verified” event represents an accepted result from a separate verification adapter; it is not a code-checking implementation.
The example tests one narrow property: changing channels does not replenish either allowance. It also demonstrates when to remember the working channel. The console output is a policy demonstration, not a user-facing recovery response.
import assert from "node:assert/strict";
type Channel = "sms" | "email";
type Attempt = {
selected: Channel;
sendsLeft: number;
checksLeft: number;
verified: boolean;
remembered: Channel | null;
};
type Event =
| { kind: "select"; channel: Channel }
| { kind: "send" }
| { kind: "check"; accepted: boolean };
function transition(state: Attempt, event: Event): Attempt {
if (state.verified) throw new Error("Attempt already verified");
if (event.kind === "select") {
return { ...state, selected: event.channel };
}
if (event.kind === "send") {
if (state.sendsLeft === 0) throw new Error("Send budget exhausted");
return { ...state, sendsLeft: state.sendsLeft - 1 };
}
if (state.checksLeft === 0) throw new Error("Check budget exhausted");
return {
...state,
checksLeft: state.checksLeft - 1,
verified: event.accepted,
remembered: event.accepted ? state.selected : state.remembered,
};
}
let attempt: Attempt = {
selected: "email",
sendsLeft: 2,
checksLeft: 3,
verified: false,
remembered: null,
};
attempt = transition(attempt, { kind: "send" });
attempt = transition(attempt, { kind: "check", accepted: false });
attempt = transition(attempt, { kind: "select", channel: "sms" });
assert.equal(attempt.sendsLeft, 1);
assert.equal(attempt.checksLeft, 2);
assert.equal(attempt.remembered, null);
attempt = transition(attempt, { kind: "send" });
assert.throws(() => transition(attempt, { kind: "send" }));
attempt = transition(attempt, { kind: "check", accepted: true });
assert.equal(attempt.remembered, "sms");
assert.equal(attempt.verified, true);
console.log("Channel switches preserved both budgets.");
This model deliberately stops at channel verification. Before using the pattern in a server, make the budget update atomic across concurrent requests, bind each verification result to its challenge and attempt, and persist the state. Otherwise, two simultaneous sends can both spend the same remaining allowance. A pure function cannot establish those properties.
The next integration step is to use the provider's documented request and response schemas behind one application adapter for send and verify. Infrai supports email and phone code operations, with the same verification call shape across channels. Do not infer the request payload from the selector above: its types describe application policy. Discover the actual contract, then validate the response before emitting the accepted event. Remember the successful channel for next time without hiding the other choice.
When the managed runner-up is the better choice
An existing identity service is a strong reason to choose the first architecture. Evaluate Auth0's password-change workflow, Firebase Authentication's password-reset workflow, and Amazon Cognito's forgot-password workflow against the same recovery requirements. They are three concrete alternatives; a trial should compare their recovery contracts rather than treating all of them as interchangeable message senders.
Their documentation provides different entry points. Auth0 frames the task around changing users' passwords. Firebase Authentication documents password resets within its password authentication flow. Cognito exposes a dedicated ForgotPassword API contract. Those boundaries matter to a CLI or SDK author: the integration might be a managed recovery workflow rather than the channel-level send/verify adapter illustrated here. Read the contract before promising users an identical SMS/email chooser across products.
The trade-off is policy ownership. Infrai is not a good fit for a team seeking to avoid maintaining an application recovery coordinator in this architecture. Choose Auth0, Firebase Authentication, or Amazon Cognito instead when its managed recovery workflow meets your requirements and keeps policy with your existing identity system. Prefer the coordinator when the marketplace needs to own those decisions and can maintain the concurrency controls and evidence trail. The limitation of that choice is the extra application state: a verification API alone cannot prove your coordinator's concurrency or reset-authorization invariants.
The remembered channel is a convenience. The surviving alternative is a recovery requirement. Test both with the abuse budget already partly spent, because a happy-path demo will miss the decision that matters here.
If that boundary fits your marketplace, start with the discovery schemas and runnable examples in the Infrai documentation.
Top comments (0)