Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Keycloak Extension - Custom Event Listener. User create and register events, listen and Call Rest API with Java

License

NotificationsYou must be signed in to change notification settings

cevheri/keycloak-custom-event-listener

TLDR

A Keycloak extension that listens for user events (create/register) and forwards them to your webhook.

Quick Start

# 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

Start Keycloak and Postgres

docker-compose up -d

Build

Start

2. Configuration

Set Up Environment Variables

# Copy example environment filecp .env.example .env# Edit .env file and update the WEBHOOK_URL# Example:# WEBHOOK_URL=https://your-webhook-url.com/endpoint

3. Build and Deploy

Build the Extension

mvn clean package

Deploy to Keycloak (Normal installation without Docker)

# Create providers directory if it doesn't existmkdir -p keycloak/providers# Copy JAR to providers directorycp target/custom-event-listener.jar keycloak/providers/

4. Run Keycloak

Start Docker Container

docker-compose up -d

5. Configure Keycloak

Enable Event Listener

  1. Access Keycloak Admin Console (default:http://localhost:8080)
  2. Login as admin (default credentials: admin/admin)
  3. Navigate to:
    • Events
    • Event configs

Event Configuration

  • Events
  1. Add "custom-event-listener"

Event Configuration

  1. Save

Event Configuration

6. Configure Webhook

Set Up Webhook

  1. Ensure your webhook endpoint is publicly accessible.

  2. Configure theWEBHOOK_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
  3. Test the webhook by sending a sample event from Keycloak or using a tool like Postman to ensure it receives the data correctly.

  4. Monitor your webhook endpoint for incoming requests to verify that events are being forwarded successfully.

Webhook Configuration

Usage

Testing the Integration

Method 1: Admin Console

  1. Users
  2. Add User
  3. Fill in the required fields:
    • Username (required)
    • Email
    • First Name
    • Last Name
  4. Click "Create" to save the new user

Create New User

  1. Check your webhook endpoint for the notification

Webhook Response

Method 2: Self-Registration

  1. Go tohttp://localhost:8080/realms/master/account/#/
  2. Click "Register" or navigate to the registration page
  3. Fill out the registration form and submit

Self Registration

Self Registration

Webhook Response

Architecture

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
Loading

Development

Local Testing

You can use services like webhook.site or RequestBin to test the webhook integration:

  1. Get a temporary webhook URL from webhook.site
  2. Add it to your .env file
  3. Create a user in Keycloak
  4. Check the webhook.site dashboard for the event data

Cleanup

# Stop and remove containersdocker-compose down# Remove volumes (optional)docker-compose down -vdocker volume ls| grep keycloak| awk'{print $2}'| xargs docker volume rm

Troubleshooting

Common Issues

  1. 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
  2. Build failures

    • Ensure Maven is installed
    • Check Java version (requires Java 11+)

Logs

# View Keycloak logsdocker-compose logs -f keycloak

Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

License

Apache-2.0 license

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

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp