keycloak-api-manager 6.0.2 → 6.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,10 +15,11 @@ exports.setKcAdminClient = function(kcAdminClient) {
15
15
 
16
16
  /**
17
17
  * ***************************** - getBruteForceStatus - *******************************
18
- * Get brute force detection status for all users in a realm
18
+ * Get brute force detection status in the current realm context.
19
19
  *
20
20
  * @parameters:
21
- * - realm: (string, required) - The realm name
21
+ * - filter: (object, optional) request filter object.
22
+ * - realm: (string, optional) Realm override for this call.
22
23
  * @returns: Array of user brute force status objects
23
24
  */
24
25
  exports.getBruteForceStatus = function(filter) {
@@ -27,11 +28,12 @@ exports.getBruteForceStatus = function(filter) {
27
28
 
28
29
  /**
29
30
  * ***************************** - getUserBruteForceStatus - *******************************
30
- * Get brute force detection status for a specific user
31
+ * Get brute force detection status for one user.
31
32
  *
32
33
  * @parameters:
33
- * - realm: (string, required) - The realm name
34
- * - id: (string, required) - The user ID
34
+ * - filter: (object, required) request filter object.
35
+ * - id: (string, required) User ID.
36
+ * - realm: (string, optional) Realm override for this call.
35
37
  * @returns: User brute force status object
36
38
  */
37
39
  exports.getUserBruteForceStatus = function(filter) {
@@ -43,8 +45,9 @@ exports.getUserBruteForceStatus = function(filter) {
43
45
  * Clear all login failures for a specific user
44
46
  *
45
47
  * @parameters:
46
- * - realm: (string, required) - The realm name
47
- * - id: (string, required) - The user ID
48
+ * - filter: (object, required) request filter object.
49
+ * - id: (string, required) User ID.
50
+ * - realm: (string, optional) Realm override for this call.
48
51
  * @returns: Promise
49
52
  */
50
53
  exports.clearUserLoginFailures = function(filter) {
@@ -56,7 +59,8 @@ exports.clearUserLoginFailures = function(filter) {
56
59
  * Clear all login failures for all users in a realm
57
60
  *
58
61
  * @parameters:
59
- * - realm: (string, required) - The realm name
62
+ * - filter: (object, optional) request filter object.
63
+ * - realm: (string, optional) Realm override for this call.
60
64
  * @returns: Promise
61
65
  */
62
66
  exports.clearAllLoginFailures = function(filter) {
@@ -389,7 +389,7 @@ exports.listScopeMappings=function(filter){
389
389
  * @parameters:
390
390
  * - filter: parameter provided as a JSON object that accepts the following filter:
391
391
  * - id: [required] The ID of the client scope to list available scope mapping.
392
- * - client: [required] The client ID (client UUID or client identifier) from which to list available roles
392
+ * - clientUniqueId: [required] The client UUID from which to list available roles.
393
393
  * - realm: [optional] The realm where the client scope is defined
394
394
  */
395
395
  exports.listAvailableClientScopeMappings=function(filter){
@@ -405,9 +405,9 @@ exports.listAvailableClientScopeMappings=function(filter){
405
405
  * @parameters:
406
406
  * - filter: parameter provided as a JSON object that accepts the following filter:
407
407
  * - id: [required] ID of the client scope.
408
- * - client: [required] The client ID (client UUID or client identifier) whose roles are being mapped.
408
+ * - clientUniqueId: [required] The client UUID whose roles are being mapped.
409
409
  * - realm : [optional] The realm where the client scope is defined.
410
- * - RoleRepresentation: An array of role definitions to add. Each RoleRepresentation typically includes(or at least their id and/or name):
410
+ * - roleRepresentation: An array of role definitions to add. Each RoleRepresentation typically includes(or at least their id and/or name):
411
411
  * - id : [optional] The role ID.
412
412
  * - name : [optional] The role name.
413
413
  * - description: [optional] A description of the role.
@@ -428,7 +428,7 @@ exports.addClientScopeMappings=function(filter,roleRepresentation){
428
428
  * @parameters:
429
429
  * - filter: parameter provided as a JSON object that accepts the following filter:
430
430
  * - id: [required] ID of the client scope.
431
- * - client: [required] The client ID (client UUID or client identifier) from which the roles are being removed.
431
+ * - clientUniqueId: [required] The client UUID from which the roles are being removed.
432
432
  * - realm : [optional] The realm where the client scope is defined.
433
433
  * - roleRepresentation: An array of role objects (or at least their id and/or name) to be removed from the client scope.
434
434
  * - id : [optional] The role ID
@@ -451,7 +451,7 @@ exports.delClientScopeMappings=function(filter,roleRepresentation){
451
451
  * @parameters:
452
452
  * - filter: parameter provided as a JSON object that accepts the following filter:
453
453
  * - id: [required] The ID of the client scope
454
- * - client: [required]: The client ID (client UUID or client identifier) whose mapped roles you want to list
454
+ * - clientUniqueId: [required] The client UUID whose mapped roles you want to list.
455
455
  * - realm: [optional] The realm where the client scope is defined
456
456
  */
457
457
  exports.listClientScopeMappings=function(filter){
@@ -467,7 +467,7 @@ exports.listClientScopeMappings=function(filter){
467
467
  * @parameters:
468
468
  * - filter: parameter provided as a JSON object that accepts the following filter:
469
469
  * - id: [required] The ID of the client scope.
470
- * - client: [required]: The client ID (client UUID or client identifier) whose mapped roles you want to list.
470
+ * - clientUniqueId: [required] The client UUID whose mapped roles you want to list.
471
471
  * - realm: [optional] The realm where the client scope is defined.
472
472
  */
473
473
  exports.listCompositeClientScopeMappings=function(filter){
@@ -522,15 +522,15 @@ exports.addRealmScopeMappings=function(filter,roleRepresentation){
522
522
  * - filter: parameter provided as a JSON object that accepts the following filter:
523
523
  * - id: [required] The ID of the client scope.
524
524
  * - realm: [optional] The realm where the client scope is defined.
525
- * - RoleRepresentation: Each role should include at least its id and/or name
525
+ * - roleRepresentation: Each role should include at least its id and/or name
526
526
  * - id: [required] The role ID.
527
527
  * - name: [required] The role name.
528
528
  * - description: [optional] Description of the role.
529
529
  * - clientRole: [optional] Should be false for realm roles.
530
530
  * - containerId: [optional] The ID of the realm containing the role.
531
531
  */
532
- exports.delRealmScopeMappings=function(filter,RoleRepresentation){
533
- return (kcAdminClientHandler.clientScopes.delRealmScopeMappings(filter,RoleRepresentation));
532
+ exports.delRealmScopeMappings=function(filter,roleRepresentation){
533
+ return (kcAdminClientHandler.clientScopes.delRealmScopeMappings(filter,roleRepresentation));
534
534
  }
535
535
 
536
536
 
@@ -14,10 +14,11 @@ exports.setKcAdminClient=function(kcAdminClient){
14
14
 
15
15
  /**
16
16
  * ***************************** - CREATE - *******************************
17
- * Create a new group in the current realme
17
+ * Create a new group in the current realm.
18
18
  * @parameters:
19
19
  * - groupRepresentation:An object representing the new state of the group. You can update properties such as:
20
- * - name: [optional] New name of the group
20
+ * - name: [required] Group name.
21
+ * - parentId: [optional] Parent group id. If provided, the group is created as a child group.
21
22
  * - attributes: [optional] Custom attributes up field
22
23
  * - path: [optional] full path of the group
23
24
  * - subGroups: [optional] List of child groups (can also be updated separately)
@@ -55,7 +55,7 @@ exports.createComposite=function(filters,roles){
55
55
  * - realm (string, optional: if set globally in the client): The realm from which to retrieve roles.
56
56
  * - first (number, optional): Index of the first result to return (used for pagination).
57
57
  * - max (number, optional): Maximum number of results to return.
58
- * - name (string, optional): Search string to filter roles by name.
58
+ * - search (string, optional): Search string to filter roles by name.
59
59
  */
60
60
  exports.find=function(filters){
61
61
  return (kcAdminClientHandler.roles.find(filters));
@@ -81,7 +81,7 @@ exports.findOneByName=function(filters){
81
81
  * Get a role by its Id
82
82
  * @parameters:
83
83
  * - filters: parameter provided as a JSON object that accepts the following parameters:
84
- * - Id (string, required) — The Id of the role to retrieve.
84
+ * - id (string, required) — The Id of the role to retrieve.
85
85
  * - realm (string, optional if set globally) — The realm where the role is defined.
86
86
  */
87
87
  exports.findOneById=function(filters){
@@ -94,7 +94,7 @@ exports.findOneById=function(filters){
94
94
  * Update a role by its name
95
95
  * @parameters:
96
96
  * - filters: parameter provided as a JSON object that accepts the following parameters:
97
- * - name (string, required) — The exact name of the role to retrieve.
97
+ * - name (string, required) — The exact name of the role to update.
98
98
  * - realm (string, optional if set globally) — The realm where the role is defined.
99
99
  * - role_dictionary: A JSON object representing a role dictionary as defined in Keycloak
100
100
  */
@@ -109,7 +109,7 @@ exports.updateByName=function(filters,role_dictionary){
109
109
  * Update a role by its Id
110
110
  * @parameters:
111
111
  * - filters: parameter provided as a JSON object that accepts the following parameters:
112
- * - name (string, required) — The exact name of the role to retrieve.
112
+ * - id (string, required) — The Id of the role to update.
113
113
  * - realm (string, optional if set globally) — The realm where the role is defined.
114
114
  * - role_dictionary: A JSON object representing a role dictionary as defined in Keycloak
115
115
  */
@@ -134,8 +134,8 @@ exports.delByName=function(filters){
134
134
  * ***************************** - findUsersWithRole - *******************************
135
135
  * Find all users associated with a specific role
136
136
  * - filters: parameter provided as a JSON object that accepts the following parameters:
137
- * - name: (string, optional) — The exact name of the role to retrieve.
138
- * - id: (string, optional) — The Id of the role to retrieve.
137
+ * - name: (string, required) — The exact name of the role.
138
+ * - id: (string, optional) — Optional role id depending on endpoint support.
139
139
  * - realm: (string, optional if set globally) — The realm where the role is defined.
140
140
  */
141
141
  exports.findUsersWithRole=function(filters){
@@ -148,8 +148,8 @@ exports.findUsersWithRole=function(filters){
148
148
  * ***************************** - getCompositeRoles - *******************************
149
149
  * Find all composite roles associated with a specific role.
150
150
  * - filters: parameter provided as a JSON object that accepts the following parameters:
151
- * - name: (string, optional) — The exact name of the role to retrieve.
152
- * - id: (string, optional) — The Id of the role to retrieve.
151
+ * - id: (string, required) — The Id of the role to retrieve.
152
+ * - realm: (string, optional) — Realm override.
153
153
  */
154
154
  exports.getCompositeRoles=function(filters){
155
155
  return (kcAdminClientHandler.roles.getCompositeRoles(filters));
@@ -161,13 +161,14 @@ exports.getCompositeRoles=function(filters){
161
161
  * associated with a given composite role.
162
162
  * When a role is defined as composite, it can include other roles either from the same
163
163
  * realm or from different clients. This specific method returns only the realm-level roles
164
- * that have been added to the composite role. It requires the roleId of the target role as a
164
+ * that have been added to the composite role. It requires the id of the target role as a
165
165
  * parameter and returns an array of RoleRepresentation objects. If the role is not composite
166
166
  * or has no associated realm roles, the result will be an empty array. This method is useful
167
167
  * for understanding and managing hierarchical role structures within a realm in Keycloak.
168
168
  * @parameters:
169
169
  * - filters: parameter provided as a JSON object that accepts the following parameters:
170
- * - roleId: (string, required) — The Id of the role to retrieve
170
+ * - id: (string, required) — The Id of the role to retrieve.
171
+ * - realm: (string, optional) — Realm override.
171
172
  */
172
173
  exports.getCompositeRolesForRealm=function(filters){
173
174
  return (kcAdminClientHandler.roles.getCompositeRolesForRealm(filters));
@@ -180,14 +181,15 @@ exports.getCompositeRolesForRealm=function(filters){
180
181
  * associated with a given composite role.
181
182
  * Composite roles in Keycloak can include roles from different clients,
182
183
  * and this method specifically returns the roles belonging to a specified client that
183
- * are part of the composite role. It requires the roleId of the composite role
184
+ * are part of the composite role. It requires the id of the composite role
184
185
  * and the clientId of the client whose roles you want to retrieve. The function returns an array of
185
186
  * RoleRepresentation objects representing the client roles included in the composite.
186
187
  * This helps manage and inspect client-specific role hierarchies within the composite role structure in Keycloak.
187
188
  * @parameters:
188
189
  * - filters: parameter provided as a JSON object that accepts the following parameters:
189
- * - roleId: (string, required) — The Id of the role to retrieve
190
+ * - id: (string, required) — The Id of the role to retrieve.
190
191
  * - clientId: (string, required) — The Id of the client to search for composite roles
192
+ * - realm: (string, optional) — Realm override.
191
193
  *
192
194
  */
193
195
  exports.getCompositeRolesForClient=function(filters){
package/README.md CHANGED
@@ -25,11 +25,13 @@ It provides a stable, function-oriented interface for managing Keycloak resource
25
25
  npm install keycloak-api-manager
26
26
  ```
27
27
 
28
- > **⚠️ DEPRECATION NOTICE (v6.0.0):** The OIDC authentication methods (`login()`, `loginPKCE()`, `generateAuthorizationUrl()`, `auth()`) have been **deprecated** and moved to [`keycloak-express-middleware`](https://github.com/smartenv-crs4/keycloak-express-middleware).
29
- >
30
- > **This package is now exclusively for Keycloak admin resource management.** For user authentication flows, use `keycloak-express-middleware` instead.
31
- >
32
- > See [OIDC_MIGRATION_PLAN.md](OIDC_MIGRATION_PLAN.md) for migration details.
28
+ ## OIDC Deprecation Notice
29
+
30
+ DEPRECATION NOTICE (v6.0.0): The OIDC authentication methods (login(), loginPKCE(), generateAuthorizationUrl(), auth()) have been deprecated and moved to keycloak-express-middleware.
31
+
32
+ This package is now exclusively for Keycloak admin resource management. For user authentication flows, use keycloak-express-middleware instead.
33
+
34
+ See [OIDC_MIGRATION_PLAN.md](OIDC_MIGRATION_PLAN.md) for migration details.
33
35
 
34
36
  ## Quick Start
35
37
 
@@ -46,6 +48,8 @@ await KeycloakManager.configure({
46
48
  tokenLifeSpan: 60
47
49
  });
48
50
 
51
+ // Alternative after configure(): update runtime context (for example realm)
52
+ // without re-authenticating or calling configure() again.
49
53
  KeycloakManager.setConfig({ realmName: 'my-realm' });
50
54
 
51
55
  const users = await KeycloakManager.users.find({ max: 20 });
@@ -54,19 +58,41 @@ console.log(users.length);
54
58
  KeycloakManager.stop();
55
59
  ```
56
60
 
57
- > **💡 Tip:** For user authentication (including Authorization Code + PKCE), use [`keycloak-express-middleware`](https://github.com/smartenv-crs4/keycloak-express-middleware). OIDC methods in this package are deprecated and kept only for backward compatibility.
58
-
59
61
  ## Keycloak Feature Flags
60
62
 
61
- For full API coverage in this package (especially Organizations, Client Policies, User Profile, Group permissions), run Keycloak with:
63
+ Some APIs exposed by this package depend on Keycloak server features that are disabled by default. Enable these flags when you want full endpoint coverage (local dev, CI, or production environments that use these modules):
62
64
 
63
65
  ```bash
64
66
  --features=admin-fine-grained-authz:v1,organization,client-policies
65
67
  ```
66
68
 
67
- ### Why `admin-fine-grained-authz:v1`
69
+ What each flag is for:
70
+
71
+ - `admin-fine-grained-authz:v1`: enables management-permissions endpoints used by group/user fine-grained permission flows.
72
+ - `organization`: enables Organizations APIs.
73
+ - `client-policies`: enables Client Policies and Client Profiles APIs.
74
+
75
+ When you can skip them:
76
+
77
+ - If you only use core admin operations (for example realms/users/clients CRUD), the package still works without these flags.
78
+ - If you use `organizations`, `clientPolicies`, or management-permissions methods, these flags are required.
79
+
80
+ ### Why `admin-fine-grained-authz:v1` in Keycloak 26.x
68
81
 
69
- In Keycloak 26.x, management-permissions APIs used by group/user fine-grained tests are compatible with `v1`.
82
+ In Keycloak 26.x, the management-permissions APIs used by this package are compatible with the `v1` variant, so `admin-fine-grained-authz:v1` is the recommended setting.
83
+
84
+ ### Example (Docker)
85
+
86
+ ```bash
87
+ docker run -d --name keycloak \
88
+ -p 8080:8080 \
89
+ -e KEYCLOAK_ADMIN=admin \
90
+ -e KEYCLOAK_ADMIN_PASSWORD=admin \
91
+ -e KC_FEATURES=admin-fine-grained-authz:v1,organization,client-policies \
92
+ quay.io/keycloak/keycloak:latest start-dev
93
+ ```
94
+
95
+ See [Keycloak Setup and Feature Flags](docs/keycloak-setup.md) for full setup details.
70
96
 
71
97
  ## Public API Entry Points
72
98
 
@@ -74,12 +100,6 @@ In Keycloak 26.x, management-permissions APIs used by group/user fine-grained te
74
100
  - `setConfig(overrides)`
75
101
  - `getToken()`
76
102
  - `stop()`
77
- - ~~`login(credentials)`~~ **DEPRECATED** - moved to keycloak-express-middleware
78
- - ~~`generateAuthorizationUrl(options)`~~ **DEPRECATED** - moved to keycloak-express-middleware
79
- - ~~`loginPKCE(credentials)`~~ **DEPRECATED** - moved to keycloak-express-middleware
80
- - ~~`auth(credentials)`~~ **DEPRECATED** - moved to keycloak-express-middleware
81
-
82
- **Note:** OIDC authentication methods have been deprecated in v6.0.0. Use [`keycloak-express-middleware`](https://github.com/smartenv-crs4/keycloak-express-middleware) for user authentication flows.
83
103
 
84
104
  Configured handler namespaces:
85
105
 
@@ -104,7 +124,7 @@ All documentation is centralized under `docs/`.
104
124
 
105
125
  ### Guides
106
126
 
107
- - [OIDC Migration Plan](OIDC_MIGRATION_PLAN.md) - Deprecation status and migration notes to keycloak-express-middleware
127
+ - [OIDC Migration Plan](OIDC_MIGRATION_PLAN.md) - Migration notes for legacy OIDC helpers
108
128
 
109
129
  ### API Reference
110
130
 
@@ -129,13 +149,13 @@ All documentation is centralized under `docs/`.
129
149
 
130
150
  - [Architecture and Runtime](docs/architecture.md)
131
151
  - [Keycloak Setup and Feature Flags](docs/keycloak-setup.md)
132
- - [Testing Guide](docs/testing.md)
133
- - [Test Configuration](docs/test-configuration.md)
152
+ - [Testing Guide](docs/testing.md) — setup, configuration, commands, and test architecture
134
153
  - [Deployment (Local/Remote, HTTP/HTTPS)](docs/deployment.md)
135
154
 
136
155
  ## Testing
137
156
 
138
157
  ```bash
158
+ npm run setup-keycloak
139
159
  npm test
140
160
  ```
141
161
 
@@ -145,6 +165,8 @@ Or test workspace only:
145
165
  npm --prefix test test
146
166
  ```
147
167
 
168
+ `npm run setup-keycloak` is an interactive helper that can start Keycloak via Docker Compose (local/remote, HTTP/HTTPS) and update the test `baseUrl` in config.
169
+
148
170
  The suite runs against a real Keycloak instance and provisions a shared test realm during setup.
149
171
 
150
172
  ## Repository Structure
@@ -163,14 +185,13 @@ docs/ # Centralized documentation
163
185
 
164
186
  ## Versioning and Compatibility
165
187
 
166
- - Package version: `6.0.1`
188
+ - Package version: `6.0.3`
167
189
  - Keycloak Admin client dependency: `@keycloak/keycloak-admin-client`
168
190
  - Main compatibility target: Keycloak 25/26
169
191
 
170
192
  ### Breaking Changes in v6.0.0
171
193
 
172
- OIDC authentication methods (`login()`, `loginPKCE()`, `generateAuthorizationUrl()`, `auth()`) are now deprecated.
173
- These methods will be removed in v7.0.0. Migrate to `keycloak-express-middleware` for user authentication.
194
+ See OIDC Deprecation Notice.
174
195
 
175
196
  ## License
176
197
 
@@ -2,41 +2,107 @@
2
2
 
3
3
  Brute-force and login-failure management endpoints.
4
4
 
5
- **Namespace:** `KeycloakManager.attackDetection`
5
+ Namespace: KeycloakManager.attackDetection
6
+
7
+ ## Overview
8
+
9
+ This handler wraps Keycloak Attack Detection endpoints used to:
10
+
11
+ - Inspect lock/failure status.
12
+ - Clear failures for one user.
13
+ - Clear failures for the entire realm.
14
+
15
+ These operations are usually used by support/admin tooling and automated account recovery flows.
6
16
 
7
17
  ## Methods
8
18
 
9
19
  ### getBruteForceStatus(filter)
10
- Get brute-force status for all users or query context depending on endpoint wrapper.
11
20
 
12
- - **Optional**: realm context fields
13
- - **Returns**: Promise<object>
21
+ Read global brute-force status context from the configured realm.
22
+
23
+ Parameters:
24
+
25
+ - filter (object, optional):
26
+ - realm (string, optional): override target realm for this call.
27
+
28
+ Returns:
29
+
30
+ - Promise<object>: realm brute-force status payload returned by Keycloak.
31
+
32
+ Example:
33
+
34
+ ```js
35
+ const status = await KeycloakManager.attackDetection.getBruteForceStatus();
36
+ console.log(status);
37
+ ```
14
38
 
15
39
  ### getUserBruteForceStatus(filter)
16
- Get brute-force status for one user.
17
40
 
18
- - **Required**: `filter.userId` (or `filter.id` based on wrapper usage)
19
- - **Returns**: Promise<object>
41
+ Read brute-force status for one user.
42
+
43
+ Parameters:
44
+
45
+ - filter (object, required):
46
+ - id (string, required): user id.
47
+ - realm (string, optional): override target realm.
48
+
49
+ Returns:
50
+
51
+ - Promise<object>: user brute-force state (for example temporary lock status, failures metadata).
52
+
53
+ Example:
54
+
55
+ ```js
56
+ const userStatus = await KeycloakManager.attackDetection.getUserBruteForceStatus({
57
+ id: userId,
58
+ });
59
+ ```
20
60
 
21
61
  ### clearUserLoginFailures(filter)
22
- Clear failed login attempts for one user.
23
62
 
24
- - **Required**: `filter.userId` (or equivalent id field)
25
- - **Returns**: Promise<void>
63
+ Clear failed-login counters for one user.
64
+
65
+ Parameters:
66
+
67
+ - filter (object, required):
68
+ - id (string, required): user id.
69
+ - realm (string, optional): override target realm.
70
+
71
+ Returns:
72
+
73
+ - Promise<void>
74
+
75
+ Example:
76
+
77
+ ```js
78
+ await KeycloakManager.attackDetection.clearUserLoginFailures({ id: userId });
79
+ ```
26
80
 
27
81
  ### clearAllLoginFailures(filter)
28
- Clear failed login attempts for all users in realm.
29
82
 
30
- - **Optional**: realm context fields
31
- - **Returns**: Promise<void>
83
+ Clear failed-login counters for all users in the realm.
84
+
85
+ Parameters:
86
+
87
+ - filter (object, optional):
88
+ - realm (string, optional): override target realm.
89
+
90
+ Returns:
32
91
 
33
- ## Example
92
+ - Promise<void>
93
+
94
+ Example:
34
95
 
35
96
  ```js
36
- const status = await KeycloakManager.attackDetection.getUserBruteForceStatus({ userId });
37
- await KeycloakManager.attackDetection.clearUserLoginFailures({ userId });
97
+ await KeycloakManager.attackDetection.clearAllLoginFailures();
38
98
  ```
39
99
 
100
+ ## Error Notes
101
+
102
+ - Some Keycloak distributions/versions may not expose attack-detection endpoints in the same way.
103
+ - If endpoint support is missing, Keycloak may return 404.
104
+
40
105
  ## See Also
106
+
41
107
  - [API Reference](../api-reference.md)
42
108
  - [Users](users.md)