Skip to main content

Audit Log API

You can publish your own application's events into the same event stream as Keycloak's access and admin events. Published events are delivered to your webhooks alongside the built-in events, so a single endpoint receives everything.

Endpoint​

Events are posted to the following endpoint. Replace <your-cluster-host> and <realm> with your values. The endpoint accepts JSON.

POST https://<your-cluster-host>/auth/realms/<realm>/events

Authentication​

The caller must have the publish-events role. It is a client role of the realm-management client in each realm, and is included in the realm-admin composite role. Grant it to a service account for backend calls, or to the users whose tokens your application uses. Send the access token in the Authorization header:

Authorization: Bearer <accessToken>

Field definitions​

Event​

The Event object describes the full action that took place in the system.

NameTypeRequiredDescription
uidstringprovidedAn ID unique to this event
timenumberoptional 1UNIX timestamp of the event, in milliseconds
realmIdstringprovidedThe realm ID where the action took place
authDetailsAuthDetailsprovided-
typestringrequiredA description of the action that took place
operationTypestringoptionalWhat operation was executed on a resource (CREATE, DELETE, UPDATE, ACTION)
resourcePathstringoptionalIf the action changed a resource, this is meant to be the / delimited resource path
resourceTypestringoptionalIf the action changed a resource, this is the resource's type
detailsobjectoptionalAn optional hash of values pertaining to the action that took place
errorstringoptionalAn optional error string for tracing purposes if the action resulted in a failure

The type must not start with access., admin., or system.. Those prefixes are reserved for events generated by the server.

AuthDetails​

The AuthDetails object describes the user or service account that published the event. Omit it when posting an event; the server fills it in from the access token.

NameTypeRequiredDescription
realmIdstringprovidedThe realm of the caller
clientIdstringprovidedThe client the caller's token was issued to
userIdstringprovidedThe user ID of the caller
ipAddressstringprovidedThe IP address of the caller
usernamestringprovidedThe username of the caller
sessionIdstringprovidedA unique ID of the current login session, if any

Responses​

HTTP status codes indicate success or failure.

Status codeDescription
202Event received
400Malformed event, for example a missing type
401Missing or invalid token, or the caller lacks publish-events
409Reserved event type
5xxServer error

Example​

curl https://<your-cluster-host>/auth/realms/my-realm/events \
--header "Content-Type: application/json" \
--header "Authorization: Bearer <accessToken>" \
--data '{ "type": "billing.invoice-paid", "details": { "invoiceId": "inv_123" } }'

Footnotes​

  1. If time is not passed by the caller, it will be provided by the server ↩