- Notifications
You must be signed in to change notification settings - Fork14
Keycloak Extension - Custom Event Listener. User create and register events, listen and Call Rest API with Java
License
cevheri/keycloak-custom-event-listener
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Keycloak extension that listens for user events (create/register) and forwards them to your webhook.
# Clone the repositorygit clone https://github.com/cevher/keycloak-custom-event-listener.gitcd keycloak-custom-event-listener# Set up environment variablescp .env.example .env# Edit .env and set your WEBHOOK_URL# Build the extensionmvn clean package# Copy JAR to Keycloak providerscp 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 filecp .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 existmkdir -p keycloak/providers# Copy JAR to providers directorycp 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:latestenvironment:- WEBHOOK_URL=https://your-webhook-url.com/endpointports:- "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 tohttp://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 containersdocker-compose down# Remove volumes (optional)docker-compose down -vdocker 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 logsdocker-compose logs -f keycloak
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
About
Keycloak Extension - Custom Event Listener. User create and register events, listen and Call Rest API with Java
Topics
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.