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

@jaltech/nestjs-admin-auth

v0.5.0

Published

NestJS module for administering Keycloak users, groups, sessions, and client roles.

Readme

@jaltech/nestjs-admin-auth

npm version license types

[!WARNING] Pre-release — not production-ready. This package is under active development (pre-1.0.0) and has not yet been through a human stabilization and review pass. Its API may change at any time, without a deprecation cycle. It is published for early experimentation and feedback only — do not use it in production. This notice will be removed at the 1.0.0 release.

A NestJS module for administering a Keycloak realm through its Admin REST API: users, groups, sessions, client roles, and Authorization Services. The package exposes contracts and DI tokens so your application depends on interfaces rather than on the concrete Keycloak implementation.

Features

  • Users — create, list, find by email, update profile, enable/disable, set password, send invitation email, add/remove group membership (idempotent), delete.
  • Sessions — list a user's active sessions and revoke them individually.
  • Groups — create root and nested groups, find-or-create by name, list members, assign/remove client roles, delete.
  • Client roles — create roles and compose them (ensureCompositeRole).
  • Authorization Services — idempotent management of scopes, resources, role policies, and scope-based permissions (via the ADMIN_AUTHZ token).
  • Interface-first — the concrete Keycloak classes stay internal; you inject IAdminUsers, IAdminGroups, and IAdminAuthz.

Requirements

  • Node.js >= 20
  • NestJS 11 (@nestjs/common and @nestjs/core ^11.0.0)
  • Peer dependencies:
    • @nestjs/common ^11.0.0
    • @nestjs/core ^11.0.0
    • reflect-metadata ^0.2.0
    • rxjs ^7.8.0
  • A confidential Keycloak client whose service account holds the realm-management roles required for the operations you use.

Installation

# pnpm
pnpm add @jaltech/nestjs-admin-auth @nestjs/common @nestjs/core reflect-metadata rxjs

# npm
npm install @jaltech/nestjs-admin-auth @nestjs/common @nestjs/core reflect-metadata rxjs

Quick start

Register the module with your Keycloak admin client credentials:

import { Module } from '@nestjs/common';
import { AdminAuthModule } from '@jaltech/nestjs-admin-auth';

@Module({
  imports: [
    AdminAuthModule.register({
      authServerUrl: process.env.KEYCLOAK_URL!,
      realm: process.env.KEYCLOAK_REALM!,
      clientId: process.env.KEYCLOAK_ADMIN_CLIENT_ID!,
      clientSecret: process.env.KEYCLOAK_ADMIN_CLIENT_SECRET!,
      sendEmails: process.env.KEYCLOAK_SEND_EMAILS === 'true',
    }),
  ],
})
export class AppModule {}

Then inject the services by their DI tokens:

import { Inject, Injectable } from '@nestjs/common';
import {
  ADMIN_GROUPS,
  ADMIN_USERS,
  type IAdminGroups,
  type IAdminUsers,
  type KcSession,
} from '@jaltech/nestjs-admin-auth';

@Injectable()
export class IdentityAdministrationService {
  constructor(
    @Inject(ADMIN_USERS) private readonly users: IAdminUsers,
    @Inject(ADMIN_GROUPS) private readonly groups: IAdminGroups,
  ) {}

  listSessions(userId: string): Promise<KcSession[]> {
    return this.users.listSessions(userId);
  }
}

API

The public API is limited to contracts and tokens — the concrete Keycloak classes remain internal to the package.

| Export | Kind | Purpose | |---|---|---| | AdminAuthModule | Module | Registers the admin services | | ADMIN_USERS / IAdminUsers | Token / interface | User and session administration | | ADMIN_GROUPS / IAdminGroups | Token / interface | Group and client-role administration | | ADMIN_AUTHZ / IAdminAuthz | Token / interface | Authorization Services administration (idempotent) | | AdminAuthConfig | Type | Module configuration | | CreateUserInput, KcSession | Types | User inputs and session shape | | GroupInfo, GroupMember | Types | Group listing shapes | | AuthzScope, AuthzResource, AuthzPolicy, AuthzPermission, EnsureResourceInput | Types | Authorization Services shapes |

IAdminUsers

createUser, listUsers, findUserByEmail, setPassword, sendInvitationEmail, addToGroup, removeFromGroup, setEnabled, updateProfile, deleteUser, listSessions, revokeSession.

| Method | Behavior | |---|---| | findUserByEmail(email) | Exact, case-insensitive match (GET /users?email=…&exact=true). Resolves to { id, email, enabled }, or null when no account has this email. | | setEnabled(sub, enabled) | Enables or disables the account (PUT /users/{id} with enabled only). Profile, groups, and credentials are left untouched. | | addToGroup(sub, groupId) | Idempotent: adding a user who is already a member does not throw (Keycloak answers 204). Throws if the user or group does not exist. | | removeFromGroup(sub, groupId) | Idempotent: removing a non-member does not throw (Keycloak answers 204); a 404 for a missing user or group is tolerated as well. |

IAdminGroups

createRole, deleteRole (idempotent: an already missing role does not throw), ensureCompositeRole, createGroup (root or nested via parentId), findGroupByName, findGroupByPath (full path, nested groups included), assignRole, removeRole, deleteGroup, listGroups, listMembers.

IAdminAuthz

Idempotent management of the client's Authorization Services: ensureAuthorizationEnabled, ensureDecisionStrategy, ensureScope, ensureResource, ensureRolePolicy, setResourcePermissions (a scope × policies matrix, denying by default when no policy is set), plus the matching list*/find*/delete* operations. The ensure* methods are safe to run repeatedly, which makes them suitable for seeding.

Contributing

This package lives in the nestjs-libs monorepo.

git clone https://github.com/jaltech-io/nestjs-libs.git
cd nestjs-libs
pnpm install
pnpm check   # typecheck + build + verify

The package builds to CommonJS with TypeScript declarations. Contributions are welcome — please open an issue to discuss substantial changes first.

License

MIT © 2026 Jaltech