Skip to content

feat(api): revoke Sign in with Apple tokens during account deletion - #65

Open
MehrshadFb wants to merge 1 commit into
feat/account-deletionfrom
feat/api-siwa-revocation
Open

MehrshadFb wants to merge 1 commit into
feat/account-deletionfrom
feat/api-siwa-revocation

Conversation

@MehrshadFb

Copy link
Copy Markdown
Collaborator

Apple requires apps that offer Sign in with Apple to revoke the user's Apple tokens when their account is deleted, and our saga did not. Auth0 obtains those tokens when it exchanges the authorization code and keeps them on the user's Apple identity, but deleting the Auth0 user just throws them away without revoking anything. The visible effect is that the app stays listed as authorised under the person's Apple ID after they delete their account, their next sign-in skips Apple's consent screen, and Apple never sends their email to Auth0 again. It is also what App Store review checks. This PR adds the missing step on top of #56: for an apple| identity the saga reads the refresh token from Auth0, revokes it against Apple's /auth/revoke endpoint with a freshly signed client secret, and only then deletes the Auth0 user. The order matters because the token lives on the Auth0 user. Apple answers 200 for a token that is already revoked, so a resumed saga repeats the step safely, and nothing new is stored in our database.

Two kinds of failure, handled differently on purpose. If Apple cannot be reached, the saga stops before the Auth0 delete and the reconciler retries later with the token still in place, the same shape as an Auth0 outage. If Apple refuses the request, or there is no token to revoke because the credentials are missing or the management client cannot read identity tokens, the deletion goes ahead and an audit error is logged, because Apple's own guidance is that the deletion must still be honoured and retrying would only delay it. Accounts from every other connection are untouched. Nothing about the endpoint or the OpenAPI spec changes, so mobile needs no regeneration. To switch it on: set APPLE_SIWA_TEAM_ID, APPLE_SIWA_KEY_ID, APPLE_SIWA_PRIVATE_KEY and APPLE_SIWA_CLIENT_ID (the iOS bundle identifier, the same values the Auth0 Apple connection uses), grant the management application read:users and read:user_idp_tokens, and enable refresh-token storage on the Apple connection. The full checklist is in api/docs/authentication.md.

Part of #31

@github-actions

Copy link
Copy Markdown

API unit-test coverage

Metric Coverage
Statements 79.29% (1153/1454)
Branches 61.76% (491/795)
Functions 82.04% (201/245)
Lines 78.01% (1008/1292)

Unit suite only; controllers are exercised by the e2e suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant