Skip to content

Events & Audit

Keycloak records two distinct categories of events:

  • Login events — actions performed by end-users: successful logins, failed login attempts, token refreshes, logouts, password resets, and more. These are stored per-realm and are the primary audit trail for user activity.
  • Admin events — actions performed by administrators in the admin console or via the Admin REST API: realm creation, client registration, user updates, role assignments, and so on.

Both types are disabled by default. You must enable them explicitly.

  1. Open the admin console and select your realm.
  2. Click Realm settings in the left sidebar.
  3. Click the Events tab.
  4. Under User events settings, toggle Save events to On.
  5. Set Expiration (e.g., 7 days) to prevent unbounded growth in the database.
  6. Optionally, expand Saved types to restrict which event types are stored.
  7. Click Save.
  1. On the same Events tab, scroll to Admin events settings.
  2. Toggle Save events to On.
  3. Optionally enable Include representation to store the full JSON payload of each change (useful for detailed audits, but increases storage).
  4. Click Save.

After events are enabled, they accumulate in real time.

Login events: In the left sidebar, click Events. The User events sub-tab shows a paginated list of login events with timestamp, user, IP address, and event type. Use the search filters to narrow by event type (e.g., LOGIN_ERROR) or date range.

Admin events: Click the Admin events sub-tab. Each entry shows the operation type (CREATE, UPDATE, DELETE), the resource type (e.g., USER, CLIENT), and optionally the before/after representation.

You can also fetch events programmatically:

curl -s "https://localhost:8080/admin/realms/my-app/events?type=LOGIN_ERROR&max=20" \
  -H "Authorization: Bearer ${TOKEN}" \
  | jq .

Replace my-app with your realm name and \${TOKEN} with a valid admin token.

Beyond storing events in the database, Keycloak supports event listeners — plugins that react to events in real time. Two built-in listeners are useful immediately:

ListenerWhat it does
jboss-loggingLogs events to the Keycloak server log (enabled by default)
emailSends an email to the user on events like LOGIN_ERROR

To enable a listener:

  1. Go to Realm settings > Events > Event listeners.
  2. Add the listener name from the drop-down.
  3. Click Save.

For custom integrations (e.g., sending events to a webhook or a message queue), you can implement a Keycloak SPI (EventListenerProvider) and deploy it as a provider JAR.

What is the difference between login events and admin events in Keycloak?
Where in the admin console do you enable event storage?
What does enabling "Include representation" for admin events do?
Which built-in event listener sends an email to the user on login errors?