/keycloak-cdc

Using Change Data Capture (CDC) to stream users created in Keycloak to your application

Primary LanguageJavaApache License 2.0Apache-2.0

Architecture

Quickly for the impatient

Clone this repository and navigate into the project directory and run the following commands:

> docker-compose -f docker-compose.nobuild.yml up -d

You will need docker, docker-compose and git to run this example.

Setting up Debezium

Make a JSON POST request (I am using cURL in this example - Use any REST client of choice) using the payload indicated below:

> curl -s \
     -X "POST" "http://localhost:8083/connectors/" \
     -H "Content-Type: application/json" \
     -d '{
  "name": "keycloak-connector",
  "config": {
    "connector.class": "io.debezium.connector.postgresql.PostgresConnector",
    "database.hostname": "postgres",
    "database.port": "5432",
    "slot.name": "keycloak_debezium",
    "plugin.name": "pgoutput",
    "database.user": "postgres",
    "database.password": "postgrespwd",
    "database.dbname": "sample",
    "database.server.name": "keycloak",
    "schema.whitelist": "sample",
    "table.whitelist": "sample.user_role_mapping,sample.user_group_membership,sample.keycloak_role,sample.user_entity"
  }
}'

Navigate to the URL and switch to the sample realm to start hacking;

Use the credentials below to log in:

Username: test
Password: test

Introduction

Preview

This repository contains a sample project on how to stream in real-time, users created in Keycloak to your application.

Prerequisite

To be able to run this application, you need the following to be setup:

  • Postgres
  • Zookeeper
  • Kafka
  • Kafka Connect
  • Keycloak
  • Java
  • Gradle

You don't have to set these up if you're using docker. I have provided a compose file to ease this.

Develop

For developers that want to contribute, you need Java setup. Clone this repository and navigate to the app-service directory. From there, run the following command:

> ./gradlew run

View real-time changes with:

> curl http://127.0.0.1:8082/api/users/stream