---
openapi: 3.1.0
tags:
- name: Auditing
  description: Query last-login audit data for users and clients
components:
  securitySchemes:
    bearerAuth:
      type: http
      description: "Keycloak admin access token. Unless KC_AUD_DISABLE_ROLE_CHECK=true,\
        \ the token must carry the realm role configured via KC_AUD_DEFAULT_ROLE (default:\
        \ view-users)."
      scheme: bearer
      bearerFormat: JWT
  schemas:
    AuditedClientRepresentation:
      type: object
      properties:
        id:
          type: string
        clientId:
          type: string
        name:
          type: string
        description:
          type: string
        type:
          type: string
        rootUrl:
          type: string
        adminUrl:
          type: string
        baseUrl:
          type: string
        surrogateAuthRequired:
          type: boolean
        enabled:
          type: boolean
        alwaysDisplayInConsole:
          type: boolean
        clientAuthenticatorType:
          type: string
        secret:
          type: string
        registrationAccessToken:
          type: string
        defaultRoles:
          type: array
          items:
            type: string
          deprecated: true
        redirectUris:
          type: array
          items:
            type: string
        webOrigins:
          type: array
          items:
            type: string
        notBefore:
          type: integer
          format: int32
        bearerOnly:
          type: boolean
        consentRequired:
          type: boolean
        standardFlowEnabled:
          type: boolean
        implicitFlowEnabled:
          type: boolean
        directAccessGrantsEnabled:
          type: boolean
        serviceAccountsEnabled:
          type: boolean
        authorizationServicesEnabled:
          type: boolean
        directGrantsOnly:
          type: boolean
          deprecated: true
        publicClient:
          type: boolean
        frontchannelLogout:
          type: boolean
        protocol:
          type: string
        attributes:
          type: object
          additionalProperties:
            type: string
        authenticationFlowBindingOverrides:
          type: object
          additionalProperties:
            type: string
        fullScopeAllowed:
          type: boolean
        nodeReRegistrationTimeout:
          type: integer
          format: int32
        registeredNodes:
          type: object
          additionalProperties:
            type: integer
            format: int32
        protocolMappers:
          type: array
          items:
            $ref: "#/components/schemas/ProtocolMapperRepresentation"
        clientTemplate:
          type: string
          deprecated: true
        useTemplateConfig:
          type: boolean
          deprecated: true
        useTemplateScope:
          type: boolean
          deprecated: true
        useTemplateMappers:
          type: boolean
          deprecated: true
        defaultClientScopes:
          type: array
          items:
            type: string
        optionalClientScopes:
          type: array
          items:
            type: string
        authorizationSettings:
          $ref: "#/components/schemas/ResourceServerRepresentation"
        access:
          type: object
          additionalProperties:
            type: boolean
        origin:
          type: string
        realm:
          type: string
        lastLogin:
          type: string
    AuditedUserRepresentation:
      type: object
      properties:
        id:
          type: string
        username:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        email:
          type: string
        emailVerified:
          type: boolean
        attributes:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
        userProfileMetadata:
          $ref: "#/components/schemas/UserProfileMetadata"
        enabled:
          type: boolean
        self:
          type: string
        origin:
          type: string
        createdTimestamp:
          type: integer
          format: int64
        totp:
          type: boolean
        federationLink:
          type: string
        serviceAccountClientId:
          type: string
        credentials:
          type: array
          items:
            $ref: "#/components/schemas/CredentialRepresentation"
        disableableCredentialTypes:
          type: array
          uniqueItems: true
          items:
            type: string
        requiredActions:
          type: array
          items:
            type: string
        federatedIdentities:
          type: array
          items:
            $ref: "#/components/schemas/FederatedIdentityRepresentation"
        realmRoles:
          type: array
          items:
            type: string
        clientRoles:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
        clientConsents:
          type: array
          items:
            $ref: "#/components/schemas/UserConsentRepresentation"
        notBefore:
          type: integer
          format: int32
        verifiableCredentials:
          type: array
          items:
            $ref: "#/components/schemas/UserVerifiableCredentialRepresentation"
        issuedVerifiableCredentials:
          type: array
          items:
            $ref: "#/components/schemas/IssuedVerifiableCredentialRepresentation"
        applicationRoles:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
          deprecated: true
        socialLinks:
          type: array
          items:
            $ref: "#/components/schemas/SocialLinkRepresentation"
          deprecated: true
        groups:
          type: array
          items:
            type: string
        access:
          type: object
          additionalProperties:
            type: boolean
        lastLogin:
          type: string
        realm:
          type: string
        clientLogins:
          type: object
          additionalProperties:
            type: string
    AuthorizationSchema:
      type: object
      properties:
        resourceTypes:
          type: object
          additionalProperties:
            $ref: "#/components/schemas/ResourceType"
    CredentialRepresentation:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
        userLabel:
          type: string
        createdDate:
          type: integer
          format: int64
        secretData:
          type: string
        credentialData:
          type: string
        priority:
          type: integer
          format: int32
        value:
          type: string
        temporary:
          type: boolean
        device:
          type: string
          deprecated: true
        hashedSaltedValue:
          type: string
          deprecated: true
        salt:
          type: string
          deprecated: true
        hashIterations:
          type: integer
          format: int32
          deprecated: true
        counter:
          type: integer
          format: int32
          deprecated: true
        algorithm:
          type: string
          deprecated: true
        digits:
          type: integer
          format: int32
          deprecated: true
        period:
          type: integer
          format: int32
          deprecated: true
        config:
          type: object
          deprecated: true
          $ref: "#/components/schemas/MultivaluedHashMapStringString"
        federationLink:
          type: string
    DecisionStrategy:
      type: string
      enum:
      - AFFIRMATIVE
      - UNANIMOUS
      - CONSENSUS
    FederatedIdentityRepresentation:
      type: object
      properties:
        identityProvider:
          type: string
        userId:
          type: string
        userName:
          type: string
    IssuedVerifiableCredentialRepresentation:
      type: object
      properties:
        id:
          type: string
        userId:
          type: string
        credentialType:
          type: string
        issuedAt:
          type: integer
          format: int64
        expiresAt:
          type: integer
          format: int64
        clientId:
          type: string
        clientName:
          type: string
        clientBaseUrl:
          type: string
        revision:
          type: string
    Logic:
      type: string
      enum:
      - POSITIVE
      - NEGATIVE
    MultivaluedHashMapStringString:
      type: object
      additionalProperties:
        type: array
        items:
          type: string
    PolicyEnforcementMode:
      type: string
      enum:
      - ENFORCING
      - PERMISSIVE
      - DISABLED
    PolicyRepresentation:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        description:
          type: string
        type:
          type: string
        policies:
          type: array
          uniqueItems: true
          items:
            type: string
        resources:
          type: array
          uniqueItems: true
          items:
            type: string
        scopes:
          type: array
          uniqueItems: true
          items:
            type: string
        logic:
          $ref: "#/components/schemas/Logic"
        decisionStrategy:
          $ref: "#/components/schemas/DecisionStrategy"
        owner:
          type: string
        resourceType:
          type: string
        resourcesData:
          type: array
          uniqueItems: true
          items:
            $ref: "#/components/schemas/ResourceRepresentation"
        scopesData:
          type: array
          uniqueItems: true
          items:
            $ref: "#/components/schemas/ScopeRepresentation"
        config:
          type: object
          additionalProperties:
            type: string
    ProtocolMapperRepresentation:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        protocol:
          type: string
        protocolMapper:
          type: string
        consentRequired:
          type: boolean
          deprecated: true
        consentText:
          type: string
          deprecated: true
        config:
          type: object
          additionalProperties:
            type: string
    ResourceOwnerRepresentation:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
    ResourceRepresentation:
      type: object
      properties:
        _id:
          type: string
        name:
          type: string
        uris:
          type: array
          uniqueItems: true
          items:
            type: string
        type:
          type: string
        scopes:
          type: array
          uniqueItems: true
          items:
            $ref: "#/components/schemas/ScopeRepresentation"
        icon_uri:
          type: string
        owner:
          type: object
          readOnly: true
          $ref: "#/components/schemas/ResourceOwnerRepresentation"
        ownerManagedAccess:
          type: boolean
        displayName:
          type: string
        attributes:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
        uri:
          type: string
          writeOnly: true
          deprecated: true
        scopesUma:
          type: array
          uniqueItems: true
          items:
            $ref: "#/components/schemas/ScopeRepresentation"
    ResourceServerRepresentation:
      type: object
      properties:
        id:
          type: string
        clientId:
          type: string
        name:
          type: string
        allowRemoteResourceManagement:
          type: boolean
        policyEnforcementMode:
          $ref: "#/components/schemas/PolicyEnforcementMode"
        resources:
          type: array
          items:
            $ref: "#/components/schemas/ResourceRepresentation"
        policies:
          type: array
          items:
            $ref: "#/components/schemas/PolicyRepresentation"
        scopes:
          type: array
          items:
            $ref: "#/components/schemas/ScopeRepresentation"
        decisionStrategy:
          $ref: "#/components/schemas/DecisionStrategy"
        authorizationSchema:
          $ref: "#/components/schemas/AuthorizationSchema"
    ResourceType:
      type: object
      properties:
        type:
          type: string
        scopes:
          type: array
          uniqueItems: true
          items:
            type: string
        scopeAliases:
          type: object
          additionalProperties:
            type: array
            uniqueItems: true
            items:
              type: string
        groupType:
          type: string
    ScopeRepresentation:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        iconUri:
          type: string
        policies:
          type: array
          items:
            $ref: "#/components/schemas/PolicyRepresentation"
        resources:
          type: array
          items:
            $ref: "#/components/schemas/ResourceRepresentation"
        displayName:
          type: string
    SocialLinkRepresentation:
      type: object
      properties:
        socialProvider:
          type: string
        socialUserId:
          type: string
        socialUsername:
          type: string
    UserConsentRepresentation:
      type: object
      properties:
        clientId:
          type: string
        grantedClientScopes:
          type: array
          items:
            type: string
        createdDate:
          type: integer
          format: int64
        lastUpdatedDate:
          type: integer
          format: int64
        grantedRealmRoles:
          type: array
          items:
            type: string
          deprecated: true
    UserProfileAttributeGroupMetadata:
      type: object
      properties:
        name:
          type: string
        displayHeader:
          type: string
        displayDescription:
          type: string
        annotations:
          type: object
          additionalProperties: {}
    UserProfileAttributeMetadata:
      type: object
      properties:
        name:
          type: string
        displayName:
          type: string
        required:
          type: boolean
        readOnly:
          type: boolean
        annotations:
          type: object
          additionalProperties: {}
        validators:
          type: object
          additionalProperties:
            type: object
            additionalProperties: {}
        group:
          type: string
        multivalued:
          type: boolean
        defaultValue:
          type: string
    UserProfileMetadata:
      type: object
      properties:
        attributes:
          type: array
          items:
            $ref: "#/components/schemas/UserProfileAttributeMetadata"
        groups:
          type: array
          items:
            $ref: "#/components/schemas/UserProfileAttributeGroupMetadata"
    UserVerifiableCredentialRepresentation:
      type: object
      properties:
        credentialScopeName:
          type: string
        credentialConfigurationId:
          type: string
        revision:
          type: string
        createdDate:
          type: integer
          format: int64
        updatedDate:
          type: integer
          format: int64
        userAttributes:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
