Skip to content

Commit 5402826

Browse files
authored
feat: delete identity doc (#2694)
* feat: delete identity doc * chore: ai review
1 parent c35ae61 commit 5402826

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.

docs/kratos/self-service/flows/user-settings.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ Three settings methods are supported:
6666
- `profile` for updating an identity's traits (for example change the first name). The updated traits must be valid against the
6767
Identity Schema defined for its [identity traits](../../manage-identities/managing-users-identities-metadata).
6868

69+
:::note
70+
71+
Account deletion isn't part of the settings flow. Deleting an account is an administrative operation. If you want to let users
72+
delete their own account, see [Delete identities](../../manage-identities/delete-users-identities).
73+
74+
:::
75+
6976
<Tabs
7077
defaultValue="oss"
7178
values={[

sidebars-network.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ const networkSidebar = [
151151
},
152152
items: [
153153
"kratos/manage-identities/create-users-identities",
154+
"kratos/manage-identities/delete-users-identities",
154155
"kratos/manage-identities/import-user-accounts-identities",
155156
"identities/model/identity-state",
156157
"kratos/manage-identities/invite-users",

0 commit comments

Comments
 (0)