Events & Audit
Two types of events
Section titled “Two types of events”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.
Enabling events in the admin console
Section titled “Enabling events in the admin console”Enable login events
Section titled “Enable login events”- Open the admin console and select your realm.
- Click Realm settings in the left sidebar.
- Click the Events tab.
- Under User events settings, toggle Save events to On.
- Set Expiration (e.g.,
7days) to prevent unbounded growth in the database. - Optionally, expand Saved types to restrict which event types are stored.
- Click Save.
Enable admin events
Section titled “Enable admin events”- On the same Events tab, scroll to Admin events settings.
- Toggle Save events to On.
- Optionally enable Include representation to store the full JSON payload of each change (useful for detailed audits, but increases storage).
- Click Save.
Viewing events
Section titled “Viewing events”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.
Querying events via the Admin REST API
Section titled “Querying events via the Admin REST API”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.
Event listeners
Section titled “Event listeners”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:
| Listener | What it does |
|---|---|
jboss-logging | Logs events to the Keycloak server log (enabled by default) |
email | Sends an email to the user on events like LOGIN_ERROR |
To enable a listener:
- Go to Realm settings > Events > Event listeners.
- Add the listener name from the drop-down.
- 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.