Delete an app user account
The API and SDK in this guide are in development and require the normal deployment/package release checks. This is an end-user account for your app, separate from the operator who signs in to the Mocco console. Your app supplies its own public deletion page; Mocco's generic hosted-auth product remains separately gated.
Use an environment-bound publishable key with identity:auth; never expose a secret key. Register your deletion page's origin in that environment. For email accounts, use existing-only email authentication to prove the original subject without creating an account. Do not use the ordinary signup-capable flow. Social-only accounts require their own verified existing-subject path before your app enables them. Display an explicit confirmation describing the managed data that will be erased and the local/source data that will be kept. People who uninstalled your app must be able to reach this page.
Before initiating deletion, securely persist the original subject, a new random UUID requestId and a random 32-byte base64url recoveryToken, scoped to this environment and subject. Use the isolated @mocco/sdk-core/identity-deletion client, bound permanently to that original user ID. Do not copy the pending pair into a client for a new account. Native apps use their secure storage; a browser page needs its own scoped persistence and XSS protections. The recovery token grants only receipt status, but it is still a credential.
Call request({ requestId, recoveryToken }) with the original live session. The API commits erasure and the completion receipt together. After an uncertain response, call status with the same pair; it requires no session refresh or sign-in. Never create a replacement identity merely to discover whether deletion worked. A valid completed result lets you remove the local recovery token. Pending, a 401 from initiation, 404 from recovery, expiry or a network error are not proof of completion: keep the unresolved state and offer your documented support route. After expiry, do not resubmit the old pair against a new account.
Recovery receipts are available for 30 days and contain keyed token/subject digests rather than email, raw tokens or a recoverable user ID. The endpoint erases identity-owned records and their database cascades. Your other business records, source files, legal retention and backups need their own documented deletion/retention policy. Do not promise universal erasure from this endpoint alone.
Sign in with Apple
Apple asks apps that offer Sign in with Apple to revoke the person's Apple tokens when their account is deleted (App Store Review Guideline 5.1.1(v)). Mocco does this for you when it has the token:
Keep the token at sign-in. The redirect flow keeps it automatically. Native apps must send the
authorizationCodefromASAuthorizationAppleIDCredentialalong with the ID token ({ idToken, nonce, authorizationCode }) on every sign-in; without it Mocco has nothing to revoke later. Mocco exchanges the code with Apple as soon as the sign-in is admitted, because it works once and only for five minutes, and keeps the refresh token only if the ID token Apple returns with it verifies and names the same user. A sign-in still succeeds when this exchange fails; the account then has no token. Mocco keeps one token per Apple client, so a person who signs in on the web and in your iOS app has both revoked.Revocation runs after the deletion commits. Deleting the account (here or from the console), or unlinking Apple from it, queues one revocation per stored Apple token in the same transaction. A background job calls Apple's
/auth/revokeas the client the token was issued to, retries Apple outages for about 26 to 33 hours, then erases the stored token whatever happened. A refusal no retry can change (invalid_request,unsupported_grant_type) stops at once and is recorded asrefused;invalid_requestcan also mean the person already removed your app from their Apple Account. A revocation whose job never finishes is erased and recorded as failed after seven days. The deletion itself never waits for Apple.Tokens from sign-ins that don't complete are revoked too. When Apple issued a token but Mocco refused the sign-in (sign-in access, a link to someone else's account) or the link was never finished, Mocco queues that token for revocation instead of keeping it.
Turn Apple sign-in off rather than removing it. Revocation signs with the environment's Apple key, which stays while the provider is turned off. Mocco refuses to remove the Apple provider while it still holds tokens or revocations are in progress.
Removing an identity environment doesn't revoke. The environment's Apple key goes with it, so its users' tokens can't be revoked afterwards. Mocco refuses to remove an environment while revocations are still in progress there.
mocco_identity_environments_removeasks you to confirm with the number of tokens that would be left unrevoked, and the audit entry records it; the console doesn't show that number yet. Delete those users first, and remove the environment once their revocations end.The audit log records each outcome as "Processed the Apple token revocation of a deleted app user":
revoked,already_invalid,no_token,refusedorfailed, with no token and no user ID.already_invalidcarriesreason: invalid_grantwhen Apple answered that, which can also mean the token was issued to another client than the one Mocco named.
For an account with no stored token (one that signed in before Mocco kept them, or whose exchange failed), there is nothing for Mocco to revoke. Tell the person, after deletion, that they can remove your app from their Apple Account under Settings → Apple Account → Sign in with Apple (Apple's TN3194 describes this path).
Requests never put access or recovery tokens into links, query parameters, analytics or logs. Recovery uses X-Mocco-Deletion-Recovery; preflight must permit this header. Both routes return no-store responses. Initiation is limited to five per minute per subject, recovery to 30 per minute per key/request, in addition to shared-key limits. Honor Retry-After and keep pending state when a limit is reached.
Before enabling accounts, exercise confirmation/cancellation, response loss, reload, an expired receipt and a different account that reused the old email, using throwaway identities. Publish the actual app-owned deletion URL in the store's account-deletion resources. A local test or draft page is not a deployed deletion resource.