A Keycloak extension that listens for user events (create/register) and forwards them to your webhook.
# Clone the repository
git clone https://github.com/cevher/keycloak-custom-event-listener.git
cd keycloak-custom-event-listener
# Set up environment variables
cp .env.example .env
# Edit .env and set your WEBHOOK_URL
# Build the extension
mvn clean package
# Copy JAR to Keycloak providers
cp target/custom-event-listener.jar providers/
# or
### Attach keycloak dockerVolume (already in docker-compose file)
```yaml
volumes:
- ../../../target/custom-event-listener.jar://opt/jboss/keycloak/standalone/deployments/custom-event-listener.jar
docker-compose up -d
# Copy example environment file
cp .env.example .env
# Edit .env file and update the WEBHOOK_URL
# Example:
# WEBHOOK_URL=https://your-webhook-url.com/endpoint
mvn clean package
# Create providers directory if it doesn't exist
mkdir -p keycloak/providers
# Copy JAR to providers directory
cp target/custom-event-listener.jar keycloak/providers/
docker-compose up -d
- Access Keycloak Admin Console (default: http://localhost:8080)
- Login as admin (default credentials: admin/admin)
- Navigate to:
- Events
- Event configs
- Events
- Add "custom-event-listener"
- Save
-
Ensure your webhook endpoint is publicly accessible.
-
Configure the
WEBHOOK_URL
in thedocker-compose.yaml
file:services: keycloak: image: quay.io/keycloak/keycloak:latest environment: - WEBHOOK_URL=https://your-webhook-url.com/endpoint ports: - "8080:8080" volumes: - ./providers:/opt/keycloak/providers
-
Test the webhook by sending a sample event from Keycloak or using a tool like Postman to ensure it receives the data correctly.
-
Monitor your webhook endpoint for incoming requests to verify that events are being forwarded successfully.
- Users
- Add User
- Fill in the required fields:
- Username (required)
- First Name
- Last Name
- Click "Create" to save the new user
- Check your webhook endpoint for the notification
- Go to http://localhost:8080/realms/master/account/#/
- Click "Register" or navigate to the registration page
- Fill out the registration form and submit
sequenceDiagram
participant User
participant Keycloak
participant EventListener
participant WebhookEndpoint
User->>Keycloak: Registers or Creates an Account
Keycloak-->>EventListener: Emits User Registration Event
EventListener->>WebhookEndpoint: Sends Event Data
WebhookEndpoint-->>EventListener: Acknowledgement
You can use services like webhook.site or RequestBin to test the webhook integration:
- Get a temporary webhook URL from webhook.site
- Add it to your .env file
- Create a user in Keycloak
- Check the webhook.site dashboard for the event data
# Stop and remove containers
docker-compose down
# Remove volumes (optional)
docker-compose down -v
docker volume ls | grep keycloak | awk '{print $2}' | xargs docker volume rm
-
Webhook not receiving events
- Check if the WEBHOOK_URL in .env is correct
- Verify the event listener is enabled in Keycloak
- Check Keycloak logs for any errors
-
Build failures
- Ensure Maven is installed
- Check Java version (requires Java 11+)
# View Keycloak logs
docker-compose logs -f keycloak
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.