{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/skycloak-io/json-schema/skycloak-io-event-schema.json",
  "title": "Event",
  "description": "A Keycloak event recorded for a cluster. Fields present depend on `category`: user-event fields are absent for admin events and vice versa.",
  "x-generated": "2026-11-25",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/skycloak-io-openapi.yaml#/components/schemas/Event",
  "type": "object",
  "required": [
    "id",
    "timestamp",
    "category",
    "realm_id",
    "realm_name"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "category": {
      "$ref": "#/$defs/EventCategory"
    },
    "realm_id": {
      "type": "string"
    },
    "realm_name": {
      "type": "string"
    },
    "client_id": {
      "type": "string",
      "description": "OAuth2 client ID."
    },
    "ip_address": {
      "type": "string",
      "description": "Source IP address of the request."
    },
    "geo": {
      "allOf": [
        {
          "$ref": "#/$defs/EventGeoLocation"
        }
      ],
      "description": "GeoIP data resolved from `ip_address`."
    },
    "type": {
      "allOf": [
        {
          "$ref": "#/$defs/UserEventType"
        }
      ],
      "description": "User event type code. Present when `category` is `user`."
    },
    "user_id": {
      "type": "string",
      "format": "uuid",
      "description": "Keycloak user UUID. Present when `category` is `user`."
    },
    "username": {
      "type": "string",
      "description": "On a user event, the user the event is about. On an admin event, the\nadministrator who performed the action, when the audit pipeline resolved a\nname for them."
    },
    "session_id": {
      "type": "string",
      "description": "OAuth2 session identifier. Present when `category` is `user`."
    },
    "auth_method": {
      "type": "string",
      "description": "Authentication method. Present when `category` is `user`."
    },
    "identity_provider": {
      "type": "string",
      "description": "Federated identity provider alias, when an external login was used. Present when `category` is `user`."
    },
    "grant_type": {
      "type": "string",
      "description": "OAuth2 grant type. Present when `category` is `user`."
    },
    "is_m2m": {
      "type": "boolean",
      "description": "Whether this was a machine-to-machine (client credentials grant) authentication. Present when `category` is `user`."
    },
    "error": {
      "type": "string",
      "description": "Error code for failed events (e.g. `invalid_user_credentials`). Present when `category` is `user` and the event represents a failure."
    },
    "operation_type": {
      "allOf": [
        {
          "$ref": "#/$defs/AdminOperationType"
        }
      ],
      "description": "Admin operation type (e.g. `CREATE`, `UPDATE`, `DELETE`). Present when `category` is `admin`."
    },
    "resource_type": {
      "type": "string",
      "description": "Type of resource affected (e.g. `USER`, `REALM`, `CLIENT`, `GROUP`). Present when `category` is `admin`."
    },
    "resource_path": {
      "type": "string",
      "description": "Full resource path. Present when `category` is `admin`."
    },
    "auth_user_id": {
      "type": "string",
      "format": "uuid",
      "description": "Keycloak UUID of the administrator who performed the action. Present when\n`category` is `admin` and Keycloak recorded an authenticated actor.\n\nDistinct from `user_id`, which on a user event is the subject of the event.\nOn an admin event the subject is identified by `resource_path` instead, so\nthe actor needs a field of its own.\n\nA UUID. The actor's name, when the audit pipeline resolved one, is on\n`username`; a federated administrator has no UUID id, so `username` may be\npresent while this is absent."
    }
  },
  "$defs": {
    "AdminOperationType": {
      "type": "string",
      "enum": [
        "CREATE",
        "UPDATE",
        "DELETE",
        "ACTION"
      ]
    },
    "EventCategory": {
      "type": "string",
      "enum": [
        "user",
        "admin"
      ],
      "description": "Keycloak event category."
    },
    "EventGeoLocation": {
      "type": "object",
      "required": [
        "country_code",
        "country",
        "city",
        "latitude",
        "longitude"
      ],
      "properties": {
        "country_code": {
          "type": "string",
          "description": "ISO 3166-1 alpha-2 country code."
        },
        "country": {
          "type": "string"
        },
        "city": {
          "type": "string"
        },
        "latitude": {
          "type": "number",
          "format": "double"
        },
        "longitude": {
          "type": "number",
          "format": "double"
        }
      },
      "description": "GeoIP location derived from the source IP address. Present only when GeoIP data is available."
    },
    "UserEventType": {
      "type": "string",
      "enum": [
        "LOGIN",
        "LOGIN_ERROR",
        "LOGOUT",
        "REGISTER",
        "REGISTER_ERROR",
        "CODE_TO_TOKEN",
        "CODE_TO_TOKEN_ERROR",
        "REFRESH_TOKEN",
        "INTROSPECT_TOKEN",
        "CLIENT_LOGIN",
        "CLIENT_LOGIN_ERROR",
        "UPDATE_PROFILE",
        "UPDATE_EMAIL",
        "UPDATE_PASSWORD",
        "UPDATE_TOTP",
        "REMOVE_TOTP",
        "VERIFY_EMAIL",
        "SEND_RESET_PASSWORD",
        "RESET_PASSWORD",
        "FEDERATED_IDENTITY_LINK",
        "REMOVE_FEDERATED_IDENTITY",
        "IDENTITY_PROVIDER_LOGIN",
        "IDENTITY_PROVIDER_FIRST_LOGIN"
      ]
    }
  }
}