Skip to main content
A type-safe API client for the Keycloak Admin and Account APIs, auto-generated from the official OpenAPI specification with full TypeScript support.

Features

  • Type-Safe - Full TypeScript support with auto-generated types from OpenAPI spec
  • Admin API - Complete Keycloak Admin REST API coverage
  • Account API - User account management endpoints
  • Auto-Updated - Daily regeneration from upstream OpenAPI specs

Installation

pnpm add keycloak-api

Usage

Admin API Usage

import { createClient } from "keycloak-api";

const client = createClient({
  baseUrl: "https://keycloak.example.com/admin/realms",
  headers: {
    Authorization: `Bearer ${process.env.KEYCLOAK_ADMIN_TOKEN}`,
  },
});

// List all realms
const realms = await client.getRealms();

// Get users in a realm
const users = await client.getUsers({
  realm: "my-realm",
});

// Create a new user
const user = await client.createUser({
  realm: "my-realm",
  body: {
    username: "newuser",
    email: "user@example.com",
    enabled: true,
  },
});

Type Exports

import type { Types } from "keycloak-api";

// Use TypeScript types
type Realm = Types.RealmRepresentation;
type User = Types.UserRepresentation;
type Client = Types.ClientRepresentation;

API Reference

The client exposes Keycloak API endpoints including:

Admin API

  • Realms - Realm management and configuration
  • Users - User CRUD operations and management
  • Clients - OAuth/OIDC client configuration
  • Roles - Role management and assignment
  • Groups - Group management and membership
  • Identity Providers - Federation configuration
  • Authentication - Authentication flow configuration
  • And more…

Account API

  • Profile - User profile management
  • Credentials - Credential management
  • Sessions - Active session management
For the complete API reference, see the Keycloak Admin REST API documentation.