I’ve created a custom even listener that calls an external API service on the following event/resource/types:
- onEvent(Event event)-> EventType.REGISTER
- onEvent(Event event) -> EventType.VERIFY_EMAIL
- onEvent(AdminEvent adminEvent, boolean b) -> ResourceType.USER + OperationType.CREATE
The admin event is executed when creating a new user through the Keycloak admin client and the other are called through normal browser registration flows on Keycloak.
The listener does a POST call on each of these events and passes along the UUID of the new user.
The external API service receives the UUID and creates an internal user/profile in my system.
The problem I seem to have is that the user is not yet available when my API service receives the UUID from the event listener in Keycloak. I always get a 404 not found on the following code.
This seems to happen when executing a call on the EventType.REGISTER event and the admin event.
UserRepresentation userRepresentation = realmResource.users().get(uuid).toRepresentation();
The call after the EventType.VERIFY_EMAIL event seems to be working, I suppose it’s because the user was created during the EventType.REGISTER stage.
It’s like there is a flush or something happening after the event listener has finished it’s call and only then the user is available through the admin client.
Does somebody know this is normal behavior or a workaround for this.