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-admin-sdk

v1.0.0

Published

Node.js SDK for Keycloak Admin API

Downloads

11

Readme

Keycloak Admin SDK

A TypeScript SDK for interacting with the Keycloak Admin REST API.

Features

  • Comprehensive TypeScript definitions for Keycloak Admin API entities
  • Support for all major Keycloak Admin REST API endpoints
  • Clean, SOLID-based architecture
  • Enhanced error handling and debugging capabilities
  • Optimized resource creation with ID extraction from Location headers
  • Comprehensive APIs for Organizations, Scope Mappings, and Role Mappings
  • Security features including Attack Detection API for brute force protection
  • Simplified API structure with reduced abstractions
  • End-to-end testing capabilities with robust error handling

Installation

npm install keycloak-admin-sdk

Usage

import KeycloakClient from 'keycloak-admin-sdk';

// Initialize the SDK
const sdk = new KeycloakClient({
  baseUrl: 'http://localhost:8080',
  realm: 'master',
  authMethod: 'password',
  credentials: {
    username: 'admin',
    password: 'admin',
    clientId: 'admin-cli'
  }
});

// Example: List all users
async function listUsers() {
  try {
    const users = await sdk.users.list();
    
    users.forEach(user => {
      console.log(`- ${user.username} (${user.email})`);
    });
  } catch (error) {
    console.error('Error listing users:', error);
  }
}

listUsers();

API Documentation

The SDK provides the following main API classes:

  • UsersApi: Methods for managing users
  • GroupsApi: Methods for managing groups
  • RealmsApi: Methods for managing realms
  • ClientsApi: Methods for managing clients
  • OrganizationsApi: Methods for managing organizations and their members
  • RolesApi: Methods for managing roles and composite roles
  • RoleMappingsApi: Methods for managing role mappings for users and groups
  • ScopeMappingsApi: Methods for managing scope mappings for clients and client scopes
  • ComponentApi: Methods for managing components
  • AttackDetectionApi: Methods for managing brute force detection
  • KeysApi: Methods for managing realm keys and certificates
  • IdentityProvidersApi: Methods for managing identity providers
  • AuthorizationServicesApi: Methods for managing authorization services

Each API class provides methods for CRUD operations and more specialized functionality, with robust error handling and detailed logging for easier debugging.

End-to-End Testing

The SDK includes comprehensive end-to-end tests that verify functionality against a running Keycloak instance.

Setting Up Tests

  1. Copy the .env.sample file to .env and configure your Keycloak connection:
cp .env.sample .env
  1. Edit the .env file with your Keycloak server details:
# Keycloak Server Configuration
KEYCLOAK_BASE_URL=http://localhost:8080
KEYCLOAK_REALM=master
KEYCLOAK_AUTH_METHOD=password

# Admin Credentials
KEYCLOAK_ADMIN_USERNAME=admin
KEYCLOAK_ADMIN_PASSWORD=admin
KEYCLOAK_ADMIN_CLIENT_ID=admin-cli

# Test Configuration
TEST_TIMEOUT=30000
  1. Make sure you have a running Keycloak instance available at the specified URL.

    Important: Keycloak should be configured with email support for the tests to pass. You can use the provided Docker Compose setup in the docker folder which includes a mail server (MailHog):

    cd docker
    docker-compose up -d

    This will start:

    • Keycloak with email support configured
    • MailHog mail server accessible at http://localhost:8025

Running Tests

To run the end-to-end tests:

npm run test:e2e

The tests will:

  1. Create a test realm and client
  2. Test the Realms API functionality
  3. Test the Clients API functionality
  4. Create and test groups and users
  5. Clean up all created resources

Examples

The SDK includes several examples in the examples directory demonstrating how to use various APIs:

These examples cover various aspects of Keycloak administration:

  • Realm management
  • Client management
  • User and group operations
  • Organization management
  • Role and role mappings management
  • Scope mappings management
  • Certificate and key management
  • Attack detection and brute force protection
  • Identity provider configuration
  • Authorization services management
  • Error handling and debugging techniques

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT