Reputation: 53
I use keycloak server for Authorization. I create my user in my database and in keycloak. Now I need to delete user from my database when user is deleted in keycloak. My server is written by Java. How can I get event from keycloak to my server when user is deleted or updated in keycloak?
Upvotes: 4
Views: 3991
Reputation: 34
please check this example KecyloakEventExample I hope it will be useful
Upvotes: 0
Reputation: 51513
I think you are better off using Keycloak User Storage SPI feature:
You can use the User Storage SPI to write extensions to Keycloak to connect to external user databases and credential stores. The built-in LDAP and ActiveDirectory support is an implementation of this SPI in action. Out of the box, Keycloak uses its local database to create, update, and look up users and validate credentials. Often though, organizations have existing external proprietary user databases that they cannot migrate to Keycloak’s data model. For those situations, application developers can write implementations of the User Storage SPI to bridge the external user store and the internal user object model that Keycloak uses to log in users and manage them.
In this way you do not need to have some callback mechanism that is trigger whenever a user gets deleted, updated or whatever. You just configure your DB as an external user DB to be used by Keycloak. Moreover, you can configured it so that whenever a user gets add, deleted, or update it reflect immediately on your DB. This approach is easier to implement, cleaner, more maintainable and performance- and memory- wise better.
Upvotes: 2