|
| 1 | +--- |
| 2 | +id: delete-users-identities |
| 3 | +title: Learn how to delete user accounts and let users delete their own account |
| 4 | +sidebar_label: Delete identities |
| 5 | +--- |
| 6 | + |
| 7 | +# Delete identities |
| 8 | + |
| 9 | +Ory Identities doesn't expose account deletion as a self-service flow, to prevent users from accidentally and irrecoverably |
| 10 | +destroying their account and to avoid an attack surface for deleting accounts on a user's behalf. |
| 11 | + |
| 12 | +Instead, deleting an identity is an administrative operation. Call the |
| 13 | +[`DELETE /admin/identities/{id}`](../../reference/api.mdx#operation/deleteIdentity) endpoint with the identity's ID. Deletion is |
| 14 | +permanent and can't be undone. |
| 15 | + |
| 16 | +````mdx-code-block |
| 17 | +import Tabs from '@theme/Tabs' |
| 18 | +import TabItem from '@theme/TabItem' |
| 19 | +
|
| 20 | +<Tabs |
| 21 | + defaultValue="cloud" |
| 22 | + values={[ |
| 23 | + {label: 'Ory Network', value: 'cloud'}, |
| 24 | + ]}> |
| 25 | + <TabItem value="cloud"> |
| 26 | +
|
| 27 | +```shell |
| 28 | +curl --request DELETE -sL \ |
| 29 | + --header "Authorization: Bearer {ORY_API_KEY}" \ |
| 30 | + https://playground.projects.oryapis.com/admin/identities/{id} |
| 31 | +``` |
| 32 | +
|
| 33 | +</TabItem> |
| 34 | +</Tabs> |
| 35 | +```` |
| 36 | + |
| 37 | +:::info |
| 38 | + |
| 39 | +The Admin API is protected by your project API key, so all calls must be made from your server. Never expose the API key or call |
| 40 | +the Admin API from a browser or mobile client. See [Authorization with API Keys](../../concepts/personal-access-token.mdx). |
| 41 | + |
| 42 | +::: |
| 43 | + |
| 44 | +## Let users delete their own account |
| 45 | + |
| 46 | +To offer a "Delete my account" option in your UI, build it in your own backend: |
| 47 | + |
| 48 | +1. Expose a button in your application's UI, for example on the settings page. |
| 49 | +2. On click, have your **server-side** application call |
| 50 | + [`DELETE /admin/identities/{id}`](../../reference/api.mdx#operation/deleteIdentity) with the logged-in identity's ID, which you |
| 51 | + get from the user's session via [`toSession`](../../reference/api#tag/frontend/operation/toSession) or `/sessions/whoami`. |
| 52 | +3. Require a fresh [privileged session](../session-management/session-lifespan#privileged-sessions) so the user re-authenticates |
| 53 | + before deletion. |
| 54 | +4. Add an explicit confirmation step with CSRF protection, so a deletion can't be triggered accidentally or by a forged request. |
| 55 | + |
| 56 | +## Account deletion and GDPR |
| 57 | + |
| 58 | +Deleting the Ory identity alone rarely satisfies a GDPR "right to erasure" request. User data usually also lives in your own |
| 59 | +databases, CRM, analytics, email provider, logs, and backups, and all of it must be cleaned up. GDPR was among the first such |
| 60 | +regulations, but the same applies to a number of similar data protection laws in other countries. |
| 61 | + |
| 62 | +Track and orchestrate deletion requests in your own system, treating the Ory identity as one of several data stores. Your endpoint |
| 63 | +can then: |
| 64 | + |
| 65 | +- Delete or pseudonymize the user's data across your services and databases. |
| 66 | +- Call [`DELETE /admin/identities/{id}`](../../reference/api.mdx#operation/deleteIdentity) to remove the identity from Ory. |
| 67 | + |
| 68 | +To keep a record of the user instead of deleting it, strip the credentials and PII but keep a skeleton record: use |
| 69 | +[`PUT /admin/identities/{id}`](../../reference/api.mdx#operation/updateIdentity) to update the traits and |
| 70 | +[`DELETE /admin/identities/{id}/credentials/{type}`](../../reference/api.mdx#operation/deleteIdentityCredentials) to remove |
| 71 | +credentials. |
0 commit comments