paths:
  /auditing/clients:
    get:
      summary: List audited clients
      description: Returns clients with their last-login timestamp. Scoping rules
        match `listUsers`.
      operationId: listClients
      tags:
      - Auditing
      parameters:
      - description: "When the caller has all-realm access, restrict results to this\
          \ realm only."
        name: realm
        in: query
        schema:
          type: string
      - description: Use `current-realm` to force single-realm results even for master
          tokens.
        name: scope
        in: query
        schema:
          type: string
      responses:
        "200":
          description: Audited clients
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/AuditedClientRepresentation"
        "401":
          description: Missing or invalid bearer token
        "403":
          description: "Token lacks the required realm role, or external access is\
            \ disabled"
      security:
      - bearerAuth: []
      servers:
      - url: "{keycloakBaseUrl}/realms/{realm}"
        variables:
          keycloakBaseUrl:
            description: Base URL of the Keycloak server
            default: http://localhost:8080
          realm:
            description: Realm whose auditing resource is being called
            default: master
  /auditing/clients/csv:
    get:
      summary: Download audited clients as CSV
      description: "Same data as `listClients`, returned as a CSV attachment."
      operationId: downloadClientsCsv
      tags:
      - Auditing
      parameters:
      - description: Restrict results to this realm only.
        name: realm
        in: query
        schema:
          type: string
      - description: Use `current-realm` to force single-realm results.
        name: scope
        in: query
        schema:
          type: string
      responses:
        "200":
          description: "CSV report (Content-Disposition: attachment)"
          content:
            text/csv:
              schema:
                format: binary
                type: string
        "401":
          description: Missing or invalid bearer token
        "403":
          description: "Token lacks the required realm role, or external access is\
            \ disabled"
      security:
      - bearerAuth: []
      servers:
      - url: "{keycloakBaseUrl}/realms/{realm}"
        variables:
          keycloakBaseUrl:
            description: Base URL of the Keycloak server
            default: http://localhost:8080
          realm:
            description: Realm whose auditing resource is being called
            default: master
  /auditing/download:
    get:
      summary: Audit reporting download page
      description: Self-contained HTML page with buttons that call the JSON/CSV endpoints.
        Served without authentication; the page itself prompts for a bearer token.
      operationId: downloadPage
      tags:
      - Auditing
      responses:
        "200":
          description: HTML page
          content:
            text/html:
              schema:
                type: string
      servers:
      - url: "{keycloakBaseUrl}/realms/{realm}"
        variables:
          keycloakBaseUrl:
            description: Base URL of the Keycloak server
            default: http://localhost:8080
          realm:
            description: Realm whose auditing resource is being called
            default: master
  /auditing/users:
    get:
      summary: List audited users
      description: Returns users with their global and per-client last-login timestamps.
        Non-master callers only see their own realm unless KC_AUD_GLOBAL_MASTER_ACCESS=true;
        master-realm tokens are auto-scoped to all realms.
      operationId: listUsers
      tags:
      - Auditing
      parameters:
      - description: "When the caller has all-realm access, restrict results to this\
          \ realm only."
        name: realm
        in: query
        schema:
          type: string
      - description: Use `current-realm` to force single-realm results even for master
          tokens. Omit or use `all-realms` for the default behaviour.
        name: scope
        in: query
        schema:
          type: string
      responses:
        "200":
          description: Audited users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/AuditedUserRepresentation"
        "401":
          description: Missing or invalid bearer token
        "403":
          description: "Token lacks the required realm role, or external access is\
            \ disabled"
      security:
      - bearerAuth: []
      servers:
      - url: "{keycloakBaseUrl}/realms/{realm}"
        variables:
          keycloakBaseUrl:
            description: Base URL of the Keycloak server
            default: http://localhost:8080
          realm:
            description: Realm whose auditing resource is being called
            default: master
  /auditing/users/csv:
    get:
      summary: Download audited users as CSV
      description: "Same data as `listUsers`, returned as a CSV attachment."
      operationId: downloadUsersCsv
      tags:
      - Auditing
      parameters:
      - description: Restrict results to this realm only.
        name: realm
        in: query
        schema:
          type: string
      - description: Use `current-realm` to force single-realm results.
        name: scope
        in: query
        schema:
          type: string
      responses:
        "200":
          description: "CSV report (Content-Disposition: attachment)"
          content:
            text/csv:
              schema:
                format: binary
                type: string
        "401":
          description: Missing or invalid bearer token
        "403":
          description: "Token lacks the required realm role, or external access is\
            \ disabled"
      security:
      - bearerAuth: []
      servers:
      - url: "{keycloakBaseUrl}/realms/{realm}"
        variables:
          keycloakBaseUrl:
            description: Base URL of the Keycloak server
            default: http://localhost:8080
          realm:
            description: Realm whose auditing resource is being called
            default: master
info:
  title: Keycloak Auditor REST API
  version: 2.4.5
  description: |-
    Query last-login audit data for users and clients recorded by the
                keycloak-auditor SPI. Served under /realms/{realm}/auditing/.
  license:
    name: MIT
