npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

keycloak-buddy

v0.0.5

Published

Helper for keycloak admin APIs

Readme

keycloak-buddy

An assistive TypeScript package for interacting with Keycloak Admin REST APIs. Provides strong typing, code completion, and easy-to-use methods for managing users, clients, realms, and more.

Features

  • Full TypeScript support with type declarations
  • Auto code completion and suggestions
  • Covers major Keycloak Admin REST API endpoints
  • Easy error handling with structured error objects

Installation

npm install keycloak-buddy

Node.js Compatibility

  • Minimum supported Node.js version: 16.x

Keycloak Compatibility

  • Tested with Keycloak v21.x and v22.x

Compatibility Matrix

| Package | Keycloak 21.x | Keycloak 22.x | Node.js 14.x | Node.js 16.x | Node.js 18.x | | :------------: | :-----------: | :-----------: | :----------: | :----------: | :----------: | | keycloak-buddy | ✅ | ✅ | ❌ | ✅ | ✅ |

Usage Example

import { KeycloakAdmin } from "keycloak-buddy";

const keycloakAdmin = new KeycloakAdmin({
  baseUrl: "https://keycloak.example.com/auth",
  realm: "master",
  clientId: "admin-cli",
  username: "admin",
  password: "yourpassword",
});

* Do not forget to include the '/auth' part at the end of baseUrl

await keycloakAdmin.init();
const users = await keycloakAdmin.getUsers();

API Reference

User APIs

getUsers()

Input: None

Output: Array of user objects

const users = await keycloakAdmin.getUsers();

getUser(userId: string)

Input: userId (string)

Output: User object

const user = await keycloakAdmin.getUser("user-uuid");

createUser(user: KeycloakUser)

Input: user (KeycloakUser interface)

Output: Created user object

const newUser = await keycloakAdmin.createUser({
  username: "alice",
  email: "[email protected]",
});

updateUser(userId: string, user: KeycloakUser)

Input: userId (string), user (KeycloakUser interface)

Output: Updated user object

await keycloakAdmin.updateUser("user-uuid", { email: "[email protected]" });

deleteUser(userId: string)

Input: userId (string)

Output: Success response

await keycloakAdmin.deleteUser("user-uuid");

resetUserPassword(userId: string, password: string, temporary?: boolean)

Input: userId (string), password (string), temporary (boolean, optional)

Output: Success response

await keycloakAdmin.resetUserPassword("user-uuid", "newPassword", true);

sendVerifyEmail(userId: string)

Input: userId (string)

Output: Success response

await keycloakAdmin.sendVerifyEmail("user-uuid");

getUserSessions(userId: string)

Input: userId (string)

Output: Array of session objects

const sessions = await keycloakAdmin.getUserSessions("user-uuid");

logoutUser(userId: string)

Input: userId (string)

Output: Success response

await keycloakAdmin.logoutUser("user-uuid");

Client APIs

getClients()

Input: None

Output: Array of client objects

const clients = await keycloakAdmin.getClients();

getClient(clientId: string)

Input: clientId (string)

Output: Client object

const client = await keycloakAdmin.getClient("client-uuid");

createClient(client: KeycloakClient)

Input: client (KeycloakClient interface)

Output: Created client object

const newClient = await keycloakAdmin.createClient({
  clientId: "my-app",
  publicClient: true,
});

updateClient(clientId: string, client: KeycloakClient)

Input: clientId (string), client (KeycloakClient interface)

Output: Updated client object

await keycloakAdmin.updateClient("client-uuid", {
  description: "Updated description",
});

deleteClient(clientId: string)

Input: clientId (string)

Output: Success response

await keycloakAdmin.deleteClient("client-uuid");

updateClientAttribute(clientId: string, attributeName: string, value: any)

Input: clientId (string), attributeName (string), value (any)

Output: Updated client object

await keycloakAdmin.updateClientAttribute(
  "client-uuid",
  "accessTokenLifespan",
  "3600"
);

updateClientAccessTokenLifespan(clientId: string, lifespan: number)

Input: clientId (string), lifespan (number)

Output: Updated client object

await keycloakAdmin.updateClientAccessTokenLifespan("client-uuid", 3600);

Realm APIs

getRealm()

Input: None

Output: Realm object

const realm = await keycloakAdmin.getRealm();

Error Handling

All methods throw errors in the following format:

throw new Error(
  JSON.stringify({
    code: number,
    message: string,
    stack: string,
  })
);

How to Handle Errors

You should always wrap your calls in a try/catch block and parse the error message:

try {
  await keycloakAdmin.getUsers();
} catch (err) {
  const error = JSON.parse(err.message);
  // error.code: HTTP status code
  // error.message: Keycloak error message or fallback
  // error.stack: Detailed error stack
  if (error.code === 401) {
    // Handle unauthorized
  }
  console.error(error.code, error.message);
}

Error Codes

  • 401: Unauthorized (invalid credentials)
  • 403: Forbidden (insufficient permissions)
  • 404: Not found (invalid ID or resource)
  • 409: Conflict (duplicate resource)
  • 500: Internal server error or unknown error

Best Practices

  • Always parse the error with JSON.parse(err.message)
  • Log or display error.code and error.message for debugging
  • Use error codes to handle specific cases in your app

TypeScript & IntelliSense

Type declarations are included for all entities and methods. You get auto-complete and suggestions in your IDE when using this package. All input objects (user, client, options) are fully typed for safety and developer experience.

License

ISC