Repository navigation
npm install keycloak-api-ts@2.0.0Rewritten for Keycloak 24, 25 and 26 (tested up to 26.8.1). Requires Node.js 20 or newer.
Breaking changes and migration
baseUrlhas no/auth. Usehttps://sso.example.cominstead ofhttps://sso.example.com/auth. Keep/authonly if your server runs with--http-relative-path=/auth.- HTTP errors no longer throw.
- Every method resolves to
ApiResponse<T>withsuccess,status,statusTextand eitherdataorerror. - Replace
try/catcharound calls withif (!response.success). - Network errors still reject.
- Token failures throw
KeycloakAuthError(withstatus,error,errorDescription).
- Every method resolves to
createmethods return the new id (from theLocationheader) indata.- Authentication:
credentials.grantTypeis honoured (client_credentials,password,refresh_token).realmNamedefaults tomaster.- The
openid-clientdependency was removed. - Tokens renew from
expires_ininstead of a fixed 58 s timer. - Call
dispose()to stop background renewal.
- Types are generated from the Keycloak 26.8.1 OpenAPI spec.
- The names (
User,Client,Realm...) are unchanged. - They mirror the current server: new fields such as
Realm.defaultRoleandUser.userProfileMetadataare present. Deprecated fields (e.g.defaultRoles) are kept but ignored by recent servers. - Almost every field is optional.
lib/types/server-settings.tswas removed. ImportServerSettingsfrom the package root.
- The names (
- Retry and throttling apply only to the library's own axios instance. They no longer touch the global axios. Configure them with
retriesandrequestsPerSecond. authentication.flows.executions.create(realm, flowAlias, provider)now posts to/flows/{alias}/executions/execution. It used to post to/flows, which was wrong.executions.getreturns a single execution.- Sub-flows use
createSubFlow.
userStorageProvider.list/listMappersquery components by type, because the old endpoints do not exist in Keycloak.users.getRoleMappingsreturnsMappingsinstead ofstring.
New
groupsmodule: CRUD, subgroups, count, members.users:listRealmRoleMappings,listCompositeRealmRoleMappings,addRealmRoleMapping,deleteRealmRoleMapping.listGroups,addToGroup,removeFromGroup.getProfile/updateProfile(user profile config).- New query parameters:
q,idpAlias,idpUserId,emailVerified,briefRepresentation.
roles.getById,roles.listUsers;authentication.flows.copy.clientScopesmodule: CRUD, realm default/optional client scopes, scope mappings and protocol mappers.identityProvidersmodule: CRUD, import config, export, reload keys, provider types, mappers, fine-grained permissions.organizationsmodule (26+): CRUD, count, members, membership type, invitations, identity provider links, andorganizations.groupswith members and role mappings. Endpoints added after 26.0 are flagged in the docs.clients:- Secrets (including rotated), registration access token, service account user, certificates, installation.
- Default/optional client scopes; evaluate scopes (example access/id tokens, userinfo, SAML response, protocol mappers, scope mappings).
- Sessions and offline sessions, cluster nodes, push revocation, fine-grained permissions.
scopeMappings,protocolMappersandauthorization(resource server, resources, scopes, policies, permissions, evaluation).
users.roleMappingsandgroups.roleMappings: realm and client role mappings, including available and composite roles.- Shared building blocks exported for custom owners:
RoleMappings,ScopeMappings,ProtocolMappers. realms: events and admin events (+ config), keys, localization, default groups, client policies/profiles, client types, partial import/export, logout all, delete session, push revocation, SMTP test, client description converter, users management permissions.users: credentials, action/verify/reset e-mails, sessions, consents, federated identities, impersonation, logout, profile metadata, unmanaged attributes.attackDetection,clientRegistrationandworkflows(26.4+ preview) modules.clients.rolesandroles.byId: client roles, composites, users, groups and permissions. Also role composites on realm roles.groups: children, group by path, fine-grained permissions.authentication: providers, authenticator configs, execution configs and priority, andauthentication.requiredActions.- Client certificates (generate, keystore download as
Buffer, multipart upload), identity provider certificate upload, component sub-types, legacyclientScopes.templates, generic authorization/policyand/permission. - Admin API coverage grew from about 14% to 100% of the 415 operations in the 26.8.1 OpenAPI spec.
- Exports:
KeycloakSchemas(all generated schemas),KEYCLOAK_SPEC_VERSION,USER_STORAGE_PROVIDER_TYPE,LDAP_STORAGE_MAPPER_TYPE. - Unit tests (nock) and integration tests (Testcontainers) against Keycloak 24.0.5, 25.0.6 and 26.8.1, run in GitHub Actions.
npm: https://www.npmjs.com/package/keycloak-api-ts/v/2.0.0
Full changelog: v1.0.0...v2.0.0