I have an Express.js CRUD application and I use Keycloak 18.0.2 for identity management. Keycloak handles Google and Facebook Single Sign-On (SSO) for my application, and all authentications are managed through Keycloak. Currently, users are authenticated using their access tokens received in HTTP requests.
I want to implement a feature where users can delete their own accounts without requiring administrative privileges. Ideally, I would like to use the user's token received in the HTTP request to authenticate and delete the user record from Keycloak. So user will make request to DELETE base_url_to_my_express_js_application/users then I will delete user from my application and then call the Keycloak deletion API with the same token I received as authorization header.
I have tried the following approaches without success:
- On internet I got suggestion for Enabling "Self-Service Account Management" in Keycloak's "Account" tab: I found that there is no "Account" tab in Keycloak 18.0.2, and I couldn't locate the option to enable self-service account management.
- Making a DELETE request to https://my-keycloak/auth/realms/my-realm/account: This endpoint returns status 404.
{
"error": "RESTEASY003210: Could not find resource for full path:http://your-keycloak-server/auth/realms/your-realm-name/account
}
- Making a DELETE request to https://my-keycloak/realms/my-realm/account: This endpoint returns status 405.
{
"error": "RESTEASY003650: No resource method found for DELETE, return 405 with Allow header"
}
Since the above approaches didn't work as expected, I'm seeking guidance on how to implement this feature using the Keycloak Admin API or any other alternative method. Specifically, I would like to know:
- How can I enable users to delete their own Keycloak accounts using their own access tokens ?
- Is there a specific Keycloak Admin API endpoint that allows users to delete their own accounts? If so, how can I access it?
- If the above approach is not possible, what alternative methods can I use to implement the account deletion feature securely?
I appreciate any insights, examples, or guidance on how to achieve this functionality within the Keycloak 18.0.2 version.
Thank you in advance for your help!