Skip to content

feathers-keycloak-listener

feathers-keycloak-listener facilitates the management of Keycloak events emitted by keycloak-event-gateway plugin.

Installation

Install with your preferred package manager:

shell
pnpm add @kalisio/feathers-keycloak-listener
shell
npm install @kalisio/feathers-keycloak-listener
shell
yarn add @kalisio/feathers-keycloak-listener

Configuration

Your application will define the endpoint to send the JSON to, using the standard Feathers mechanism:

js
// `POST /api/keycloak-events`
app.use('/api/keycloak-events', new KeycloakListenerService({
	app: app
}), {
   methods: [
     'create'
   ]
})

In Keycloak, you will have to configure this endpoint, along with an access token, in the keycloak-event-gateway plugin.

Then You must define hooks around the service’s create method to implement the business logic triggered by the received event:

js
app.getService('keycloak-events').hooks({
   before: {
      createUser: [
        async (context) => {
          const event = context.arguments[0]

          ...

          // Use the event: Access to
          // event.operationType, event.resourcePath,
          // etc.
          //
          // See some examples of JSON payloads
          // in project keycloak-event-gateway
        }
      ]
   }
})