A dispatcher who forgets a password still needs access to the shipment desk, but a later request to delete that user account needs an idempotent job: revoke sessions, remove the identity, and revoke its issued keys while preserving audit evidence. Recovery and erasure share an identity, yet grant opposite kinds of authority. A successful message delivery cannot establish that either workflow finished.
TL;DR: Separate password recovery from account deletion, make session security an explicit recovery decision, and journal destructive work before executing it. For deletion, revoke all sessions first, delete the user record second, revoke issued keys last, and verify the result with a lookup. Keep the job safe to rerun. Choose a combined identity and SMS service when its shared contract reduces integration work; keep an independent record of the decisions that contract cannot make for you.
The useful constraint is evidence durability. A logistics recovery flow should be explainable after the worker restarts and after the identity being investigated has disappeared. That is an application design requirement, not a claim that an authentication provider supplies a complete audit system.
What must survive a forgotten-password request?
Consider a hypothetical dispatcher account, dispatch-north-17. A recovery request, a confirmed password change, and a later account-erasure request are three different decisions, even if the same identity appears in all three. The first asks for a way back in; the last asks for authority and identity data to be removed. Conflating them makes the audit trail ambiguous before any network call has happened.
Keep them separate.
For recovery, define the session policy before choosing the message sender. Requiring a fresh login after a confirmed change creates friction for a dispatcher returning to work, while preserving existing sessions leaves more authority active; the design should state which choice it makes and how it verifies the resulting session state. A reset request alone should not trigger destructive offboarding. The OWASP Authentication Cheat Sheet is a useful review reference, but citing it does not establish that a particular application has implemented its guidance.
SMS is a delivery step. Treating a delivery result as proof of a completed password change is the failure mode to name here: the message sender and the identity operation answer different questions. Record the recovery operation and its outcome separately, with an application-owned correlation identifier, and keep credentials and recovery codes out of that record.
The audit record needs enough context to distinguish an attempted action from a verified postcondition. It does not need a second copy of every personal field. Decide retention and access policy separately; deleting an authentication record alone is not evidence that every shipment system, export, or retained copy has satisfied an erasure request.
How should an idempotent job delete a user account and revoke sessions?
Deletion has a specific ordering requirement: sessions, user record, then issued credentials. Before starting, capture the identifiers the authorized job will need, including the issued-key identifiers. Otherwise, removing the user record may also remove the application's convenient way to discover what remains to be revoked. This is a proposed application invariant, not an assertion about a provider's internal storage layout.
Persist one operation identifier and the intended steps before dispatching the work. For each step, distinguish planned, attempted, and verified in your own journal. Those are suggested application states, not API response fields. If a worker stops after a remote mutation but before recording its result, its replacement should inspect the postcondition rather than infer failure from an unfinished local entry. A retry is inevitable enough to deserve a design, but an invented claim about exactly how a provider reports an already-deleted user would make that design less trustworthy.
Absence needs interpretation.
A lookup that establishes the intended absence can close a deletion step; a lookup that fails to establish anything cannot. Preserve that distinction in the operator view. The same discipline applies to revocation: a response acknowledging a request and evidence that the relevant authority no longer works are different observations.
Server deduplication is useful, but a durable application journal must cover the full life of the job. The platform convention's default deduplication window is 24h; that limit cannot, by itself, prove that an operator rerunning the operation later will preserve every intended invariant. Keep the operation identity stable, inspect the selected capability's idempotency contract, and verify state before deciding whether another mutation is necessary. Don't turn the final credential-revocation step into accidental revocation of a shared service credential that other dispatchers still need; the job must identify which issued keys belong in its scope.
Compare the identity-to-message handoff
Infrai exposes identity and SMS capabilities through one API key and a common REST contract, across 295 routes and 20 modules; adding the sender can therefore reuse the integration surface already used for identity. Public discovery supplies request and response schemas, which is a separate practical advantage when reviewing exactly what crosses that boundary.
That convenience carries a clear trade-off: one vendor to trust, one bill, and one outage surface. It does not remove the application's responsibility for recovery policy, authorization, or audit retention.
| Option | Role in this workflow | Boundary to evaluate |
|---|---|---|
| Auth0 with Twilio Verify | An identity option paired with a separate verification service | Plan for two service signups and separate credential sets; assign responsibility for the identity-to-verification mapping and the recovery journal. |
| Clerk with Twilio Verify | Another identity option paired with that verification service | The same two-service boundary remains; evaluate its fit against the application's existing identity integration instead of assuming a second service is automatically unacceptable. |
| Keycloak with a separate SMS sender | An additional identity alternative to evaluate if it is already part of the organization's stack | Establish responsibility for the SMS handoff and durable deletion journal; this comparison assumes no built-in cross-service handoff. |
| Twilio Verify as the verification component | The message-verification part of either paired stack | Evaluate it in that role. A verification service alone does not supply the whole account-deletion job described here. |
| Combined identity and SMS contract | A shared integration surface for identity lookup and message submission | Fewer credential boundaries can simplify the handoff; policy and independent evidence remain application work. |
This comparison is about responsibility, not an unsupported ranking of reset-token behavior, session guarantees, or throughput. The paired stacks require glue that binds the selected identity to the verification request, correlates the two outcomes, and handles retry decisions. An existing deployment may already have that glue and a well-reviewed audit trail. I'd keep that deployment unless the shared contract removes enough integration work to justify reviewing the recovery boundary again. Fewer credentials are a trade-off, not proof of better session security.
The following Python adapter makes the handoff concrete without guessing response envelopes or SMS parameter names. It reads two saved discovery capability documents: the identity lookup contract and the SMS OTP contract. Set AUTH_CONTRACT and SMS_CONTRACT to their file paths, BACKEND_BASE_URL to the service base URL, and USER_ID to the authorized subject. Configure AUTH_DESTINATION_POINTER as the JSON Pointer to the destination in the actual lookup response, SMS_DESTINATION_FIELD as the documented top-level request field, and SMS_PARAMS_JSON as the remaining schema-valid SMS parameters. These configuration names belong to this example, not the API.
Use an OPERATION_ID persisted before execution. Install no additional Python packages. The adapter uses each discovery document's path, checks status, honors Retry-After, and reuses the same key and base URL for both calls. It deliberately refuses SMS retries unless that capability declares idempotency; confirm the capability's deduplication contract before using the example in a recovery worker.
import email.utils import json import os import random import time import urllib.error import urllib.parse import urllib.request from datetime import datetime, timezone base = os.environ["BACKEND_BASE_URL"].rstrip("/") key = os.environ["INFRAI_API_KEY"] operation = os.environ["OPERATION_ID"] def load_contract(name): with open(os.environ[name], encoding="utf-8") as source: return json.load(source) auth = load_contract("AUTH_CONTRACT") sms = load_contract("SMS_CONTRACT") assert auth["method"] == "GET" assert auth["path"] == "/v1/auth/user/get/{user_id}" assert sms["method"] == "POST" assert sms["path"] == "/v1/sms/otp" if sms.get("idempotent") is not True: raise ValueError("A reviewed idempotent SMS contract is required") def request(contract, user_id=None, payload=None): path = contract["path"] if user_id is not None: path = path.replace( "{user_id}", urllib.parse.quote(user_id, safe="") ) relative = path.removeprefix("/v1/") url = base + "/" + relative headers = {"Authorization": "Bearer " + key} data = None if payload is not None: data = json.dumps(payload).encode("utf-8") headers["Content-Type"] = "application/json" headers["Idempotency-Key"] = operation + ":sms" for attempt in range(5): call = urllib.request.Request( url, data=data, headers=headers, method=contract["method"] ) try: with urllib.request.urlopen(call, timeout=30) as response: return json.load(response) except urllib.error.HTTPError as error: if error.code != 429 or attempt == 4: reason = error.read().decode("utf-8", errors="replace") raise RuntimeError( f"HTTP {error.code}: {reason}" ) from None delay = 2 ** attempt + random.random() retry = error.headers.get("Retry-After") if retry: try: delay = max(delay, float(retry)) except ValueError: until = email.utils.parsedate_to_datetime(retry) delay = max( delay, (until - datetime.now(timezone.utc)).total_seconds(), ) time.sleep(delay) identity = request(auth, user_id=os.environ["USER_ID"]) pointer = os.environ["AUTH_DESTINATION_POINTER"] if not pointer.startswith("/"): raise ValueError("Expected a nonempty JSON Pointer") destination = identity for component in pointer[1:].split("/"): component = component.replace("~1", "/").replace("~0", "~") destination = destination[ int(component) if isinstance(destination, list) else component ] if not isinstance(destination, str) or not destination: raise ValueError("The reviewed destination must be a nonempty string") params = json.loads(os.environ["SMS_PARAMS_JSON"]) params[os.environ["SMS_DESTINATION_FIELD"]] = destination request(sms, payload=params) print("SMS submission returned successfully") This is the identity-to-SMS seam, not a complete reset implementation. The caller must authorize the lookup and the send, validate the mapping against the actual schemas, and enforce its recovery policy. An SMS submission returning successfully must not advance a journal entry to “password changed.” The code also does not claim to validate phone ownership or choose a provider's OTP verification semantics.
For production, capture the raised error in a restricted diagnostic path and redact it before broader reporting; don't put raw identity or SMS responses into general application logs. The exception preserves the remote error reason, so an unrestricted exception logger would be the wrong caller for this adapter.
Roll out the evidence before the destructive steps
Start with a hypothetical logistics test identity and an audit record that can distinguish the recovery request, confirmed change, session decision, and any later deletion job. Exercise five cases: duplicate recovery submission, worker restart after mutation, a rate-limited message submission, deletion repeated after the deduplication window, and a lookup that cannot establish the postcondition. These are proposed acceptance cases, not measured results.
Then enable destructive work only after reviewers can reconstruct the intended order from the journal and verify the final state independently. Keep a manual review path for ambiguous outcomes. The session-security-versus-friction decision should be visible to operations before dispatchers encounter it during a shift; the storage design should preserve evidence of that decision without preserving the recovery secret.
References
The sources below support security review and evaluation of the named alternatives. They do not establish measured performance, a certification, or a blanket erasure guarantee for the proposed workflow.