Purging Users (Periodically)

We have ~60 000 new users created in a realm per annum (this is the 1st year). Would anyone have suggestions/advise on how some of these accounts can be periodically purged? Thank you.

You can use the administration REST API (${product.name.full} Admin REST API) to move through you users and delete the ones wchich you want to be purged.

(You can also use the notwork developer tools of your browser to observe the api calls which are fired when moving to the users list and when deleting one of them in the admin console.)

1 Like

We had to solve this with an external script and a keycloak extension to have a deletion criteria.

The extension sets a last-login attribute on the user.
The cleanup script then periodically scans for accounts with no login in a configureable time span, marks these accounts for deletion (with a different custom attribute), and sends out an email to the user notifying them their account will be deleted within 2 months.
The deletion mark is simply a timestamp, if it is older than 2 months the account will be deleted.

The entire check/notification/deletion handling is done in python with python-keycloak.

1 Like