How we made our custom workflow with Keycloak way before workflow feature
At please-open.it we implement everything necessary for our customers’ use cases. Many times we have to make workflows : “when a user registers, create it in Hubspot”.
There is an interesting provider for that : EventListeners. Instead of writing specific EventListeners, we chose a different way with n8n that allows us to have workflows from Keycloak.
An “EventListener” in Keycloak is a SPI (Service Provider Interface) that allows catching all possible events in Keycloak https://github.com/keycloak/keycloak/blob/main/server-spi-private/src/main/java/org/keycloak/events/EventType.java and execute specific code when events occurs.
Through this repo, we have an interesting approach :
https://github.com/p2-inc/keycloak-events
Send an event over http :
https://github.com/p2-inc/keycloak-events?tab=readme-ov-file#http-sender
Got it ? :-)
A workflow entrypoint : a webhook.
After deploying an eventlistener (on your realm) that sends the event to your webhook, you are free of using this event.
Within parameter “Repond : immediately”, your flow is now async.
For every event, the webhook will be called.
We like this method, but we think that we can go further without deploying anything in Keycloak.
Keycloak can save all events in the database. In this example, we will save only “login” events with an expiration.
In n8n, a “Postgres trigger”, connected to our Keycloak DB that listen for “insert” in “event_entity” table :
And there it is, the event is catched by N8N and we are able now to start a specific workflow :
We prefer this method for :
- having multiple workflows that listen on the same event, only duplicate the trigger works while using webhooks needs a single one for all events
- nothing to deploy on Keycloak, only save events feature
- only triggered on events we chose
A common use case is : “replicate the user in Hubspot”. Hubspot has all APIs available and well documented and some implementations of Java SDK exists :
https://github.com/Smartling/hubspot-rest-sdk-java
And in n8n ?
Boom !
So much connectors already exists, logs, metrics, debug, alerting… Ready out of the box !
Want a new workflow for a specific event ?
Click, Click, Click, “new workflow”, “Postgres trigger” and you are ready to go.
We are sure that today this solution is one of the most effective there is.