keycloak-api-manager 1.0.0 → 2.0.1
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.
- package/.idea/workspace.xml +19 -2
- package/Handlers/authenticationManagementHandler.js +602 -0
- package/Handlers/clientScopesHandler.js +567 -0
- package/Handlers/clientsHandler.js +1411 -0
- package/Handlers/componentsHandler.js +130 -0
- package/Handlers/groupsHandler.js +293 -0
- package/Handlers/identityProvidersHandler.js +255 -0
- package/Handlers/realmsHandler.js +575 -0
- package/Handlers/rolesHandler.js +196 -0
- package/Handlers/usersHandler.js +559 -0
- package/README.md +742 -1102
- package/index.js +37 -1181
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ API calls, and error management internally. Designed for developers who want ful
|
|
|
10
10
|
without manually invoking REST endpoints, keycloak-api-manager enables fast, reliable,
|
|
11
11
|
and type-safe operations across multiple realms and environments.
|
|
12
12
|
it is a wrapper based on '@keycloak/keycloak-admin-client'
|
|
13
|
+
|
|
14
|
+
|
|
13
15
|
---
|
|
14
16
|
## 📦 Features
|
|
15
17
|
|
|
@@ -66,10 +68,8 @@ yarn add keycloak-api-manager
|
|
|
66
68
|
---
|
|
67
69
|
|
|
68
70
|
## 🛠️ Get Keycloak Configuration
|
|
69
|
-
|
|
70
71
|
Copy or Download from keycloak admin page your client configuration `keycloak.json` by visiting
|
|
71
72
|
the Keycloak Admin Console → clients (left sidebar) → choose your client → Installation → Format Option → Keycloak OIDC JSON → Download
|
|
72
|
-
|
|
73
73
|
```json
|
|
74
74
|
{
|
|
75
75
|
"realm": "your-realm",
|
|
@@ -82,211 +82,73 @@ the Keycloak Admin Console → clients (left sidebar) → choose your client →
|
|
|
82
82
|
"confidential-port": 0
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
|
-
|
|
86
85
|
---
|
|
87
86
|
|
|
88
87
|
## 📄 Usage Example
|
|
89
88
|
|
|
90
89
|
```js
|
|
90
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
91
91
|
const express = require('express');
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const app = express();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// Configure and Initialize Keycloak adapter
|
|
98
|
-
await keycloackAdapter.configure(app,{
|
|
99
|
-
"realm": "Realm-Project",
|
|
100
|
-
"auth-server-url": "https://YourKeycloakUrl:30040/",
|
|
101
|
-
"ssl-required": "external",
|
|
102
|
-
"resource": "keycloackclientName",
|
|
103
|
-
"credentials": {
|
|
104
|
-
"secret": "aaaaaaaaaa"
|
|
105
|
-
},
|
|
106
|
-
"confidential-port": 0
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
session:{
|
|
110
|
-
secret: 'mySecretForSession',
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
92
|
+
// Import the Keycloak API Manager
|
|
114
93
|
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
94
|
+
// Configure and Initialize Keycloak manager api
|
|
95
|
+
// Initialize the manager with Keycloak credentials
|
|
96
|
+
await KeycloakManager.configure({
|
|
97
|
+
baseUrl: 'http://localhost:8080', // Keycloak base URL
|
|
98
|
+
realm: 'master', // Realm where the admin user belongs
|
|
99
|
+
clientId: 'admin-cli', // Keycloak admin client
|
|
100
|
+
username: 'admin', // Admin username
|
|
101
|
+
password: 'admin', // Admin password
|
|
102
|
+
grantType: 'password', // Type of authentication
|
|
118
103
|
});
|
|
119
104
|
|
|
120
|
-
/* Protected routes (any authenticated user) */
|
|
121
105
|
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// Example of login with keycloackAdapter.loginMiddleware middleware
|
|
131
|
-
// After login redirect to "/home"
|
|
132
|
-
app.get('/loginMiddleware', keycloackAdapter.loginMiddleware("/home") ,(req, res) => {
|
|
133
|
-
// Response handled by middleware, this section will never be reached.
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Example of logout with keycloackAdapter.logout function
|
|
137
|
-
// After login redirect to "http://localhost:3001/home"
|
|
138
|
-
app.get('/logout', (req, res) => {
|
|
139
|
-
console.log("Your Custom Code");
|
|
140
|
-
keycloackAdapter.logout(req,res,"http://localhost:3001/home");
|
|
106
|
+
// Create a new user in the target realm
|
|
107
|
+
const newUser = await KeycloakManager.users.create({
|
|
108
|
+
username: 'john.doe',
|
|
109
|
+
email: 'john.doe@example.com',
|
|
110
|
+
firstName: 'John',
|
|
111
|
+
lastName: 'Doe',
|
|
112
|
+
enabled: true,
|
|
141
113
|
});
|
|
142
114
|
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
app.get('/logoutMiddle', keycloackAdapter.logoutMiddleware("http://redirctUrl"), (req, res) => {
|
|
146
|
-
// Response handled by middleware, this section will never be reached.
|
|
147
|
-
});
|
|
115
|
+
// List first page of users
|
|
116
|
+
const users = await KeycloakManager.users.find({ first: 0, max: 10 });
|
|
148
117
|
|
|
118
|
+
// find users by attributes
|
|
119
|
+
users = await KeycloakManager.users.find({ q: "phone:123" });
|
|
149
120
|
|
|
150
|
-
//
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
console.log("Your Custom Code");
|
|
154
|
-
console.log( req.session);
|
|
155
|
-
res.redirect('/auth');
|
|
121
|
+
// Override client configuration for all further requests:
|
|
122
|
+
setConfig({
|
|
123
|
+
realmName: 'another-realm',
|
|
156
124
|
});
|
|
157
125
|
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
// Access is allowed only for authenticated admin users
|
|
161
|
-
app.get('/privateStaticClientRole', keycloackAdapter.protectMiddleware("admin"), (req, res) => {
|
|
162
|
-
// "Your Custom Code"
|
|
163
|
-
res.send("Is its admin.");
|
|
164
|
-
});
|
|
126
|
+
// This operation will now be performed in 'another-realm' if the user has access.
|
|
127
|
+
const groups = await KeycloakManager.groups.find();
|
|
165
128
|
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
129
|
+
// Set a `realm` property to override the realm for only a single operation.
|
|
130
|
+
// For example, creating a user in another realm:
|
|
131
|
+
await KeycloakManager.users.create({
|
|
132
|
+
realm: 'a-third-realm',
|
|
133
|
+
username: 'username',
|
|
134
|
+
email: 'user@third-realm.com',
|
|
172
135
|
});
|
|
173
136
|
|
|
174
|
-
// Example of protection with keycloackAdapter.protectMiddleware middleware
|
|
175
|
-
// whith a static other client role validation string
|
|
176
|
-
// Access is allowed only for authenticated otherClient admin users
|
|
177
|
-
app.get('/privateStaticRealmRole', keycloackAdapter.protectMiddleware("otherClient:admin"), (req, res) => {
|
|
178
|
-
// "Your Custom Code"
|
|
179
|
-
res.send("Is its admin otherClient:admin.");
|
|
180
|
-
});
|
|
181
137
|
|
|
182
|
-
//
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return token.hasRole('admin');
|
|
187
|
-
}
|
|
188
|
-
app.get('/isAdmin', keycloackAdapter.protectMiddleware(tmpFunction), (req, res) => {
|
|
189
|
-
// "Your Custom Code"
|
|
190
|
-
res.send("Is its admin tmpFunction.");
|
|
138
|
+
// create a new realm, If id omitted, Keycloak uses the realm name as the ID.
|
|
139
|
+
const realm = await KeycloakManager.realms.create({
|
|
140
|
+
id: "123456",
|
|
141
|
+
realm: "new-realm",
|
|
191
142
|
});
|
|
192
143
|
|
|
193
144
|
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
let tmpFunctionString=function (req,res) {
|
|
198
|
-
let id=req.params.id
|
|
199
|
-
// Control String by url param Id
|
|
200
|
-
return (`${id}`);
|
|
201
|
-
}
|
|
202
|
-
app.get('/:id/isAdmin', keycloackAdapter.customProtectMiddleware(tmpFunctionString), (req, res) => {
|
|
203
|
-
// "Your Custom Code"
|
|
204
|
-
res.send("Is its admin tmpFunctionString.");
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
// Example of protection with keycloackAdapter.encodeTokenRole middleware
|
|
209
|
-
// Encode the token and add it to req.encodedTokenRole
|
|
210
|
-
// Use req.encodedTokenRole.hasRole("role") to check whether the token has that role or not
|
|
211
|
-
app.get('/encodeToken', keycloackAdapter.encodeTokenRole(), (req, res) => {
|
|
212
|
-
if(req.encodedTokenRole.hasRole('realm:admin'))
|
|
213
|
-
res.send("Is its a realm admin");
|
|
214
|
-
else
|
|
215
|
-
res.send("Is its'n a realm admin");
|
|
216
|
-
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// This section provides examples of how to protect resources based on permissions
|
|
220
|
-
// rather than roles.
|
|
221
|
-
|
|
222
|
-
// Example of protection with keycloackAdapter.enforcerMiddleware middleware
|
|
223
|
-
// whith a static control string
|
|
224
|
-
// Access is allowed only for users with 'ui-admin-resource' permission defined
|
|
225
|
-
// in keycloak
|
|
226
|
-
app.get('/adminResource', keycloackAdapter.enforcerMiddleware('ui-admin-resource'), (req, res) => {
|
|
227
|
-
// If this section is reached, the user has the required privileges;
|
|
228
|
-
// otherwise, the middleware responds with a 403 Access Denied.
|
|
229
|
-
res.send('You are an authorized ui-admin-resource User');
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
// Example of protection with keycloackAdapter.enforcerMiddleware middleware
|
|
233
|
-
// whith a control function tmpFunctionEnforceValidation
|
|
234
|
-
// Access is allowed only for users with 'ui-admin-resource' or
|
|
235
|
-
// ui-viewer-resource permission defined in keycloak
|
|
236
|
-
let tmpFunctionEnforceValidation=function (token,req,callback) {
|
|
237
|
-
// Check permission using token.hasPermission, which performs the verification
|
|
238
|
-
// and responds with a callback that returns true if the permission is valid,
|
|
239
|
-
// and false otherwise.
|
|
240
|
-
if(token.hasPermission('ui-admin-resource',function(permission){
|
|
241
|
-
if(permission) callback(true);
|
|
242
|
-
else if(token.hasPermission('ui-viewer-resource',function(permission){
|
|
243
|
-
if(permission) callback(true);
|
|
244
|
-
else callback(false);
|
|
245
|
-
}));
|
|
246
|
-
}));
|
|
247
|
-
}
|
|
248
|
-
app.get('/adminOrViewerResorce', keycloackAdapter.enforcerMiddleware(tmpFunctionEnforceValidation), (req, res) => {
|
|
249
|
-
// If this section is reached, the user has the required privileges
|
|
250
|
-
// driven by tmpFunctionEnforceValidation; otherwise, the middleware responds
|
|
251
|
-
// with a 403 Access Denied.
|
|
252
|
-
res.send('You are an authorized User');
|
|
145
|
+
// Get realm Info
|
|
146
|
+
realm = await KeycloakManager.realms.findOne({
|
|
147
|
+
realm: "new-realm"
|
|
253
148
|
});
|
|
254
149
|
|
|
150
|
+
console.log("realm info:", realm);
|
|
255
151
|
|
|
256
|
-
// Example of protection with keycloackAdapter.customEnforcerMiddleware middleware
|
|
257
|
-
// whith a control function tmpFunctionEnforce that define the control string
|
|
258
|
-
// Access is allowed only for users with a url params ':permission' permission defined
|
|
259
|
-
// in keycloak
|
|
260
|
-
let tmpFunctionEnforce=function (req,res) {
|
|
261
|
-
// Permission that depends on a URL parameter.
|
|
262
|
-
return(req.params.permission);
|
|
263
|
-
}
|
|
264
|
-
app.get('/urlParameterPermission/:permission', keycloackAdapter.customEnforcerMiddleware(tmpFunctionEnforce), (req, res) => {
|
|
265
|
-
res.send(`You are an authorized User with ${req.params.permission} permission`);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// Example of protection with keycloackAdapter.encodeTokenPermission middleware
|
|
269
|
-
// Encode the token permission and add it to req.encodedTokenPremission
|
|
270
|
-
// Use req.encodedTokenPremission.hasPermission("permission") to check whether
|
|
271
|
-
// the token has that permission or not
|
|
272
|
-
app.get('/encodeTokenPermission', keycloackAdapter.encodeTokenPermission(), (req, res) => {
|
|
273
|
-
// Check permission using token.hasPermission, which performs the verification
|
|
274
|
-
// and responds with a callback that returns true if the permission is valid,
|
|
275
|
-
// and false otherwise.
|
|
276
|
-
req.encodedTokenPremission.hasPermission('ui-admin-resource', function(permission){
|
|
277
|
-
if(permission)
|
|
278
|
-
res.send('You are an authorized User by ui-admin-resource permission');
|
|
279
|
-
else res.status(403).send("access Denied");
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// Start the server
|
|
286
|
-
const PORT = process.env.PORT || 3000;
|
|
287
|
-
app.listen(PORT, () => {
|
|
288
|
-
console.log(`Server running at http://localhost:${PORT}`);
|
|
289
|
-
});
|
|
290
152
|
```
|
|
291
153
|
|
|
292
154
|
---
|
|
@@ -296,602 +158,58 @@ app.listen(PORT, () => {
|
|
|
296
158
|
In your Express application:
|
|
297
159
|
|
|
298
160
|
```js
|
|
299
|
-
|
|
161
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
300
162
|
|
|
301
|
-
// Configure and Initialize Keycloak
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
},
|
|
312
|
-
{
|
|
313
|
-
session:{
|
|
314
|
-
secret: 'mySecretForSession',
|
|
315
|
-
}
|
|
316
|
-
})
|
|
163
|
+
// Configure and Initialize Keycloak manager api
|
|
164
|
+
// Initialize the manager with Keycloak credentials
|
|
165
|
+
await KeycloakManager.configure({
|
|
166
|
+
baseUrl: 'http://localhost:8080', // Keycloak base URL
|
|
167
|
+
realm: 'master', // Realm where the admin user belongs
|
|
168
|
+
clientId: 'admin-cli', // Keycloak admin client
|
|
169
|
+
username: 'admin', // Admin username
|
|
170
|
+
password: 'admin', // Admin password
|
|
171
|
+
grantType: 'password', // Type of authentication
|
|
172
|
+
});
|
|
317
173
|
```
|
|
318
174
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
It is an async function and returns a promise
|
|
175
|
+
Configure is a configuration function for the Keycloak-api-manager.
|
|
176
|
+
It must be called at app startup, before to use the administrative
|
|
177
|
+
functions exposed by this library
|
|
323
178
|
|
|
324
179
|
Parameters:
|
|
325
|
-
-
|
|
326
|
-
- keyCloakConfig: JSON object containing the Keycloak client configuration.
|
|
327
|
-
This can be obtained from the Keycloak admin console:
|
|
328
|
-
Clients → [client name] → Installation → "Keycloak OIDC JSON" → Download
|
|
329
|
-
Example:
|
|
330
|
-
{
|
|
331
|
-
"realm": "realm-name",
|
|
332
|
-
"auth-server-url": "https://keycloak.example.com/",
|
|
333
|
-
"ssl-required": "external",
|
|
334
|
-
"resource": "client-name",
|
|
335
|
-
"credentials": { "secret": "secret-code" },
|
|
336
|
-
"confidential-port": 0
|
|
337
|
-
}
|
|
338
|
-
- keyCloakOptions: advanced configuration options for the adapter.
|
|
339
|
-
Main supported options:
|
|
340
|
-
- session: Express session configuration (as in express-session)
|
|
341
|
-
- scope: authentication scopes (e.g., 'openid profile email offline_access')
|
|
342
|
-
Note: to use offline_access, the client must have the option enabled and
|
|
343
|
-
the user must have the offline_access role.
|
|
344
|
-
- idpHint: to suggest an identity provider to Keycloak during login
|
|
345
|
-
- cookies: to enable cookie handling
|
|
346
|
-
- realmUrl: to override the realm URL
|
|
347
|
-
- adminClientCredentials: [Optional] Advanced configuration for setting up the realm-admin user or client,
|
|
180
|
+
- adminClientCredentials: [required] Advanced configuration for setting up the realm-admin user or client,
|
|
348
181
|
which will be used as the administrator to manage Keycloak via API.
|
|
349
182
|
This is required in order to use the administrative functions exposed by this library.
|
|
350
183
|
If this parameter is not provided, it will not be possible to use the administrative functions of Keycloak
|
|
351
|
-
exposed by this adapter
|
|
352
|
-
keycloakAdapter.kcAdminClient will result in a runtime error due to access on an undefined object
|
|
184
|
+
exposed by this adapter, so any attempt to call KeycloakManager.{function} will result in a runtime error due to access on an undefined object
|
|
353
185
|
Main supported options:
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
- clientSecret: [Optional] string containing the client secret of the client. Required for client_credentials or confidential clients.
|
|
367
|
-
- totp: string for Time-based One-Time Password (TOTP) for multifactor authentication (MFA), if enabled for the user.
|
|
368
|
-
- offlineToken: [Optional] boolean value. If true, requests an offline token (used for long-lived refresh tokens). Default is false.
|
|
369
|
-
- refreshToken: [Optional] string containing a valid refresh token to request a new access token when using the refresh_token grant type.
|
|
370
|
-
---
|
|
371
|
-
|
|
372
|
-
## 🔧 Available Middlewares
|
|
373
|
-
|
|
374
|
-
### `underKeycloakProtection(callback) - deprecated - `
|
|
375
|
-
@deprecated. Use the `configure` Method with `await keycloakAdapter.configure(...)`,
|
|
376
|
-
then define your resources as you normally would in Express:
|
|
377
|
-
```js
|
|
378
|
-
await keycloakAdapter.configure(config_Parameters);
|
|
379
|
-
|
|
380
|
-
// all your routes
|
|
381
|
-
|
|
382
|
-
app.get('/my-route', handler);
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
Alternatively, if you prefer to define your resources inside a container after configuration,
|
|
386
|
-
you can use the `then` syntax:
|
|
387
|
-
```js
|
|
388
|
-
keycloakAdapter.configure(configParameters).then(() => {
|
|
389
|
-
// Define all your routes here
|
|
390
|
-
app.get('/my-route', handler);
|
|
391
|
-
});
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
This Method is deprecated and will be removed in future versions.
|
|
395
|
-
|
|
396
|
-
Method to define Express routes that must be protected by Keycloak.
|
|
397
|
-
|
|
398
|
-
This method must be called **after** Keycloak has been configured with `configure()`.
|
|
399
|
-
The routes declared inside the provided callback will be protected and will have access
|
|
400
|
-
to authentication/authorization features managed by Keycloak.
|
|
401
|
-
|
|
402
|
-
📌 Public (unprotected) routes should be declared **before** calling this method.
|
|
403
|
-
|
|
404
|
-
@param {Function} callback - A function that defines all routes to be protected.
|
|
405
|
-
It must contain exclusively routes requiring authentication.
|
|
406
|
-
|
|
407
|
-
✅ Usage example:
|
|
408
|
-
```js
|
|
409
|
-
// Public route not protected by Keycloak
|
|
410
|
-
app.get('/public', (req, res) => {
|
|
411
|
-
res.send('Public content');
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
// Section of routes protected by Keycloak
|
|
415
|
-
keycloakAdapter.underKeycloakProtection(() => {
|
|
416
|
-
|
|
417
|
-
// This function is deprecated and will be removed in future versions.
|
|
418
|
-
// It is retained only for backward compatibility with older versions
|
|
419
|
-
|
|
420
|
-
// Route protected by authentication
|
|
421
|
-
app.get('/confidential', keycloakAdapter.protectMiddleware(), (req, res) => {
|
|
422
|
-
res.send('Confidential content visible only to authenticated users');
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
// Route with forced login: handled directly by middleware
|
|
426
|
-
app.get('/loginMiddleware', keycloakAdapter.loginMiddleware("/home"), (req, res) => {
|
|
427
|
-
// This response will never be sent because the middleware handles the
|
|
428
|
-
// request directly
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
### `protectMiddleware([conditions])`
|
|
434
|
-
Middleware to protect Express routes based on authentication and, optionally,
|
|
435
|
-
authorization via Keycloak roles.
|
|
436
|
-
|
|
437
|
-
Allows restricting access to a resource only to authenticated users or
|
|
438
|
-
to those possessing specific roles in the realm or in a Keycloak client.
|
|
439
|
-
|
|
440
|
-
@param {string|function} [conditions]
|
|
441
|
-
- If a string, specifies one or more required roles, using the syntax:
|
|
442
|
-
- 'role' → client role in the configured client (e.g., 'admin')
|
|
443
|
-
- 'clientid:role' → client role of a specific client (e.g., 'myclient:editor')
|
|
444
|
-
- 'realm:role' → realm role (e.g., 'realm:superuser')
|
|
445
|
-
- If a function, receives (token, req) and must return true or false synchronously.
|
|
446
|
-
This function enables custom authorization logic.
|
|
447
|
-
- The `token` object passed to the authorization function exposes methods such as:
|
|
448
|
-
- token.hasRole('admin') // client role in configured client
|
|
449
|
-
- token.hasRole('realm:superuser') // realm role
|
|
450
|
-
- token.hasRole('my-client:editor') // client role of a specific client
|
|
451
|
-
- token.hasResourceRole('editor', 'my-client-id') // equivalent to hasRole('my-client:editor')
|
|
452
|
-
|
|
453
|
-
The authorization function must be synchronous and return true (allow access) or false (deny access).
|
|
454
|
-
|
|
455
|
-
@returns {Function} Express middleware to protect the route.
|
|
456
|
-
|
|
457
|
-
✅ Usage example:
|
|
458
|
-
```js
|
|
459
|
-
|
|
460
|
-
// Authentication only, no role check
|
|
461
|
-
app.get('/admin', keycloakAdapter.protectMiddleware(), (req, res) => {
|
|
462
|
-
res.send('Only authenticated users can see this resource.');
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
// Check on client role of configured client (e.g., 'admin')
|
|
466
|
-
app.get('/admin', keycloakAdapter.protectMiddleware('admin'), (req, res) => {
|
|
467
|
-
res.send('Only users with the admin client role can access.');
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
// Check on role of a specific client (e.g., client 'clientid', role 'admin')
|
|
471
|
-
app.get('/admin', keycloakAdapter.protectMiddleware('clientid:admin'), (req, res) => {
|
|
472
|
-
res.send('Only users with admin role in client "clientid" can access.');
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
// Check on realm role (e.g., 'superuser' role at realm level)
|
|
476
|
-
app.get('/admin', keycloakAdapter.protectMiddleware('realm:superuser'), (req, res) => {
|
|
477
|
-
res.send('Only users with realm superuser role can access.');
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
// Custom synchronous authorization function
|
|
481
|
-
app.get('/custom', keycloakAdapter.protectMiddleware((token, req) => {
|
|
482
|
-
// Allow only if user has realm role 'editor'
|
|
483
|
-
// and the request has a specific custom header
|
|
484
|
-
return token.hasRealmRole('editor') && req.headers['x-custom-header'] === 'OK';
|
|
485
|
-
}), (req, res) => {
|
|
486
|
-
res.send('Access granted by custom authorization function.');
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
### `customProtectMiddleware(fn)`
|
|
493
|
-
Middleware similar to `protectMiddleware` but with dynamic role checking via a function.
|
|
494
|
-
|
|
495
|
-
Unlike `protectMiddleware`, which accepts a string expressing the role or a control function
|
|
496
|
-
that works on the token, this middleware accepts a function that receives the Express
|
|
497
|
-
request and response objects `req` and `res` and must return a string representing the role control string.
|
|
498
|
-
|
|
499
|
-
This is useful for parametric resources where the role control string must be dynamically generated based on the request,
|
|
500
|
-
for example, based on URL parameters or query strings.
|
|
501
|
-
|
|
502
|
-
Note: this function **does not** access or parse the token, nor performs any checks other than the role,
|
|
503
|
-
so it cannot be used for complex logic depending on request properties other than the role
|
|
504
|
-
(e.g., client IP, custom headers, etc.).
|
|
505
|
-
The function's sole task is to generate the role control string.
|
|
506
|
-
|
|
507
|
-
--- Parameters ---
|
|
508
|
-
|
|
509
|
-
@param {function} customFunction - function that receives (req, res) and returns a string
|
|
510
|
-
with the role control string to pass to Keycloak.
|
|
511
|
-
|
|
512
|
-
✅ Usage example:
|
|
513
|
-
```js
|
|
514
|
-
|
|
515
|
-
app.get('/custom/:id', keycloakAdapter.customProtectMiddleware((req) => {
|
|
516
|
-
// Dynamically builds the client role based on URL parameter 'id'
|
|
517
|
-
return `clientRole${req.params.id}`;
|
|
518
|
-
}), (req, res) => {
|
|
519
|
-
res.send(`Access granted to users with role 'clientRole${req.params.id}'`);
|
|
520
|
-
});
|
|
521
|
-
```
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
### `enforcerMiddleware(conditions, options)`
|
|
525
|
-
`enforcerMiddleware` is a middleware to enable permission checks
|
|
526
|
-
based on resources and policies defined in Keycloak Authorization Services (UMA 2.0-based).
|
|
527
|
-
|
|
528
|
-
Unlike `protectMiddleware` and similar, which only verify authentication or roles,
|
|
529
|
-
`enforcerMiddleware` allows checking if the user has permission to access
|
|
530
|
-
a specific protected resource through flexible and dynamic policies.
|
|
531
|
-
|
|
532
|
-
Useful in contexts where resources are registered in Keycloak (such as documents, instances, dynamic entities) and
|
|
533
|
-
protected by flexible policies.
|
|
534
|
-
|
|
535
|
-
--- Parameters ---
|
|
536
|
-
|
|
537
|
-
@param {string|function} conditions
|
|
538
|
-
- string containing the name of the resource or permission to check
|
|
539
|
-
- custom check function with signature:
|
|
540
|
-
function(token, req, callback)
|
|
541
|
-
- token: decoded Keycloak token
|
|
542
|
-
- req: Express request
|
|
543
|
-
- callback(boolean): invoke with true if authorized, false otherwise
|
|
544
|
-
|
|
545
|
-
@param {object} [options] (optional)
|
|
546
|
-
- response_mode: 'permissions' (default) or 'token'
|
|
547
|
-
- claims: object with claim info for dynamic policies (e.g. owner id matching)
|
|
548
|
-
- resource_server_id: resource client id (default: current client)
|
|
549
|
-
|
|
550
|
-
--- How it works ---
|
|
551
|
-
- If conditions is a function, it is used for custom checks with callback.
|
|
552
|
-
- If conditions is a string, `keycloak.enforcer(conditions, options)` is used for the check.
|
|
553
|
-
|
|
554
|
-
--- response_mode modes ---
|
|
555
|
-
1) 'permissions' (default)
|
|
556
|
-
- Keycloak returns the list of granted permissions (no new token)
|
|
557
|
-
- Permissions available in `req.permissions`
|
|
558
|
-
|
|
559
|
-
2) 'token'
|
|
560
|
-
- Keycloak issues a new access token containing the granted permissions
|
|
561
|
-
- Permissions available in `req.kauth.grant.access_token.content.authorization.permissions`
|
|
562
|
-
- Useful for apps with sessions and decision caching
|
|
563
|
-
|
|
564
|
-
--- Keycloak requirements ---
|
|
565
|
-
|
|
566
|
-
The client must have:
|
|
567
|
-
- Authorization Enabled = ON
|
|
568
|
-
- Policy Enforcement Mode = Enforcing
|
|
569
|
-
- Add permissions to access token = ON
|
|
570
|
-
|
|
571
|
-
You must also configure in Keycloak:
|
|
572
|
-
- Resources
|
|
573
|
-
- Policies (e.g., role, owner, JS script)
|
|
574
|
-
- Permissions (associate policies to resources)
|
|
575
|
-
|
|
576
|
-
✅ Usage example:
|
|
577
|
-
```js
|
|
578
|
-
|
|
579
|
-
// Check with static string
|
|
580
|
-
app.get('/onlyAdminroute', keycloakAdapter.enforcerMiddleware('ui-admin-resource'), (req, res) => {
|
|
581
|
-
res.send('You are an authorized admin for this resource');
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
// Check with custom function (async with callback)
|
|
585
|
-
app.get('/onlyAdminrouteByfunction', keycloakAdapter.enforcerMiddleware(function(token, req, callback) {
|
|
586
|
-
token.hasPermission('ui-admin-resource', function(permission) {
|
|
587
|
-
if (permission) callback(true);
|
|
588
|
-
else {
|
|
589
|
-
token.hasPermission('ui-viewer-resource', function(permission) {
|
|
590
|
-
callback(permission ? true : false);
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
}), (req, res) => {
|
|
595
|
-
res.send('You are an authorized admin or viewer (custom check)');
|
|
596
|
-
});
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
### `customEnforcerMiddleware(fn, options)`
|
|
600
|
-
`customEnforcerMiddleware` is a middleware for permission checks based on resources and policies
|
|
601
|
-
defined in Keycloak Authorization Services (UMA 2.0), using dynamic permission strings.
|
|
602
|
-
|
|
603
|
-
This middleware is similar to `enforcerMiddleware`, but takes a function
|
|
604
|
-
`customFunction(req, res)` as a parameter, which must dynamically return
|
|
605
|
-
the permission/resource string to be checked.
|
|
606
|
-
|
|
607
|
-
--- Parameters ---
|
|
608
|
-
|
|
609
|
-
@param {function} customFunction
|
|
610
|
-
Function that receives `req` and `res` and returns the control string for Keycloak.
|
|
611
|
-
Example:
|
|
612
|
-
```js
|
|
613
|
-
function customFunction(req, res) {
|
|
614
|
-
// Your function logic
|
|
615
|
-
return req.params.permission;
|
|
616
|
-
}
|
|
617
|
-
```
|
|
618
|
-
|
|
619
|
-
@param {object} [options] (optional)
|
|
620
|
-
Additional options passed to `keycloak.enforcer()`, including:
|
|
621
|
-
- response_mode: 'permissions' (default) or 'token'
|
|
622
|
-
- claims: object with claim info for dynamic policies (e.g., owner ID)
|
|
623
|
-
- resource_server_id: string representing the resource client ID (default: current client)
|
|
624
|
-
|
|
625
|
-
--- response_mode options ---
|
|
626
|
-
1) 'permissions' (default)
|
|
627
|
-
- The server returns only the list of granted permissions (no new token)
|
|
628
|
-
- Permissions available in `req.permissions`
|
|
629
|
-
|
|
630
|
-
2) 'token'
|
|
631
|
-
- The server issues a new access token with granted permissions
|
|
632
|
-
- Permissions available in `req.kauth.grant.access_token.content.authorization.permissions`
|
|
633
|
-
- Useful for decision caching, session handling, automatic token refresh
|
|
634
|
-
|
|
635
|
-
--- Keycloak Requirements ---
|
|
636
|
-
|
|
637
|
-
The client must be configured with:
|
|
638
|
-
- Authorization Enabled = ON
|
|
639
|
-
- Policy Enforcement Mode = Enforcing
|
|
640
|
-
- Add permissions to access token = ON
|
|
641
|
-
|
|
642
|
-
You must also have created:
|
|
643
|
-
- Resources
|
|
644
|
-
- Policies (e.g., role, owner, JS rules)
|
|
645
|
-
- Permissions (linking policies to resources)
|
|
646
|
-
|
|
647
|
-
✅ Usage example:
|
|
648
|
-
```js
|
|
649
|
-
|
|
650
|
-
const tmpFunctionEnforce = function(req, res) {
|
|
651
|
-
return req.params.permission; // dynamic permission from URL parameter
|
|
652
|
-
};
|
|
653
|
-
|
|
654
|
-
app.get('/onlyAdminrouteByfunction/:permission', keycloakAdapter.customEnforcerMiddleware(tmpFunctionEnforce), (req, res) => {
|
|
655
|
-
res.send('You are an authorized user with dynamic permission: ' + req.params.permission);
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
```
|
|
659
|
-
|
|
660
|
-
### `encodeTokenRole()`
|
|
661
|
-
`encodeTokenRole` is a middleware that decodes the Keycloak token and adds it
|
|
662
|
-
to the Express request as `req.encodedTokenRole`.
|
|
663
|
-
|
|
664
|
-
Unlike `protectMiddleware` or `customProtectMiddleware`, this middleware
|
|
665
|
-
does NOT perform any role or authentication checks, but simply extracts
|
|
666
|
-
and makes the decoded token available within the route handler function.
|
|
667
|
-
|
|
668
|
-
It is especially useful when you want to perform custom logic based on roles
|
|
669
|
-
or other information contained in the token directly in the route handler,
|
|
670
|
-
for example showing different content based on role.
|
|
671
|
-
|
|
672
|
-
--- Contents of `req.encodedTokenRole` ---
|
|
673
|
-
|
|
674
|
-
Represents the decoded Keycloak token and exposes several useful methods such as:
|
|
675
|
-
- token.hasRole('admin') // true/false if it has client role "admin"
|
|
676
|
-
- token.hasRole('realm:superuser') // true/false if it has realm role "superuser"
|
|
677
|
-
- token.hasRole('my-client:editor') // true/false if it has client role "editor" for client "my-client"
|
|
678
|
-
- token.hasResourceRole('editor', 'my-client-id') // identical to hasRole('my-client:editor')
|
|
679
|
-
|
|
680
|
-
✅ Usage example:
|
|
681
|
-
```js
|
|
682
|
-
|
|
683
|
-
app.get('/encodeToken', keycloakAdapter.encodeTokenRole(), (req, res) => {
|
|
684
|
-
if (req.encodedTokenRole.hasRole('realm:admin')) {
|
|
685
|
-
res.send("User with admin (realm) role in encodeToken");
|
|
686
|
-
} else {
|
|
687
|
-
res.send("Regular user in encodeToken");
|
|
688
|
-
}
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
```
|
|
692
|
-
|
|
693
|
-
### `encodeTokenPermission()`
|
|
694
|
-
`encodeTokenPermission` ia s Middleware whose sole purpose is to decode the access token present in the request
|
|
695
|
-
and add to the `req` object a property called `encodedTokenPermission` containing the token's permissions.
|
|
696
|
-
|
|
697
|
-
Unlike `enforcerMiddleware` and `customEnforcerMiddleware`, it **does not perform any access**
|
|
698
|
-
or authorization checks, but exposes a useful method (`hasPermission`) for checking permissions
|
|
699
|
-
within the route handler.
|
|
700
|
-
|
|
701
|
-
It is particularly useful when:
|
|
702
|
-
- you want to **customize the response** based on the user's permissions (e.g., show a different page),
|
|
703
|
-
- you want to **manually handle access** or perform custom checks on multiple permissions,
|
|
704
|
-
- you do not want to block access upfront but decide dynamically within the route handler.
|
|
705
|
-
|
|
706
|
-
--- Additions to `req` ---
|
|
707
|
-
|
|
708
|
-
After applying the middleware, `req` contains:
|
|
709
|
-
- @property {Object} req.encodedTokenPermission
|
|
710
|
-
An object exposing the method:
|
|
711
|
-
- hasPermission(permission: string, callback: function(boolean))
|
|
712
|
-
Checks whether the token contains the specified permission.
|
|
713
|
-
The callback receives `true` if the permission is present, `false` otherwise.
|
|
714
|
-
|
|
715
|
-
✅ Usage example:
|
|
716
|
-
```js
|
|
717
|
-
|
|
718
|
-
app.get('/encodeTokenPermission',
|
|
719
|
-
keycloakAdapter.encodeTokenPermission(),
|
|
720
|
-
(req, res) => {
|
|
721
|
-
req.encodedTokenPermission.hasPermission('ui-admin-resource', function(perm) {
|
|
722
|
-
if (perm)
|
|
723
|
-
res.send('You are an authorized admin user by function permission parameters');
|
|
724
|
-
else
|
|
725
|
-
res.status(403).send('Access Denied by encodeTokenPermission');
|
|
726
|
-
});
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
```
|
|
730
|
-
|
|
731
|
-
### `loginMiddleware(redirectTo)`
|
|
732
|
-
`loginMiddleware` is a Middleware used to **force user authentication** via Keycloak.
|
|
733
|
-
|
|
734
|
-
It is particularly useful when you want to:
|
|
735
|
-
- ensure the user is authenticated,
|
|
736
|
-
- redirect the user to a specific page after login or when access is denied,
|
|
737
|
-
- integrate automatic login flows on routes that don’t require direct authorization,
|
|
738
|
-
but where login should still be enforced (e.g., profile page, personal area, etc.).
|
|
739
|
-
|
|
740
|
-
--- Behavior ---
|
|
741
|
-
1. If the user is **not authenticated**, Keycloak redirects them to the login flow.
|
|
742
|
-
2. If authentication fails or is denied, the user is redirected according to Keycloak's configured settings.
|
|
743
|
-
3. If authentication is successful, the user is redirected to 'redirectTo' (usually `/home`, `/dashboard`, etc.).
|
|
744
|
-
|
|
745
|
-
--- Parameters ---
|
|
746
|
-
|
|
747
|
-
@param {string} redirectTo - URL to redirect the user to after login.
|
|
748
|
-
|
|
749
|
-
--- Warning ---
|
|
750
|
-
|
|
751
|
-
The route handler callback is **never executed**, because the middleware will respond earlier
|
|
752
|
-
with a redirect or block the request.
|
|
753
|
-
|
|
754
|
-
✅ Usage example:
|
|
755
|
-
```js
|
|
756
|
-
|
|
757
|
-
app.get('/loginMiddleware', keycloakAdapter.loginMiddleware("/home"), (req, res) => {
|
|
758
|
-
// This section is never reached
|
|
759
|
-
res.send("If you see this message, something went wrong.");
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
```
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
### `logoutMiddleware(redirectTo)`
|
|
766
|
-
`logoutMiddleware` Middleware is used to **force user logout**, removing the local session
|
|
767
|
-
and redirecting the user to Keycloak's logout endpoint according to its configuration.
|
|
768
|
-
|
|
769
|
-
It is useful when:
|
|
770
|
-
- You want to completely log out the user,
|
|
771
|
-
- You want to **terminate the session on Keycloak** (not just locally),
|
|
772
|
-
- You want to redirect the user to a public page, such as a homepage, after logout.
|
|
773
|
-
|
|
774
|
-
--- Behavior ---
|
|
775
|
-
1. Retrieves the `id_token` of the authenticated user.
|
|
776
|
-
2. Constructs the Keycloak logout URL including the token and the redirect URL.
|
|
777
|
-
3. **Destroys the local Express session** (e.g., cookies, user data).
|
|
778
|
-
4. Redirects the user to the Keycloak logout URL, which in turn redirects to the provided URL.
|
|
779
|
-
|
|
780
|
-
--- Parameters ---
|
|
781
|
-
|
|
782
|
-
@param {string} redirectTo - URL to which the user will be redirected after complete logout.
|
|
783
|
-
|
|
784
|
-
✅ Usage example:
|
|
785
|
-
```js
|
|
786
|
-
|
|
787
|
-
app.get('/logoutMiddleware', keycloakAdapter.logoutMiddleware("http://localhost:3001/home"), (req, res) => {
|
|
788
|
-
// This section is never reached
|
|
789
|
-
// The middleware handles logout and redirection automatically
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
```
|
|
793
|
-
|
|
794
|
-
--- Note ---
|
|
795
|
-
- The middleware **never executes the route callback**, as it fully handles the response.
|
|
796
|
-
- The `redirectTo` parameter must match a **valid redirect URI** configured in Keycloak for the client.
|
|
797
|
-
|
|
798
|
-
--- Requirements ---
|
|
799
|
-
- The Keycloak client must have properly configured `Valid Redirect URIs`.
|
|
800
|
-
- The Express session must be active (e.g., `express-session` properly initialized).
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
## 🔧 Available Functions
|
|
804
|
-
|
|
805
|
-
### `login(req, res, redirectTo)`
|
|
806
|
-
`login` Function not a middleware, but a **classic synchronous function** that forces user authentication
|
|
807
|
-
via Keycloak and, if the user is not authenticated, redirects them to the login page.
|
|
808
|
-
After successful login, the user is redirected to the URL specified in the `redirectTo` parameter.
|
|
809
|
-
|
|
810
|
-
--- Differences from `loginMiddleware` ---
|
|
811
|
-
- `loginMiddleware` handles everything automatically **before** the route handler function.
|
|
812
|
-
- `login` instead is a function **that can be manually called inside the route handler**,
|
|
813
|
-
offering **greater control** over when and how login is enforced.
|
|
814
|
-
|
|
815
|
-
--- Parameters ---
|
|
816
|
-
|
|
817
|
-
- @param {Object} req - Express `Request` object
|
|
818
|
-
- @param {Object} res - Express `Response` object
|
|
819
|
-
- @param {string} redirectTo - URL to redirect the user to after successful login
|
|
820
|
-
|
|
821
|
-
--- Behavior ---
|
|
822
|
-
1. Attempts to protect the request using `keycloak.protect()`.
|
|
823
|
-
2. If the user **is authenticated**, it performs `res.redirect(redirectTo)`.
|
|
824
|
-
3. If **not authenticated**, Keycloak automatically handles redirection to the login page.
|
|
825
|
-
|
|
826
|
-
✅ Usage example:
|
|
827
|
-
```js
|
|
828
|
-
|
|
829
|
-
app.get('/login', (req, res) => {
|
|
830
|
-
// Your route logic
|
|
831
|
-
// ...
|
|
832
|
-
// Force authentication if necessary
|
|
833
|
-
keycloakAdapter.login(req, res, "/home");
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
```
|
|
837
|
-
|
|
838
|
-
--- Notes ---
|
|
839
|
-
- The function can be called **within an Express route**, allowing for custom conditional logic.
|
|
840
|
-
- Useful for scenarios where only certain conditions should trigger a login.
|
|
841
|
-
|
|
842
|
-
--- Requirements ---
|
|
843
|
-
- `Valid Redirect URIs` must include the URL passed to `redirectTo`.
|
|
844
|
-
|
|
845
|
-
### `logout(req, res, redirectTo)`
|
|
846
|
-
`logout` Function is not a middleware, but a **classic synchronous function** that forces the user to logout
|
|
847
|
-
via Keycloak. In addition to terminating the current session (if any), it generates the Keycloak
|
|
848
|
-
logout URL and redirects the user's browser to that address.
|
|
849
|
-
|
|
850
|
-
--- Differences from `logoutMiddleware` ---
|
|
851
|
-
- `logoutMiddleware` is designed to be used directly as middleware in the route definition.
|
|
852
|
-
- `logout` instead is a function **to be called inside the route**, useful for handling logout
|
|
853
|
-
**conditionally** or within more complex logic.
|
|
854
|
-
|
|
855
|
-
--- Parameters ---
|
|
856
|
-
- @param {Object} req - Express `Request` object
|
|
857
|
-
- @param {Object} res - Express `Response` object
|
|
858
|
-
- @param {string} redirectTo - URL to redirect the user after logout
|
|
859
|
-
|
|
860
|
-
--- Behavior ---
|
|
861
|
-
1. Retrieves the `id_token` from the current user's Keycloak token (if present).
|
|
862
|
-
2. Builds the logout URL using `keycloak.logoutUrl()`.
|
|
863
|
-
3. Destroys the user's Express session.
|
|
864
|
-
4. Redirects the user to the Keycloak logout URL, which in turn redirects to `redirectTo`.
|
|
865
|
-
|
|
866
|
-
✅ Usage example:
|
|
867
|
-
```js
|
|
868
|
-
|
|
869
|
-
app.get('/logout', (req, res) => {
|
|
870
|
-
// Any custom logic before logout
|
|
871
|
-
// ...
|
|
872
|
-
keycloakAdapter.logout(req, res, "http://localhost:3001/home");
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
```
|
|
876
|
-
|
|
877
|
-
--- Requirements ---
|
|
878
|
-
- The user must be authenticated with Keycloak and have a valid token in `req.kauth.grant`.
|
|
879
|
-
- The URL specified in `redirectTo` must be present in the `Valid Redirect URIs` in the Keycloak client.
|
|
880
|
-
|
|
186
|
+
- grantType: [required] The OAuth2 grant type used for authentication. example "password". Possible values: 'password', 'client_credentials', 'refresh_token', etc.
|
|
187
|
+
- clientId: [required] string containing the client ID configured in Keycloak. Required for all grant types.
|
|
188
|
+
- username: [optional] string username. Required when using the password grant type.
|
|
189
|
+
- password: [optional] string password. Required when using the password grant type.
|
|
190
|
+
- baseUrl: [Optional] Keycloak base Url
|
|
191
|
+
- realmName: [Optional] A String that specifies the realm to authenticate against, if different from the "keyCloakConfig.realm" parameter. If you intend to use Keycloak administrator credentials, this should be set to 'master'.
|
|
192
|
+
- scope: [Optional] A string that specifies The OAuth2 scope requested during authentication (optional). Typically, not required for administrative clients. example:openid profile
|
|
193
|
+
- requestOptions: [Optional] JSON parameters to configure HTTP requests (such as custom headers, timeouts, etc.). It is compatible with the Fetch API standard. Fetch request options https://developer.mozilla.org/en-US/docs/Web/API/fetch#options
|
|
194
|
+
- clientSecret: [Optional] string containing the client secret of the client. Required for client_credentials or confidential clients.
|
|
195
|
+
- totp: string for Time-based One-Time Password (TOTP) for multifactor authentication (MFA), if enabled for the user.
|
|
196
|
+
- offlineToken: [Optional] boolean value. If true, requests an offline token (used for long-lived refresh tokens). Default is false.
|
|
197
|
+
- refreshToken: [Optional] string containing a valid refresh token to request a new access token when using the refresh_token grant type.
|
|
881
198
|
---
|
|
882
199
|
|
|
883
200
|
|
|
884
|
-
## 🔧 Admin Functions
|
|
885
|
-
All administrative functions that rely on Keycloak's Admin API must be invoked using the
|
|
886
|
-
|
|
201
|
+
## 🔧 Available Admin Functions
|
|
202
|
+
All administrative functions that rely on Keycloak's Admin API must be invoked using the
|
|
203
|
+
KeycloakManager.{entity}.{function} pattern.
|
|
887
204
|
- {entyty} represents the type of resource you want to manage (e.g., users, roles, groups, clients).
|
|
888
205
|
- {function} is the specific operation you want to perform on that resource (e.g., find, create, update, del).
|
|
889
206
|
For example:
|
|
890
207
|
```js
|
|
208
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
891
209
|
// get all users of this client
|
|
892
210
|
// users is the entity you want to administer.
|
|
893
211
|
// find is the method used to retrieve the list of users.
|
|
894
|
-
|
|
212
|
+
KeycloakManager.users.find();
|
|
895
213
|
```
|
|
896
214
|
Credits to @keycloak/keycloak-admin-client.
|
|
897
215
|
This admin function is built on top of it. For more details, please refer to the official repository.
|
|
@@ -899,7 +217,7 @@ This admin function is built on top of it. For more details, please refer to the
|
|
|
899
217
|
### `entity realm`
|
|
900
218
|
The realms property provides access to all administrative operations related to Keycloak realms.
|
|
901
219
|
A realm in Keycloak is a fundamental concept that acts as an isolated tenant:
|
|
902
|
-
|
|
220
|
+
each realm manages its own set of users, roles, groups, and clients independently.
|
|
903
221
|
#### `entity realm functions`
|
|
904
222
|
|
|
905
223
|
##### `function create(realm-dictionary)`
|
|
@@ -909,11 +227,12 @@ This method accepts a realm representation object containing details such as is,
|
|
|
909
227
|
- realm-dictionary: is a JSON object that accepts filter parameters
|
|
910
228
|
- id:[required] The internal ID of the realm. If omitted, Keycloak uses the realm name as the ID.
|
|
911
229
|
- realm:[required] The name of the realm to create.
|
|
912
|
-
- Additional optional properties can be passed to configure the realm (e.g., enabled, displayName, etc.).
|
|
230
|
+
- { other fields }Additional optional properties can be passed to configure the realm (e.g., enabled, displayName, etc.).
|
|
913
231
|
|
|
914
232
|
```js
|
|
233
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
915
234
|
// create a new realm
|
|
916
|
-
const realm = await
|
|
235
|
+
const realm = await KeycloakManager.realms.create({
|
|
917
236
|
id: "realm-id",
|
|
918
237
|
realm: "realmName",
|
|
919
238
|
});
|
|
@@ -929,8 +248,9 @@ You can use this method to modify settings such as login behavior, themes, token
|
|
|
929
248
|
- realm properties that can be passed to update the realm (e.g., enabled, displayName, etc.).
|
|
930
249
|
|
|
931
250
|
```js
|
|
251
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
932
252
|
// update a realm
|
|
933
|
-
await
|
|
253
|
+
await KeycloakManager.realms.update(
|
|
934
254
|
{ realm: 'realm-name' },
|
|
935
255
|
{
|
|
936
256
|
displayName: "test",
|
|
@@ -947,20 +267,21 @@ This operation is irreversible and removes all users, clients, roles, groups, an
|
|
|
947
267
|
- realm:[required] The name of the realm to delete.
|
|
948
268
|
|
|
949
269
|
```js
|
|
270
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
950
271
|
// delete 'realmeName' realm
|
|
951
|
-
const realm = await
|
|
272
|
+
const realm = await KeycloakManager.realms.del({
|
|
952
273
|
realm: "realmName",
|
|
953
274
|
});
|
|
954
275
|
```
|
|
955
276
|
|
|
956
|
-
##### `function find(
|
|
277
|
+
##### `function find()`
|
|
957
278
|
Retrieves a list of all realms configured in the Keycloak server.
|
|
958
279
|
This includes basic metadata for each realm such as ID and display name, but not the full configuration details.
|
|
959
280
|
This method does not take any parameters.
|
|
960
|
-
|
|
961
281
|
```js
|
|
282
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
962
283
|
// delete 'realmeName' realm
|
|
963
|
-
|
|
284
|
+
const realms = await KeycloakManager.realms.find();
|
|
964
285
|
console.log("Retrieved realms:",realms);
|
|
965
286
|
```
|
|
966
287
|
|
|
@@ -972,8 +293,9 @@ This includes settings like login policies, themes, password policies, etc.
|
|
|
972
293
|
- realm:[required] The name (ID) of the realm you want to retrieve.
|
|
973
294
|
|
|
974
295
|
```js
|
|
296
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
975
297
|
// delete 'realmeName' realm
|
|
976
|
-
|
|
298
|
+
const realmConfig = await KeycloakManager.realms.findOne({
|
|
977
299
|
realm: "realmName",
|
|
978
300
|
});
|
|
979
301
|
console.log("Retrieved realm:",realmConfig);
|
|
@@ -993,9 +315,10 @@ It’s useful for incremental updates or merging configuration pieces.
|
|
|
993
315
|
- 'FAIL' – the operation fails if a resource already exists.
|
|
994
316
|
- 'SKIP' – existing resources are skipped.
|
|
995
317
|
- 'OVERWRITE' – existing resources are overwritten.
|
|
996
|
-
- other configuration to be imported like users, roles, groups ...
|
|
318
|
+
- {other fields} other configuration to be imported like users, roles, groups ...
|
|
997
319
|
|
|
998
320
|
```js
|
|
321
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
999
322
|
// import configuration
|
|
1000
323
|
const roleToImport: PartialImportRealmRepresentation = {
|
|
1001
324
|
ifResourceExists: "FAIL",
|
|
@@ -1011,7 +334,7 @@ const roleToImport: PartialImportRealmRepresentation = {
|
|
|
1011
334
|
},
|
|
1012
335
|
};
|
|
1013
336
|
// partial realm import
|
|
1014
|
-
const result = await
|
|
337
|
+
const result = await KeycloakManager.realms.partialImport({
|
|
1015
338
|
realm: 'my-realm',
|
|
1016
339
|
rep: roleToImport,
|
|
1017
340
|
});
|
|
@@ -1027,9 +350,10 @@ This method returns the full realm representation in JSON format, including role
|
|
|
1027
350
|
- exportGroupsAndRoles: [optional] boolean, Whether to include groups and roles in the export. Default: true.
|
|
1028
351
|
|
|
1029
352
|
```js
|
|
353
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1030
354
|
|
|
1031
355
|
// realm export
|
|
1032
|
-
const exportedRealm = await
|
|
356
|
+
const exportedRealm = await KeycloakManager.realms.export({
|
|
1033
357
|
realm: 'my-realm',
|
|
1034
358
|
exportClients: true, // optional
|
|
1035
359
|
exportGroupsAndRoles: true, // optional
|
|
@@ -1046,9 +370,10 @@ These providers define how new clients can be registered and what rules or valid
|
|
|
1046
370
|
- realm:[required] The name of the realm where you want to list client registration policy providers.
|
|
1047
371
|
|
|
1048
372
|
```js
|
|
373
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1049
374
|
|
|
1050
375
|
// get Client Registration Policy Providers
|
|
1051
|
-
await
|
|
376
|
+
await KeycloakManager.realms.getClientRegistrationPolicyProviders({
|
|
1052
377
|
realm: currentRealmName,
|
|
1053
378
|
});
|
|
1054
379
|
```
|
|
@@ -1073,8 +398,9 @@ This token allows clients to register themselves with the realm using the Dynami
|
|
|
1073
398
|
- count: Maximum allowed uses
|
|
1074
399
|
- remainingCount: How many uses are left
|
|
1075
400
|
```js
|
|
401
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1076
402
|
// get Client Registration Policy Providers with oount=1 and unlimited expiration time
|
|
1077
|
-
const initialAccess= await
|
|
403
|
+
const initialAccess= await KeycloakManager.realms.realms.createClientsInitialAccess(
|
|
1078
404
|
{ realm: currentRealmName },
|
|
1079
405
|
{ count: 1, expiration: 0 },
|
|
1080
406
|
);
|
|
@@ -1097,8 +423,9 @@ These tokens are used to allow programmatic or automated registration of clients
|
|
|
1097
423
|
- count: Maximum allowed uses
|
|
1098
424
|
- remainingCount: How many uses are left
|
|
1099
425
|
```js
|
|
426
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1100
427
|
// get get Clients Initial Access list
|
|
1101
|
-
const tokens= await
|
|
428
|
+
const tokens= await KeycloakManager.realms.getClientsInitialAccess({ realm:'realm-id'});
|
|
1102
429
|
console.log("Initial Access Tokens:", tokens);
|
|
1103
430
|
```
|
|
1104
431
|
|
|
@@ -1112,8 +439,9 @@ This revokes the token, preventing any future use.
|
|
|
1112
439
|
- realm:[required] The name of the realm where the token was created.
|
|
1113
440
|
- id:[required] The ID of the initial access token you want to delete.
|
|
1114
441
|
```js
|
|
442
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1115
443
|
// delete Clients Initial Access
|
|
1116
|
-
await
|
|
444
|
+
await KeycloakManager.realms.delClientsInitialAccess({
|
|
1117
445
|
realm: 'realm-id',
|
|
1118
446
|
id: 'initial-access-token-id',
|
|
1119
447
|
});
|
|
@@ -1128,8 +456,9 @@ Users created in this realm will automatically be added to all default groups.
|
|
|
1128
456
|
- realm:[required] The name of the realm where the default group will be set.
|
|
1129
457
|
- id:[required] The ID of the group to be added as a default group
|
|
1130
458
|
```js
|
|
459
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1131
460
|
// get get Clients Initial Access list
|
|
1132
|
-
await
|
|
461
|
+
await KeycloakManager.realms.addDefaultGroup({
|
|
1133
462
|
realm: 'realm-id',
|
|
1134
463
|
id: 'default-group-id',
|
|
1135
464
|
});
|
|
@@ -1143,8 +472,9 @@ Default groups are automatically assigned to new users when they are created.
|
|
|
1143
472
|
- realm:[required] The name of the realm from which to remove the default group.
|
|
1144
473
|
- id:[required] The ID of the group you want to remove from the default list.
|
|
1145
474
|
```js
|
|
475
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1146
476
|
// remove from 'realm-id' the group 'default-group-id'
|
|
1147
|
-
await
|
|
477
|
+
await KeycloakManager.realms.removeDefaultGroup({
|
|
1148
478
|
realm: 'realm-id',
|
|
1149
479
|
id: 'default-group-id',
|
|
1150
480
|
});
|
|
@@ -1159,8 +489,9 @@ These are the groups that new users will automatically be added to upon creation
|
|
|
1159
489
|
- realm:[required] The name of the realm from which to retrieve default groups.
|
|
1160
490
|
|
|
1161
491
|
```js
|
|
492
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1162
493
|
// get 'realm-id' default groups
|
|
1163
|
-
const defaultGroups = await
|
|
494
|
+
const defaultGroups = await KeycloakManager.realms.getDefaultGroups({
|
|
1164
495
|
realm: 'realm-id',
|
|
1165
496
|
});
|
|
1166
497
|
console.log(defaultGroups);
|
|
@@ -1177,8 +508,9 @@ This is useful when you know the group’s full path (e.g., /parent/child) but n
|
|
|
1177
508
|
|
|
1178
509
|
|
|
1179
510
|
```js
|
|
511
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1180
512
|
// get 'realm-id' group by Path
|
|
1181
|
-
const defaultGroups = await
|
|
513
|
+
const defaultGroups = await KeycloakManager.realms.getGroupByPath({
|
|
1182
514
|
realm: 'realm-id',
|
|
1183
515
|
path: 'realm-name-path'
|
|
1184
516
|
});
|
|
@@ -1195,8 +527,9 @@ Useful for auditing and tracking activities inside Keycloak.
|
|
|
1195
527
|
- realmFilter: is a JSON object that accepts filter parameters
|
|
1196
528
|
- realm:[required] The name of the realm from which to retrieve the event configuration.
|
|
1197
529
|
```js
|
|
530
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1198
531
|
// get Config Events
|
|
1199
|
-
const config= await
|
|
532
|
+
const config= await KeycloakManager.realms.getConfigEvents({
|
|
1200
533
|
realm: 'realm-id',
|
|
1201
534
|
});
|
|
1202
535
|
console.log(config);
|
|
@@ -1227,8 +560,9 @@ enabling admin event logging, and choosing which event listeners to use.
|
|
|
1227
560
|
- adminEventsEnabled: Enables logging for admin events.
|
|
1228
561
|
- adminEventsDetailsEnabled: Includes full details in admin event logs if set to true.
|
|
1229
562
|
```js
|
|
563
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1230
564
|
// Update Config Events
|
|
1231
|
-
const config= await
|
|
565
|
+
const config= await KeycloakManager.realms.updateConfigEvents(
|
|
1232
566
|
{ realm: 'realm-id'},
|
|
1233
567
|
{
|
|
1234
568
|
eventsEnabled: true,
|
|
@@ -1256,9 +590,10 @@ Useful for auditing login, logout, and other user-related activities.
|
|
|
1256
590
|
- first: [optional] Pagination offset.
|
|
1257
591
|
- max: [optional] Maximum number of events to return.
|
|
1258
592
|
```js
|
|
593
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1259
594
|
|
|
1260
595
|
// find 10 realm-id events with a type=LOGIN and dateFrom and dateTo.
|
|
1261
|
-
const config= await
|
|
596
|
+
const config= await KeycloakManager.realms.findEvents({
|
|
1262
597
|
realm: 'realm-id',
|
|
1263
598
|
type: 'LOGIN',
|
|
1264
599
|
dateFrom: '2025-08-01T00:00:00Z',
|
|
@@ -1286,9 +621,10 @@ This is useful for auditing changes made via the admin API or admin console.
|
|
|
1286
621
|
- resourcePath: [optional] Filter events by resource path.
|
|
1287
622
|
- resourceTypes: [optional] Filter events by resource type (e.g., USER, REALM_ROLE, CLIENT).
|
|
1288
623
|
```js
|
|
624
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1289
625
|
|
|
1290
626
|
// find 10 realm-id admin events with a type=CREATE|DELETE and dateFrom and dateTo.
|
|
1291
|
-
const config= await
|
|
627
|
+
const config= await KeycloakManager.realms.findAdminEvents({
|
|
1292
628
|
realm: 'realm-id',
|
|
1293
629
|
operationTypes: ['CREATE', 'DELETE'],
|
|
1294
630
|
dateFrom: '2025-08-01T00:00:00Z',
|
|
@@ -1307,9 +643,10 @@ This does not clear administrative events. To remove those, use realms.clearAdmi
|
|
|
1307
643
|
- realmFilter: is a JSON object that accepts filter parameters
|
|
1308
644
|
- realm: [required] The name of the realm from which to clear user events.
|
|
1309
645
|
```js
|
|
646
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1310
647
|
|
|
1311
648
|
// clear realm-id events
|
|
1312
|
-
const config= await
|
|
649
|
+
const config= await KeycloakManager.realms.clearEvents({
|
|
1313
650
|
realm: 'realm-id',
|
|
1314
651
|
});
|
|
1315
652
|
```
|
|
@@ -1323,9 +660,10 @@ performed by administrators via the Admin Console or Admin REST API.
|
|
|
1323
660
|
- realmFilter: is a JSON object that accepts filter parameters
|
|
1324
661
|
- realm: [required] The name of the realm from which to clear administrative events.
|
|
1325
662
|
```js
|
|
663
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1326
664
|
|
|
1327
665
|
// clear realm-id admin events
|
|
1328
|
-
const config= await
|
|
666
|
+
const config= await KeycloakManager.realms.clearAdminEvents({
|
|
1329
667
|
realm: 'realm-id',
|
|
1330
668
|
});
|
|
1331
669
|
```
|
|
@@ -1342,6 +680,7 @@ This allows you to check whether user management operations (like creating, upda
|
|
|
1342
680
|
|
|
1343
681
|
Returns an object with information such as:
|
|
1344
682
|
```js
|
|
683
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1345
684
|
{
|
|
1346
685
|
enabled: boolean;
|
|
1347
686
|
resource: string;
|
|
@@ -1354,9 +693,10 @@ if enabled is false, user management operations are not restricted by fine-grain
|
|
|
1354
693
|
You can enable or configure these permissions using updateUsersManagementPermissions()
|
|
1355
694
|
|
|
1356
695
|
```js
|
|
696
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1357
697
|
|
|
1358
698
|
// Get Permissions
|
|
1359
|
-
const permissions= await
|
|
699
|
+
const permissions= await KeycloakManager.realms.getUsersManagementPermissions({
|
|
1360
700
|
realm: 'realm-id',
|
|
1361
701
|
});
|
|
1362
702
|
console.log(permissions.enabled); // true or false
|
|
@@ -1378,6 +718,7 @@ are protected using Keycloak's authorization services.
|
|
|
1378
718
|
|
|
1379
719
|
Returns an object with information such as:
|
|
1380
720
|
```js
|
|
721
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1381
722
|
{
|
|
1382
723
|
enabled: boolean;
|
|
1383
724
|
resource: string;
|
|
@@ -1388,8 +729,9 @@ Returns an object with information such as:
|
|
|
1388
729
|
```
|
|
1389
730
|
|
|
1390
731
|
```js
|
|
732
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1391
733
|
// Update Permissions
|
|
1392
|
-
const permissions= await
|
|
734
|
+
const permissions= await KeycloakManager.realms.updateUsersManagementPermissions({
|
|
1393
735
|
realm: 'realm-id',
|
|
1394
736
|
});
|
|
1395
737
|
|
|
@@ -1427,8 +769,9 @@ Returns a list of keys and related information:
|
|
|
1427
769
|
```
|
|
1428
770
|
|
|
1429
771
|
```js
|
|
772
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1430
773
|
// Get Keys
|
|
1431
|
-
const Keys= await
|
|
774
|
+
const Keys= await KeycloakManager.realms.getKeys({
|
|
1432
775
|
realm: 'realm-id',
|
|
1433
776
|
});
|
|
1434
777
|
|
|
@@ -1447,8 +790,9 @@ Retrieves statistics about active client sessions in the specified realm. This i
|
|
|
1447
790
|
Returns an array of objects, each representing a client with active sessions
|
|
1448
791
|
|
|
1449
792
|
```js
|
|
793
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1450
794
|
// Get Client Session Stats
|
|
1451
|
-
const stats= await
|
|
795
|
+
const stats= await KeycloakManager.realms.getClientSessionStats({
|
|
1452
796
|
realm: 'realm-id',
|
|
1453
797
|
});
|
|
1454
798
|
|
|
@@ -1472,8 +816,9 @@ This forces clients to revalidate tokens, effectively revoking cached access tok
|
|
|
1472
816
|
- realm: [required] The name of the realm where the revocation should be pushed.
|
|
1473
817
|
|
|
1474
818
|
```js
|
|
819
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1475
820
|
// push revocaiton to realm realm-id
|
|
1476
|
-
const pushR= await
|
|
821
|
+
const pushR= await KeycloakManager.realms.pushRevocation({
|
|
1477
822
|
realm: 'realm-id',
|
|
1478
823
|
});
|
|
1479
824
|
|
|
@@ -1490,8 +835,9 @@ This invalidates all user sessions, forcing every user to re-authenticate.
|
|
|
1490
835
|
- realm: [required] The name of the realm from which to log out all users.
|
|
1491
836
|
|
|
1492
837
|
```js
|
|
838
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1493
839
|
// force all users logout in realm realm-id
|
|
1494
|
-
const logout= await
|
|
840
|
+
const logout= await KeycloakManager.realms.logoutAll({
|
|
1495
841
|
realm: 'realm-id',
|
|
1496
842
|
});
|
|
1497
843
|
|
|
@@ -1517,9 +863,10 @@ fully integrating it into the realm configuration.
|
|
|
1517
863
|
- authType: [optional] Type of authentication; usually "simple" or "none".
|
|
1518
864
|
|
|
1519
865
|
```js
|
|
866
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1520
867
|
//should fail with invalid ldap settings
|
|
1521
868
|
try {
|
|
1522
|
-
await
|
|
869
|
+
await KeycloakManager.realms.testLDAPConnection(
|
|
1523
870
|
{ realm: "realm-name" },
|
|
1524
871
|
{
|
|
1525
872
|
action: "testConnection",
|
|
@@ -1557,9 +904,10 @@ such as supported controls, extensions, authentication mechanisms, and more.
|
|
|
1557
904
|
- authType: [optional] Type of authentication; usually "simple" or "none".
|
|
1558
905
|
|
|
1559
906
|
```js
|
|
907
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1560
908
|
// should fail with invalid ldap server capabilities
|
|
1561
909
|
try {
|
|
1562
|
-
await
|
|
910
|
+
await KeycloakManager.realms.ldapServerCapabilities(
|
|
1563
911
|
{ realm: "realm-name" },
|
|
1564
912
|
{
|
|
1565
913
|
action: "testConnection",
|
|
@@ -1600,9 +948,10 @@ SMTP server before applying the settings to the realm.
|
|
|
1600
948
|
- envelopeFrom [optional] Envelope sender address.
|
|
1601
949
|
|
|
1602
950
|
```js
|
|
951
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1603
952
|
// should fail with invalid smtp settings
|
|
1604
953
|
try {
|
|
1605
|
-
await
|
|
954
|
+
await KeycloakManager.realms.testSMTPConnection(
|
|
1606
955
|
{ realm: "master" },
|
|
1607
956
|
{
|
|
1608
957
|
from: "test@test.com",
|
|
@@ -1626,10 +975,10 @@ Localization texts are used to override default Keycloak UI messages for login f
|
|
|
1626
975
|
- filter: is a JSON object that accepts this filter parameters
|
|
1627
976
|
- realm: [required] The name of the realm from which to fetch localization texts.
|
|
1628
977
|
- selectedLocale: [required] The locale code (e.g., 'en', 'it', 'fr', etc.) for which you want to retrieve the translations.
|
|
1629
|
-
-
|
|
1630
978
|
```js
|
|
979
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1631
980
|
// Realm localization
|
|
1632
|
-
const texts= await
|
|
981
|
+
const texts= await KeycloakManager.realms.getRealmLocalizationTexts({
|
|
1633
982
|
realm: "realm-id",
|
|
1634
983
|
selectedLocale:'it'
|
|
1635
984
|
});
|
|
@@ -1649,8 +998,9 @@ This allows you to override default messages in the login screens and other UI c
|
|
|
1649
998
|
- key: [required] The message key or identifier to override (e.g., loginAccountTitle, errorInvalidUsername).
|
|
1650
999
|
- value: [required] The actual translated text to associate with the key for the given locale.
|
|
1651
1000
|
```js
|
|
1001
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1652
1002
|
// should add localization
|
|
1653
|
-
await
|
|
1003
|
+
await KeycloakManager.realms.addLocalization({
|
|
1654
1004
|
realm: "realm-id",
|
|
1655
1005
|
selectedLocale:'it',
|
|
1656
1006
|
key:"theKey"
|
|
@@ -1671,15 +1021,16 @@ This function is useful to determine which locales have at least one overridden
|
|
|
1671
1021
|
Return An array of locale codes (e.g., ["en", "it", "fr"]) representing the languages that have at least
|
|
1672
1022
|
one customized localization entry in the given realm.
|
|
1673
1023
|
```js
|
|
1024
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1674
1025
|
// should add localization
|
|
1675
|
-
await
|
|
1026
|
+
await KeycloakManager.realms.addLocalization({
|
|
1676
1027
|
realm: "realm-id",
|
|
1677
1028
|
selectedLocale:'it',
|
|
1678
1029
|
key:"theKey"
|
|
1679
1030
|
},"new Value String for key:theKey");
|
|
1680
1031
|
|
|
1681
1032
|
// should get localization for specified locale
|
|
1682
|
-
const specificLocales= await
|
|
1033
|
+
const specificLocales= await KeycloakManager.realms.getRealmSpecificLocales({
|
|
1683
1034
|
realm: "realm-id",
|
|
1684
1035
|
selectedLocale: "it",
|
|
1685
1036
|
});
|
|
@@ -1702,8 +1053,9 @@ This is useful when you want to remove a previously added or overridden message
|
|
|
1702
1053
|
Returns void if the deletion is successful. Will throw an error if the entry does not exist or if parameters are invalid.
|
|
1703
1054
|
|
|
1704
1055
|
```js
|
|
1056
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1705
1057
|
// should delete localization for specified locale key 'theKey'
|
|
1706
|
-
await
|
|
1058
|
+
await KeycloakManager.realms.deleteRealmLocalizationTexts({
|
|
1707
1059
|
realm: "realm-id",
|
|
1708
1060
|
selectedLocale: "it",
|
|
1709
1061
|
key:'theKey'
|
|
@@ -1726,8 +1078,9 @@ It is typically used when you want to programmatically add new users to your Key
|
|
|
1726
1078
|
@parameters:
|
|
1727
1079
|
- userRepresentation: An object containing the user fields to be updated.
|
|
1728
1080
|
```js
|
|
1081
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1729
1082
|
// create a new user
|
|
1730
|
-
const userProfile = await
|
|
1083
|
+
const userProfile = await KeycloakManager.users.create({
|
|
1731
1084
|
username:"username",
|
|
1732
1085
|
email: "test@keycloak.org",
|
|
1733
1086
|
// enabled required to be true in order to send actions email
|
|
@@ -1746,8 +1099,9 @@ sessions, and group/role memberships) are permanently deleted.
|
|
|
1746
1099
|
- id: [Required] the user ID to delete
|
|
1747
1100
|
- realm [Optional] the realm name (defaults to current realm)
|
|
1748
1101
|
```js
|
|
1102
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1749
1103
|
// delete a user
|
|
1750
|
-
const userProfile = await
|
|
1104
|
+
const userProfile = await KeycloakManager.users.del({
|
|
1751
1105
|
id: 'user-Id'
|
|
1752
1106
|
});
|
|
1753
1107
|
```
|
|
@@ -1762,18 +1116,19 @@ Searching by attributes is only available from Keycloak > 15
|
|
|
1762
1116
|
- max: A pagination parameter used to define the maximum number of users to return (limit).
|
|
1763
1117
|
- first: A pagination parameter used to define the number of users to skip before starting to return results (offset/limit).
|
|
1764
1118
|
```js
|
|
1119
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1765
1120
|
// find a user with 'key:value'
|
|
1766
|
-
const user = await
|
|
1121
|
+
const user = await KeycloakManager.users.find({ q: "key:value" });;
|
|
1767
1122
|
if(user) console.log('User found:', user);
|
|
1768
1123
|
else console.log('User not found');
|
|
1769
1124
|
|
|
1770
1125
|
// find a user by name = John
|
|
1771
|
-
user = await
|
|
1126
|
+
user = await KeycloakManager.users.find({ name: "John" });;
|
|
1772
1127
|
if(user) console.log('User found:', user);
|
|
1773
1128
|
else console.log('User not found');
|
|
1774
1129
|
|
|
1775
1130
|
// find a user with 'name:john', skip 10 users and limt to 5
|
|
1776
|
-
const user = await
|
|
1131
|
+
const user = await KeycloakManager.users.find({ q: "name:john", first:11, max:5});;
|
|
1777
1132
|
if(user) console.log('User found:', user);
|
|
1778
1133
|
else console.log('User not found');
|
|
1779
1134
|
```
|
|
@@ -1782,8 +1137,9 @@ else console.log('User not found');
|
|
|
1782
1137
|
findOne is method used to retrieve a specific user's details by their unique identifier (id) within a given realm.
|
|
1783
1138
|
It returns the full user representation if the user exists.
|
|
1784
1139
|
```js
|
|
1140
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1785
1141
|
// find a user with id:'user-id'
|
|
1786
|
-
const user = await
|
|
1142
|
+
const user = await KeycloakManager.users.findOne({ id: 'user-id' });
|
|
1787
1143
|
if(user) console.log('User found:', user);
|
|
1788
1144
|
else console.log('User not found');
|
|
1789
1145
|
```
|
|
@@ -1796,12 +1152,13 @@ Searching by attributes is only available from Keycloak > 15
|
|
|
1796
1152
|
@parameters:
|
|
1797
1153
|
- filter is a JSON object that accepts filter parameters, such as { email: 'test@keycloak.org' }
|
|
1798
1154
|
```js
|
|
1155
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1799
1156
|
// Return the total number of registered users
|
|
1800
|
-
const user_count = await
|
|
1157
|
+
const user_count = await KeycloakManager.users.count();
|
|
1801
1158
|
console.log('User found:', user_count);
|
|
1802
1159
|
|
|
1803
1160
|
// Return the number of users with the name "John"
|
|
1804
|
-
user_count = await
|
|
1161
|
+
user_count = await KeycloakManager.users.count({name:'Jhon'});
|
|
1805
1162
|
console.log('User found:', user_count);
|
|
1806
1163
|
```
|
|
1807
1164
|
|
|
@@ -1816,8 +1173,9 @@ You can modify fields like firstName, lastName, email, enabled, and more.
|
|
|
1816
1173
|
- realm [Optional] the realm name (defaults to current realm)
|
|
1817
1174
|
- userRepresentation: An object containing the user fields to be updated.
|
|
1818
1175
|
```js
|
|
1176
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1819
1177
|
// Update user with id:'user-id'
|
|
1820
|
-
const user_count = await
|
|
1178
|
+
const user_count = await KeycloakManager.users.update({ id: 'user-Id' }, {
|
|
1821
1179
|
firstName: 'John',
|
|
1822
1180
|
lastName: 'Updated',
|
|
1823
1181
|
enabled: true,
|
|
@@ -1838,8 +1196,9 @@ change the password on next login.
|
|
|
1838
1196
|
- value: a String containing new password to be set
|
|
1839
1197
|
|
|
1840
1198
|
```js
|
|
1199
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1841
1200
|
// Update user with id:'user-id'
|
|
1842
|
-
const user = await
|
|
1201
|
+
const user = await KeycloakManager.users.resetPassword({
|
|
1843
1202
|
id: userId,
|
|
1844
1203
|
credential:{
|
|
1845
1204
|
temporary: false,
|
|
@@ -1858,27 +1217,13 @@ or managing credentials such as password reset, WebAuthn deletion, etc.
|
|
|
1858
1217
|
- id: [Required] the user ID to update
|
|
1859
1218
|
- realm [Optional] the realm name (defaults to current realm)
|
|
1860
1219
|
```js
|
|
1220
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1861
1221
|
// get credentials info for user whose id is 'user-id'
|
|
1862
|
-
const ressult = await
|
|
1222
|
+
const ressult = await KeycloakManager.users.getCredentials({id: 'user-id'});
|
|
1863
1223
|
console.log(ressult);
|
|
1864
1224
|
```
|
|
1865
1225
|
|
|
1866
1226
|
|
|
1867
|
-
##### `function getCredentials(filter)`
|
|
1868
|
-
getCredentials() method retrieves the list of credentials (e.g., passwords, OTPs, WebAuthn, etc.)
|
|
1869
|
-
currently associated with a given user in a specific realm.
|
|
1870
|
-
This is useful for auditing, checking what types of credentials a user has set up,
|
|
1871
|
-
or managing credentials such as password reset, WebAuthn deletion, etc.
|
|
1872
|
-
@parameters:
|
|
1873
|
-
- getCredentials: is a JSON object that accepts filter parameters
|
|
1874
|
-
- id: [Required] the user ID to update
|
|
1875
|
-
- realm [Optional] the realm name (defaults to current realm)
|
|
1876
|
-
```js
|
|
1877
|
-
// get credentials info for user whose id is 'user-id'
|
|
1878
|
-
const ressult = await keycloakAdapter.kcAdminClient.users.getCredentials({id: 'user-id'});
|
|
1879
|
-
console.log(ressult);
|
|
1880
|
-
```
|
|
1881
|
-
|
|
1882
1227
|
##### `function deleteCredential(accountInfo)`
|
|
1883
1228
|
deleteCredential method allows you to delete a specific credential (e.g., password, OTP, WebAuthn, etc.) from a user.
|
|
1884
1229
|
This is useful when you want to invalidate or remove a credential, forcing the user to reconfigure or reset it.
|
|
@@ -1887,8 +1232,9 @@ This is useful when you want to invalidate or remove a credential, forcing the u
|
|
|
1887
1232
|
- id: [Required] the user ID to update
|
|
1888
1233
|
- credentialId [Required] the credentils identifier
|
|
1889
1234
|
```js
|
|
1235
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1890
1236
|
// delete credentials info for user whose id is 'user-id'
|
|
1891
|
-
const ressult = await
|
|
1237
|
+
const ressult = await KeycloakManager.users.deleteCredential({
|
|
1892
1238
|
id: 'user-id',
|
|
1893
1239
|
credentialId: credential.id
|
|
1894
1240
|
});
|
|
@@ -1899,8 +1245,9 @@ It is a method that retrieves the user profile dictionary information.
|
|
|
1899
1245
|
This includes basic user details such as username, email, first name, last name,
|
|
1900
1246
|
and other attributes associated with the user profile in the Keycloak realm.
|
|
1901
1247
|
```js
|
|
1902
|
-
|
|
1903
|
-
|
|
1248
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1249
|
+
// Get user profile
|
|
1250
|
+
const userProfile = await KeycloakManager.users.getProfile();
|
|
1904
1251
|
console.log('User profile dicionary:', userProfile);
|
|
1905
1252
|
```
|
|
1906
1253
|
|
|
@@ -1911,8 +1258,9 @@ Adds a user to a specific group within the realm.
|
|
|
1911
1258
|
- id [required]: The user ID of the user you want to add to the group.
|
|
1912
1259
|
- groupId [required]: The group ID of the group the user should be added to.
|
|
1913
1260
|
```js
|
|
1261
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1914
1262
|
// create a role name called my-role
|
|
1915
|
-
const userGroup = await
|
|
1263
|
+
const userGroup = await KeycloakManager.users.addToGroup({
|
|
1916
1264
|
groupId: 'group-id',
|
|
1917
1265
|
id: 'user-id',
|
|
1918
1266
|
});
|
|
@@ -1925,8 +1273,9 @@ Removes a user from a specific group in Keycloak.
|
|
|
1925
1273
|
- id [required]: The user ID of the user you want to remove to the group.
|
|
1926
1274
|
- groupId [required]: The group ID of the group the user should be removed to.
|
|
1927
1275
|
```js
|
|
1276
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1928
1277
|
// create a role name called my-role
|
|
1929
|
-
const userGroup = await
|
|
1278
|
+
const userGroup = await KeycloakManager.users.delFromGroup({
|
|
1930
1279
|
groupId: 'group-id',
|
|
1931
1280
|
id: 'user-id',
|
|
1932
1281
|
});
|
|
@@ -1940,8 +1289,9 @@ Retrieves the number of groups that a given user is a member of.
|
|
|
1940
1289
|
- id: [required] The user ID of the user whose group membership count you want to retrieve.
|
|
1941
1290
|
- search: [optional] a String containing group name such "cool-group",
|
|
1942
1291
|
```js
|
|
1292
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1943
1293
|
// Return the total number of user groups
|
|
1944
|
-
const user_count = await
|
|
1294
|
+
const user_count = await KeycloakManager.users.countGroups({id:'user-id'});
|
|
1945
1295
|
console.log('Groups found:', user_count);
|
|
1946
1296
|
|
|
1947
1297
|
```
|
|
@@ -1952,8 +1302,9 @@ Returns the list of groups that a given user is a member of.
|
|
|
1952
1302
|
- id: [required] The user ID of the user whose group membership you want to retrieve.
|
|
1953
1303
|
- search: [optional] a String containing group name such "cool-group",
|
|
1954
1304
|
```js
|
|
1305
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1955
1306
|
// Return the total number of user groups
|
|
1956
|
-
const user_count = await
|
|
1307
|
+
const user_count = await KeycloakManager.users.listGroups({id:'user-id'});
|
|
1957
1308
|
console.log('Groups found:', user_count);
|
|
1958
1309
|
|
|
1959
1310
|
```
|
|
@@ -1970,8 +1321,9 @@ Returns a promise that resolves when the roles are successfully assigned. No ret
|
|
|
1970
1321
|
- id: [required] The role Id
|
|
1971
1322
|
- name: [required] The role Name
|
|
1972
1323
|
```js
|
|
1324
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1973
1325
|
// Assigns one realm-level role to a user whose ID is 'user-id'.
|
|
1974
|
-
const user_count = await
|
|
1326
|
+
const user_count = await KeycloakManager.users.addRealmRoleMappings({
|
|
1975
1327
|
id: 'user-id',
|
|
1976
1328
|
// at least id and name should appear
|
|
1977
1329
|
roles: [
|
|
@@ -1996,8 +1348,9 @@ This method does not affect composite roles. It only removes directly assigned r
|
|
|
1996
1348
|
- id: [required] The role Id
|
|
1997
1349
|
- name: [required] The role Name
|
|
1998
1350
|
```js
|
|
1351
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
1999
1352
|
// remove one realm-level role to a user whose ID is 'user-id'.
|
|
2000
|
-
const roles_remove = await
|
|
1353
|
+
const roles_remove = await KeycloakManager.users.delRealmRoleMappings({
|
|
2001
1354
|
id: 'user-id',
|
|
2002
1355
|
// at least id and name should appear
|
|
2003
1356
|
roles: [
|
|
@@ -2020,8 +1373,9 @@ These are the roles that exist in the realm but have not yet been mapped to the
|
|
|
2020
1373
|
- filter is a JSON object that accepts this parameters:
|
|
2021
1374
|
- id: [required] The ID of the user for whom to list assignable realm roles.
|
|
2022
1375
|
```js
|
|
1376
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2023
1377
|
// Get assignable realm-level roles for user 'user-id'.
|
|
2024
|
-
const available_roles = await
|
|
1378
|
+
const available_roles = await KeycloakManager.users.listAvailableRealmRoleMappings({
|
|
2025
1379
|
id: 'user-id',
|
|
2026
1380
|
});
|
|
2027
1381
|
console.log('Assignable realm-level roles for user user-id',available_roles);
|
|
@@ -2039,8 +1393,9 @@ Retrieves all realm-level and client-level roles that are currently assigned to
|
|
|
2039
1393
|
- clientMappings: object containing client roles grouped by client.
|
|
2040
1394
|
|
|
2041
1395
|
```js
|
|
1396
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2042
1397
|
// Get assigned roles for user 'user-id'.
|
|
2043
|
-
const roleMappings = await
|
|
1398
|
+
const roleMappings = await KeycloakManager.users.listRoleMappings({
|
|
2044
1399
|
id: 'user-id',
|
|
2045
1400
|
});
|
|
2046
1401
|
console.log(`Realm Roles assigned to user-id:`);
|
|
@@ -2071,8 +1426,9 @@ Unlike listRoleMappings, this method focuses only on realm roles and excludes cl
|
|
|
2071
1426
|
|
|
2072
1427
|
|
|
2073
1428
|
```js
|
|
1429
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2074
1430
|
// Get assigned roles for user 'user-id'.
|
|
2075
|
-
const roleMappings = await
|
|
1431
|
+
const roleMappings = await KeycloakManager.users.listRealmRoleMappings({
|
|
2076
1432
|
id: 'user-id',
|
|
2077
1433
|
});
|
|
2078
1434
|
console.log(`Realm roles assigned to user user-id:`);
|
|
@@ -2094,8 +1450,9 @@ Composite roles include both directly assigned realm roles and any roles inherit
|
|
|
2094
1450
|
|
|
2095
1451
|
|
|
2096
1452
|
```js
|
|
1453
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2097
1454
|
// Get assigned roles for user 'user-id'.
|
|
2098
|
-
const roleMappings = await
|
|
1455
|
+
const roleMappings = await KeycloakManager.users.listCompositeRealmRoleMappings({
|
|
2099
1456
|
id: 'user-id',
|
|
2100
1457
|
});
|
|
2101
1458
|
console.log(`Composite realm roles assigned to user user-id:`);
|
|
@@ -2120,8 +1477,9 @@ allowing the user to have permissions defined by those client roles.
|
|
|
2120
1477
|
- [optional] Other fields
|
|
2121
1478
|
|
|
2122
1479
|
```js
|
|
1480
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2123
1481
|
// Add client roles for user 'user-id'.
|
|
2124
|
-
const roleMappings = await
|
|
1482
|
+
const roleMappings = await KeycloakManager.users.addClientRoleMappings({
|
|
2125
1483
|
id: 'user-id',
|
|
2126
1484
|
clientUniqueId: 'internal-client-id',
|
|
2127
1485
|
|
|
@@ -2143,9 +1501,10 @@ This is useful for determining which roles can still be mapped to the user.
|
|
|
2143
1501
|
- id: [required] The ID of the user
|
|
2144
1502
|
- clientUniqueId:[required] The internal ID of the client (not the clientId string)
|
|
2145
1503
|
```js
|
|
1504
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2146
1505
|
|
|
2147
1506
|
// Get all user 'user-id' available roles for client 'internal-client-id'
|
|
2148
|
-
const availableRoles = await
|
|
1507
|
+
const availableRoles = await KeycloakManager.users.listAvailableClientRoleMappings({
|
|
2149
1508
|
id: 'user-id',
|
|
2150
1509
|
clientUniqueId: 'internal-client-id'
|
|
2151
1510
|
});
|
|
@@ -2164,9 +1523,10 @@ This method returns not only directly assigned roles, but also roles inherited t
|
|
|
2164
1523
|
- id: [required] The ID of the user
|
|
2165
1524
|
- clientUniqueId:[required] The internal ID of the client (not the clientId string)
|
|
2166
1525
|
```js
|
|
1526
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2167
1527
|
|
|
2168
1528
|
// Get all composite roles assigned to a user 'user-id' for client 'internal-client-id'
|
|
2169
|
-
const availableRoles = await
|
|
1529
|
+
const availableRoles = await KeycloakManager.users.listCompositeClientRoleMappings({
|
|
2170
1530
|
id: 'user-id',
|
|
2171
1531
|
clientUniqueId: 'internal-client-id'
|
|
2172
1532
|
});
|
|
@@ -2185,9 +1545,10 @@ assigned to the user from the client, without including roles inherited via comp
|
|
|
2185
1545
|
- id: [required] The ID of the user
|
|
2186
1546
|
- clientUniqueId:[required] The internal ID of the client (not the clientId string)
|
|
2187
1547
|
```js
|
|
1548
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2188
1549
|
|
|
2189
1550
|
// Get all roles assigned to a user 'user-id' for client 'internal-client-id'
|
|
2190
|
-
const availableRoles = await
|
|
1551
|
+
const availableRoles = await KeycloakManager.users.listClientRoleMappings({
|
|
2191
1552
|
id: 'user-id',
|
|
2192
1553
|
clientUniqueId: 'internal-client-id'
|
|
2193
1554
|
});
|
|
@@ -2208,9 +1569,10 @@ This operation unlinks the direct association between the user and the specified
|
|
|
2208
1569
|
- name:[required]: role name
|
|
2209
1570
|
- [optional] Other fields
|
|
2210
1571
|
```js
|
|
1572
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2211
1573
|
|
|
2212
1574
|
// Get all roles assigned to a user 'user-id' for client 'internal-client-id'
|
|
2213
|
-
await
|
|
1575
|
+
await KeycloakManager.users.delClientRoleMappings({
|
|
2214
1576
|
id: 'user-id',
|
|
2215
1577
|
clientUniqueId: 'internal-client-id',
|
|
2216
1578
|
roles: [{
|
|
@@ -2232,9 +1594,10 @@ Each session represents a login session associated with that user across differe
|
|
|
2232
1594
|
- id: [required] The ID of the user whose sessions will be listed.
|
|
2233
1595
|
- clientId: [optional] The internal ID of the client that owns the roles.
|
|
2234
1596
|
```js
|
|
1597
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2235
1598
|
|
|
2236
1599
|
// Get all the user 'user-id' sessions.
|
|
2237
|
-
const sessions=await
|
|
1600
|
+
const sessions=await KeycloakManager.users.listSessions({
|
|
2238
1601
|
id: 'user-id',
|
|
2239
1602
|
});
|
|
2240
1603
|
console.log("User 'user-id' sessions:",sessions);
|
|
@@ -2252,9 +1615,10 @@ without requiring the user to be actively logged in.
|
|
|
2252
1615
|
- id: [required] The ID of the user whose sessions will be listeds
|
|
2253
1616
|
- clientId: [optional] The client ID whose sessions are being checked
|
|
2254
1617
|
```js
|
|
1618
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2255
1619
|
|
|
2256
1620
|
// Get all the user 'user-id' sessions.
|
|
2257
|
-
const sessions=await
|
|
1621
|
+
const sessions=await KeycloakManager.users.listOfflineSessions({
|
|
2258
1622
|
id: 'user-id',
|
|
2259
1623
|
clientId: 'client-id'
|
|
2260
1624
|
});
|
|
@@ -2271,9 +1635,10 @@ This invalidates the user’s active sessions and tokens, effectively logging th
|
|
|
2271
1635
|
- filter is a JSON object that accepts this parameters:
|
|
2272
1636
|
- id: [required] The ID of the user whose sessions will be closed
|
|
2273
1637
|
```js
|
|
1638
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2274
1639
|
|
|
2275
1640
|
// Get all the user 'user-id' sessions.
|
|
2276
|
-
const sessions=await
|
|
1641
|
+
const sessions=await KeycloakManager.users.logout({
|
|
2277
1642
|
id: 'user-id',
|
|
2278
1643
|
});
|
|
2279
1644
|
console.log('All User session closed');
|
|
@@ -2288,9 +1653,10 @@ Each consent represents a client application that the user has authorized to acc
|
|
|
2288
1653
|
- filter is a JSON object that accepts this parameters:
|
|
2289
1654
|
- id: [required] The ID of the user whose client consents can be retrieved.
|
|
2290
1655
|
```js
|
|
1656
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2291
1657
|
|
|
2292
1658
|
// Retrieves the list of OAuth2 client consents that the specified user has granted.
|
|
2293
|
-
const listConsents=await
|
|
1659
|
+
const listConsents=await KeycloakManager.users.listConsents({
|
|
2294
1660
|
id: 'user-id',
|
|
2295
1661
|
});
|
|
2296
1662
|
console.log('All User consents:',listConsents);
|
|
@@ -2309,9 +1675,10 @@ effectively disconnecting the client from the user's account and invalidating as
|
|
|
2309
1675
|
- id: [required] The ID of the user whose consent should be revoked
|
|
2310
1676
|
- clientId: TThe client ID for which the consent should be revoked
|
|
2311
1677
|
```js
|
|
1678
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2312
1679
|
|
|
2313
1680
|
// Retrieves the list of OAuth2 client consents that the specified user has granted.
|
|
2314
|
-
await
|
|
1681
|
+
await KeycloakManager.users.revokeConsent({
|
|
2315
1682
|
id: 'user-id',
|
|
2316
1683
|
clientId: 'client-id',
|
|
2317
1684
|
});
|
|
@@ -2330,9 +1697,10 @@ Returns an object containing a redirect URL or token used to impersonate the use
|
|
|
2330
1697
|
- filter is a JSON object that accepts this parameters:
|
|
2331
1698
|
- id: [required] The ID of the user to impersonate.
|
|
2332
1699
|
```js
|
|
1700
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2333
1701
|
|
|
2334
1702
|
// Impersonate a user whose id is 'user-id'
|
|
2335
|
-
await
|
|
1703
|
+
await KeycloakManager.users.impersonation({id: 'user-id'},{
|
|
2336
1704
|
user: 'user-id',
|
|
2337
1705
|
realm: 'realmeName'
|
|
2338
1706
|
});
|
|
@@ -2348,9 +1716,10 @@ This is useful if the user has linked their account with external providers like
|
|
|
2348
1716
|
- filter is a JSON object that accepts this parameters:
|
|
2349
1717
|
- id: [required] The unique ID of the user for whom you want to fetch the federated identities.
|
|
2350
1718
|
```js
|
|
1719
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2351
1720
|
|
|
2352
1721
|
// This will return a list of all identity providers that the user has linked to their Keycloak account.
|
|
2353
|
-
const federatedIdentities= await
|
|
1722
|
+
const federatedIdentities= await KeycloakManager.users.listFederatedIdentities({id: 'user-id'});
|
|
2354
1723
|
console.log("Federated Identities:", federatedIdentities);
|
|
2355
1724
|
```
|
|
2356
1725
|
|
|
@@ -2369,6 +1738,7 @@ This is typically used to associate a federated identity (such as a Google or Fa
|
|
|
2369
1738
|
- userId: [required] The ID of the user in the external identity provider.
|
|
2370
1739
|
- userName: [required] The username in the external identity provider.
|
|
2371
1740
|
```js
|
|
1741
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2372
1742
|
|
|
2373
1743
|
// Add user whose id is 'user-id' to a deferated 'federatedIdentity-Id'
|
|
2374
1744
|
const federatedIdentity = {
|
|
@@ -2376,7 +1746,7 @@ This is typically used to associate a federated identity (such as a Google or Fa
|
|
|
2376
1746
|
userId: "user-id",
|
|
2377
1747
|
userName: "username",
|
|
2378
1748
|
};
|
|
2379
|
-
await
|
|
1749
|
+
await KeycloakManager.users.addToFederatedIdentity({
|
|
2380
1750
|
id: 'user-id',
|
|
2381
1751
|
federatedIdentityId: "federatedIdentity-Id",
|
|
2382
1752
|
federatedIdentity:federatedIdentity,
|
|
@@ -2394,9 +1764,10 @@ This operation dissociates the external identity (e.g., a Google or Facebook acc
|
|
|
2394
1764
|
- id: [required] The ID of the Keycloak user from whom the federated identity should be removed.
|
|
2395
1765
|
- federatedIdentityId: [required] The alias of the identity provider (e.g., "google" or "facebook").
|
|
2396
1766
|
```js
|
|
1767
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2397
1768
|
|
|
2398
1769
|
// Remove a user whose id is 'user-id' from federated 'federatedIdentity-Id'
|
|
2399
|
-
await
|
|
1770
|
+
await KeycloakManager.users.delFromFederatedIdentity({
|
|
2400
1771
|
id: 'user-id',
|
|
2401
1772
|
federatedIdentityId: "federatedIdentity-Id",
|
|
2402
1773
|
});
|
|
@@ -2434,8 +1805,9 @@ Creates a new client with the provided configuration
|
|
|
2434
1805
|
- ....[optional] Other client fields
|
|
2435
1806
|
|
|
2436
1807
|
```js
|
|
1808
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2437
1809
|
// create a client called my-client
|
|
2438
|
-
const client= await
|
|
1810
|
+
const client= await KeycloakManager.clients.create({name: "my-client", id:"client-id"});
|
|
2439
1811
|
console.log("New Client Created:", client);
|
|
2440
1812
|
```
|
|
2441
1813
|
|
|
@@ -2451,8 +1823,9 @@ for a specific one using filters like clientId.
|
|
|
2451
1823
|
- first:[optional] Pagination: index of the first result to return.
|
|
2452
1824
|
- max:[optional] Pagination: maximum number of results to return.
|
|
2453
1825
|
```js
|
|
1826
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2454
1827
|
// Get client by ID: 'client-id'
|
|
2455
|
-
const clients= await
|
|
1828
|
+
const clients= await KeycloakManager.clients.find({ clientId:"client-id"});
|
|
2456
1829
|
console.log("Clients:", clients);
|
|
2457
1830
|
```
|
|
2458
1831
|
|
|
@@ -2463,8 +1836,9 @@ This method fetches the client’s configuration, including its settings, roles,
|
|
|
2463
1836
|
- filter: A JSON structure used to filter results based on specific fields:
|
|
2464
1837
|
- id: [optional] The unique identifier of the client to retrieve
|
|
2465
1838
|
```js
|
|
1839
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2466
1840
|
// Get client by ID: 'client-id'
|
|
2467
|
-
const clients= await
|
|
1841
|
+
const clients= await KeycloakManager.clients.findOne({ id:"client-id"});
|
|
2468
1842
|
console.log("Clients:", clients);
|
|
2469
1843
|
```
|
|
2470
1844
|
|
|
@@ -2476,8 +1850,9 @@ This operation is irreversible and will remove the client and all its associated
|
|
|
2476
1850
|
- filter: A JSON structure used to filter results based on specific fields:
|
|
2477
1851
|
- id: [required] The internal ID of the client to delete (not clientId)
|
|
2478
1852
|
```js
|
|
1853
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2479
1854
|
// delete client by ID: 'internal-client-id'
|
|
2480
|
-
const clients= await
|
|
1855
|
+
const clients= await KeycloakManager.clients.del({ id:"internal-client-id"});
|
|
2481
1856
|
console.log(`Client successfully deleted.`);
|
|
2482
1857
|
```
|
|
2483
1858
|
|
|
@@ -2490,8 +1865,9 @@ You can modify various attributes such as the client name, redirect URIs, protoc
|
|
|
2490
1865
|
- id: [required] The unique ID of the client you want to update
|
|
2491
1866
|
- clientRepresentation: [required] The new configuration for the client
|
|
2492
1867
|
```js
|
|
1868
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2493
1869
|
// update single client
|
|
2494
|
-
await
|
|
1870
|
+
await KeycloakManager.clients.update(
|
|
2495
1871
|
{ id:"internal-client-id"},
|
|
2496
1872
|
{
|
|
2497
1873
|
// clientId is required in client update
|
|
@@ -2516,8 +1892,9 @@ for fine-grained access control within that client.
|
|
|
2516
1892
|
- description: [optional] Optional description of the role.
|
|
2517
1893
|
- [optional] Other role fields
|
|
2518
1894
|
```js
|
|
1895
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2519
1896
|
// Creates a new client role under a specific client.
|
|
2520
|
-
const role= await
|
|
1897
|
+
const role= await KeycloakManager.clients.createRole({
|
|
2521
1898
|
id: 'client-id',
|
|
2522
1899
|
name: 'roleName'
|
|
2523
1900
|
});
|
|
@@ -2536,8 +1913,9 @@ This is useful when you want to inspect or verify the properties of a role defin
|
|
|
2536
1913
|
- roleName: [required] The name of the client role you want to find.
|
|
2537
1914
|
|
|
2538
1915
|
```js
|
|
1916
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2539
1917
|
// Get client role by ID: 'internal-client-id'
|
|
2540
|
-
const role= await
|
|
1918
|
+
const role= await KeycloakManager.clients.findRole({
|
|
2541
1919
|
id: 'internal-client-id',
|
|
2542
1920
|
roleName:'roleName'
|
|
2543
1921
|
});
|
|
@@ -2554,8 +1932,9 @@ This includes changing the role's name, description, or any associated metadata.
|
|
|
2554
1932
|
- roleName: [required] The name of the client role you want to update
|
|
2555
1933
|
- roleRepresentation: [required] An object with the updated properties of the role
|
|
2556
1934
|
```js
|
|
1935
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2557
1936
|
// update the client role
|
|
2558
|
-
await
|
|
1937
|
+
await KeycloakManager.clients.updateRole(
|
|
2559
1938
|
{ id: 'internal-client-id', roleName:'roleName'},
|
|
2560
1939
|
{
|
|
2561
1940
|
name: 'newName',
|
|
@@ -2577,8 +1956,9 @@ If the role does not exist or the operation fails, an error will be thrown.
|
|
|
2577
1956
|
- roleName: [required] The name of the client role you want to delete.
|
|
2578
1957
|
|
|
2579
1958
|
```js
|
|
1959
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2580
1960
|
// delere client role by ID: 'internal-client-id'
|
|
2581
|
-
const role= await
|
|
1961
|
+
const role= await KeycloakManager.clients.delRole({
|
|
2582
1962
|
id: 'internal-client-id',
|
|
2583
1963
|
roleName:'roleName'
|
|
2584
1964
|
});
|
|
@@ -2593,8 +1973,9 @@ These roles can be used to assign permissions to users or groups for the specifi
|
|
|
2593
1973
|
- id: [required] The internal ID of the client (not clientId)
|
|
2594
1974
|
|
|
2595
1975
|
```js
|
|
1976
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2596
1977
|
// list the client role
|
|
2597
|
-
const roles= await
|
|
1978
|
+
const roles= await KeycloakManager.clients.listRoles({
|
|
2598
1979
|
id: 'internal-client-id'
|
|
2599
1980
|
});
|
|
2600
1981
|
console.log("Client roles:", roles);
|
|
@@ -2609,8 +1990,9 @@ This is typically used for clients using client_credentials or authorization_cod
|
|
|
2609
1990
|
- id: [required] The internal ID of the client (not clientId)
|
|
2610
1991
|
|
|
2611
1992
|
```js
|
|
1993
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2612
1994
|
// get client secret
|
|
2613
|
-
const secret= await
|
|
1995
|
+
const secret= await KeycloakManager.clients.getClientSecret({
|
|
2614
1996
|
id: 'internal-client-id'
|
|
2615
1997
|
});
|
|
2616
1998
|
console.log("Client secret:", secret);
|
|
@@ -2626,8 +2008,9 @@ It is useful when rotating credentials or recovering access.
|
|
|
2626
2008
|
- id: [required] The internal ID of the client (not clientId)
|
|
2627
2009
|
|
|
2628
2010
|
```js
|
|
2011
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2629
2012
|
// generate new client secret
|
|
2630
|
-
const secret= await
|
|
2013
|
+
const secret= await KeycloakManager.clients.generateNewClientSecret({
|
|
2631
2014
|
id: 'internal-client-id'
|
|
2632
2015
|
});
|
|
2633
2016
|
|
|
@@ -2643,8 +2026,9 @@ It’s particularly useful in dynamic client registration workflows or when auto
|
|
|
2643
2026
|
- id: [required] The internal ID of the client (not clientId)
|
|
2644
2027
|
|
|
2645
2028
|
```js
|
|
2029
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2646
2030
|
// generate new registration access token
|
|
2647
|
-
const result= await
|
|
2031
|
+
const result= await KeycloakManager.clients.generateRegistrationAccessToken({
|
|
2648
2032
|
id: 'internal-client-id'
|
|
2649
2033
|
});
|
|
2650
2034
|
|
|
@@ -2661,8 +2045,9 @@ After invalidation, the client will no longer be able to authenticate using the
|
|
|
2661
2045
|
- id: [required] The internal ID of the client (not clientId)
|
|
2662
2046
|
|
|
2663
2047
|
```js
|
|
2048
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2664
2049
|
// invalidate rotation token
|
|
2665
|
-
await
|
|
2050
|
+
await KeycloakManager.clients.invalidateSecret({
|
|
2666
2051
|
id: 'internal-client-id'
|
|
2667
2052
|
});
|
|
2668
2053
|
console.log("Client secret invalidated successfully.");
|
|
@@ -2681,8 +2066,9 @@ for example as a JSON file, Keycloak XML adapter config, or other formats suppor
|
|
|
2681
2066
|
|
|
2682
2067
|
Return an array of installation provider objects, each representing a supported installation format for the client.
|
|
2683
2068
|
```js
|
|
2069
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2684
2070
|
// get installation providers
|
|
2685
|
-
const providers = await
|
|
2071
|
+
const providers = await KeycloakManager.clients.getInstallationProviders({
|
|
2686
2072
|
id: 'internal-client-id'
|
|
2687
2073
|
});
|
|
2688
2074
|
console.log("Available installation providers:", providers);
|
|
@@ -2699,8 +2085,9 @@ This method allows you to see which policy types are supported and available to
|
|
|
2699
2085
|
- id: [required] The ID of the client (resource server) for which to list available policy providers.
|
|
2700
2086
|
|
|
2701
2087
|
```js
|
|
2088
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2702
2089
|
// get installation providers
|
|
2703
|
-
const providers = await
|
|
2090
|
+
const providers = await KeycloakManager.clients.listPolicyProviders({
|
|
2704
2091
|
id: 'internal-client-id'
|
|
2705
2092
|
});
|
|
2706
2093
|
console.log("Available policy providers:", providers);
|
|
@@ -2720,8 +2107,9 @@ which can be used for token-based access and permissions management.
|
|
|
2720
2107
|
Return an object representing the user linked to the client's service account,
|
|
2721
2108
|
including details such as user ID, username, email, and other user attributes.
|
|
2722
2109
|
```js
|
|
2110
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2723
2111
|
// get service account user
|
|
2724
|
-
const serviceAccountUser = await
|
|
2112
|
+
const serviceAccountUser = await KeycloakManager.clients.getServiceAccountUser({
|
|
2725
2113
|
id: 'internal-client-id'
|
|
2726
2114
|
});
|
|
2727
2115
|
console.log("Service Account User:", serviceAccountUser);
|
|
@@ -2738,8 +2126,9 @@ Default scopes are automatically included in tokens issued to the client.
|
|
|
2738
2126
|
- clientScopeId: [required] The ID of the client scope you want to add as a default scope.
|
|
2739
2127
|
|
|
2740
2128
|
```js
|
|
2129
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2741
2130
|
// add default client scope
|
|
2742
|
-
await
|
|
2131
|
+
await KeycloakManager.clients.addDefaultClientScope({
|
|
2743
2132
|
id: 'internal-client-id',
|
|
2744
2133
|
clientScopeId:'client-scope-id'
|
|
2745
2134
|
});
|
|
@@ -2756,8 +2145,9 @@ Default scopes are automatically assigned to tokens issued for the client.
|
|
|
2756
2145
|
- clientScopeId: [required] The ID of the client scope to be removed.
|
|
2757
2146
|
|
|
2758
2147
|
```js
|
|
2148
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2759
2149
|
// cleanup default scopes
|
|
2760
|
-
await
|
|
2150
|
+
await KeycloakManager.clients.delDefaultClientScope({
|
|
2761
2151
|
id: 'internal-client-id',
|
|
2762
2152
|
clientScopeId:'client-scope-id'
|
|
2763
2153
|
});
|
|
@@ -2773,8 +2163,9 @@ Optional client scopes are those that are not automatically assigned to clients
|
|
|
2773
2163
|
- clientScopeId: [required] The ID of the client scope you want to unlink from the client.
|
|
2774
2164
|
|
|
2775
2165
|
```js
|
|
2166
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2776
2167
|
// cleanup default scopes
|
|
2777
|
-
await
|
|
2168
|
+
await KeycloakManager.clients.delOptionalClientScope({
|
|
2778
2169
|
id: 'internal-client-id',
|
|
2779
2170
|
clientScopeId:'client-scope-id'
|
|
2780
2171
|
});
|
|
@@ -2790,8 +2181,9 @@ Default client scopes are automatically assigned to a client during token reques
|
|
|
2790
2181
|
- id: [required] The client ID of the client whose default client scopes you want to list.
|
|
2791
2182
|
|
|
2792
2183
|
```js
|
|
2184
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2793
2185
|
// list default client scopes
|
|
2794
|
-
const defaultScopes = await
|
|
2186
|
+
const defaultScopes = await KeycloakManager.clients.listDefaultClientScopes({
|
|
2795
2187
|
id: 'internal-client-id',
|
|
2796
2188
|
});
|
|
2797
2189
|
console.log("Default Clients Scopes:",defaultScopes);
|
|
@@ -2809,8 +2201,9 @@ Optional scopes are those that a client can request explicitly but are not autom
|
|
|
2809
2201
|
- id: [required] The client ID of the client whose optional client scopes you want to list.
|
|
2810
2202
|
|
|
2811
2203
|
```js
|
|
2204
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2812
2205
|
// list optional client scopes
|
|
2813
|
-
const optionalScopes = await
|
|
2206
|
+
const optionalScopes = await KeycloakManager.clients.listOptionalClientScopes({
|
|
2814
2207
|
id: 'internal-client-id',
|
|
2815
2208
|
});
|
|
2816
2209
|
console.log("Optional Clients Scopes:",optionalScopes);
|
|
@@ -2827,8 +2220,9 @@ Optional scopes are not automatically applied during login unless explicitly req
|
|
|
2827
2220
|
- clientScopeId: [required] The ID of the client scope you want to assign as optional.
|
|
2828
2221
|
|
|
2829
2222
|
```js
|
|
2223
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2830
2224
|
// add optional client scope
|
|
2831
|
-
await
|
|
2225
|
+
await KeycloakManager.clients.addOptionalClientScope({
|
|
2832
2226
|
id: 'internal-client-id',
|
|
2833
2227
|
clientScopeId: 'scope-id',
|
|
2834
2228
|
});
|
|
@@ -2844,9 +2238,10 @@ This includes realm-level roles and client-level roles that are mapped to the cl
|
|
|
2844
2238
|
- id: [required] The ID of the client whose scope mappings you want to list.
|
|
2845
2239
|
|
|
2846
2240
|
```js
|
|
2241
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2847
2242
|
|
|
2848
2243
|
// get 'internal-client-id' scope mapping
|
|
2849
|
-
const scopeMappings = await
|
|
2244
|
+
const scopeMappings = await KeycloakManager.clients.listScopeMappings({
|
|
2850
2245
|
id: 'internal-client-id'
|
|
2851
2246
|
});
|
|
2852
2247
|
|
|
@@ -2866,9 +2261,10 @@ This helps you discover which client roles you can still add as scope mappings.
|
|
|
2866
2261
|
- client: [required] The client ID of the source client (the one that owns the roles to be mapped).
|
|
2867
2262
|
|
|
2868
2263
|
```js
|
|
2264
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2869
2265
|
|
|
2870
2266
|
// get 'internal-client-id' available roles to be mapped
|
|
2871
|
-
const availableRoles = await
|
|
2267
|
+
const availableRoles = await KeycloakManager.clients.listAvailableClientScopeMappings({
|
|
2872
2268
|
id: 'internal-client-id',
|
|
2873
2269
|
client: 'internal-client-id',
|
|
2874
2270
|
});
|
|
@@ -2892,9 +2288,10 @@ This means the target client will inherit these roles when requesting tokens.
|
|
|
2892
2288
|
|
|
2893
2289
|
|
|
2894
2290
|
```js
|
|
2291
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2895
2292
|
|
|
2896
2293
|
// map available roles
|
|
2897
|
-
await
|
|
2294
|
+
await KeycloakManager.clients.addClientScopeMappings({
|
|
2898
2295
|
id: 'internal-client-id', // Target client
|
|
2899
2296
|
client: "my-source-client-id", // Source client
|
|
2900
2297
|
},
|
|
@@ -2925,9 +2322,10 @@ It shows which roles from another client (source) are already mapped to the targ
|
|
|
2925
2322
|
|
|
2926
2323
|
|
|
2927
2324
|
```js
|
|
2325
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2928
2326
|
|
|
2929
2327
|
// list assigned role mappings
|
|
2930
|
-
const assignedRoles = await
|
|
2328
|
+
const assignedRoles = await KeycloakManager.clients.listClientScopeMappings({
|
|
2931
2329
|
id: 'internal-client-id', // Target client
|
|
2932
2330
|
client: "my-source-client", // Source client
|
|
2933
2331
|
});
|
|
@@ -2945,9 +2343,10 @@ It differs from listClientScopeMappings because it expands composite roles and s
|
|
|
2945
2343
|
- client: [required] The ID of the source client (the one that owns the roles)
|
|
2946
2344
|
|
|
2947
2345
|
```js
|
|
2346
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2948
2347
|
|
|
2949
2348
|
// list effective (composite) role mappings
|
|
2950
|
-
const effectiveRoles = await
|
|
2349
|
+
const effectiveRoles = await KeycloakManager.clients.listCompositeClientScopeMappings({
|
|
2951
2350
|
id: 'internal-client-id', // Target client
|
|
2952
2351
|
client: "my-source-client", // Source client
|
|
2953
2352
|
});
|
|
@@ -2971,9 +2370,10 @@ It is the reverse of clients.addClientScopeMappings
|
|
|
2971
2370
|
|
|
2972
2371
|
|
|
2973
2372
|
```js
|
|
2373
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2974
2374
|
|
|
2975
2375
|
// Rremove roles from client mappings
|
|
2976
|
-
await
|
|
2376
|
+
await KeycloakManager.clients.delClientScopeMappings({
|
|
2977
2377
|
id: 'internal-client-id', // Target client
|
|
2978
2378
|
client: "my-source-client", // Source client
|
|
2979
2379
|
roles: [
|
|
@@ -2996,9 +2396,10 @@ These are roles defined at the realm level that the client does not yet have map
|
|
|
2996
2396
|
- id: [required] The ID of the client for which you want to list available realm-level role mappings.
|
|
2997
2397
|
|
|
2998
2398
|
```js
|
|
2399
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
2999
2400
|
|
|
3000
2401
|
// Get available realm roles for client
|
|
3001
|
-
const availableRealmRoles = await
|
|
2402
|
+
const availableRealmRoles = await KeycloakManager.clients.listAvailableRealmScopeMappings({
|
|
3002
2403
|
id: 'internal-client-id',
|
|
3003
2404
|
});
|
|
3004
2405
|
|
|
@@ -3014,9 +2415,10 @@ These are roles defined at the realm level that the client does not yet have map
|
|
|
3014
2415
|
- id: [required] The ID of the client for which you want to list available realm-level role mappings.
|
|
3015
2416
|
|
|
3016
2417
|
```js
|
|
2418
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3017
2419
|
|
|
3018
2420
|
// Get available realm roles for client
|
|
3019
|
-
const availableRealmRoles = await
|
|
2421
|
+
const availableRealmRoles = await KeycloakManager.clients.listAvailableRealmScopeMappings({
|
|
3020
2422
|
id: 'internal-client-id',
|
|
3021
2423
|
});
|
|
3022
2424
|
|
|
@@ -3033,9 +2435,10 @@ This shows which realm roles the client is allowed to request on behalf of users
|
|
|
3033
2435
|
- id: [required] The client ID whose realm-level scope mappings you want to list
|
|
3034
2436
|
|
|
3035
2437
|
```js
|
|
2438
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3036
2439
|
|
|
3037
2440
|
// Get mapped realm roles for client
|
|
3038
|
-
const roles = await
|
|
2441
|
+
const roles = await KeycloakManager.clients.listRealmScopeMappings({
|
|
3039
2442
|
id: 'internal-client-id',
|
|
3040
2443
|
});
|
|
3041
2444
|
|
|
@@ -3051,9 +2454,10 @@ This includes not only the roles directly mapped to the client, but also roles i
|
|
|
3051
2454
|
- id: [required] The client ID whose composite realm scope mappings you want to list
|
|
3052
2455
|
|
|
3053
2456
|
```js
|
|
2457
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3054
2458
|
|
|
3055
2459
|
// Get mapped realm composite roles for client
|
|
3056
|
-
const roles = await
|
|
2460
|
+
const roles = await KeycloakManager.clients.listCompositeRealmScopeMappings({
|
|
3057
2461
|
id: 'internal-client-id',
|
|
3058
2462
|
});
|
|
3059
2463
|
|
|
@@ -3071,9 +2475,10 @@ This effectively grants the client access to the specified realm roles.
|
|
|
3071
2475
|
- roles: [required] An array of realm roles to be mapped to the client. Each role object typically contains at least id and name
|
|
3072
2476
|
|
|
3073
2477
|
```js
|
|
2478
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3074
2479
|
|
|
3075
2480
|
// Add Realm scope mappings
|
|
3076
|
-
await
|
|
2481
|
+
await KeycloakManager.clients.addRealmScopeMappings(
|
|
3077
2482
|
{id:'internal-client-id'},
|
|
3078
2483
|
[{id:'role1_id'},{id:'role1_id'}]
|
|
3079
2484
|
);
|
|
@@ -3089,9 +2494,10 @@ This is the opposite of clients.addRealmScopeMappings.
|
|
|
3089
2494
|
- roles: [required] An array of role objects you want to remove. Each role object must at least contain the id or name field.
|
|
3090
2495
|
|
|
3091
2496
|
```js
|
|
2497
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3092
2498
|
|
|
3093
2499
|
// remove Realm scope mappings
|
|
3094
|
-
await
|
|
2500
|
+
await KeycloakManager.clients.delRealmScopeMappings(
|
|
3095
2501
|
{id:'internal-client-id'},
|
|
3096
2502
|
[{id:'role1_id'},{id:'role1_id'}]
|
|
3097
2503
|
);
|
|
@@ -3107,9 +2513,10 @@ The method retrieves active user sessions for a specific client.
|
|
|
3107
2513
|
- max: [optional] pagination field. Maximum number of results.
|
|
3108
2514
|
|
|
3109
2515
|
```js
|
|
2516
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3110
2517
|
|
|
3111
2518
|
// get client sessions
|
|
3112
|
-
const sessions = await
|
|
2519
|
+
const sessions = await KeycloakManager.clients.listSessions({
|
|
3113
2520
|
id: 'internal-client-id',
|
|
3114
2521
|
first: 0,
|
|
3115
2522
|
max: 20,
|
|
@@ -3133,9 +2540,10 @@ Offline sessions are created when a client uses offline tokens (refresh tokens w
|
|
|
3133
2540
|
- max: [optional] pagination field. Maximum number of results.
|
|
3134
2541
|
|
|
3135
2542
|
```js
|
|
2543
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3136
2544
|
|
|
3137
2545
|
// get offline sessions
|
|
3138
|
-
const sessions = await
|
|
2546
|
+
const sessions = await KeycloakManager.clients.listOfflineSessions({
|
|
3139
2547
|
id: 'internal-client-id',
|
|
3140
2548
|
first: 0,
|
|
3141
2549
|
max: 20,
|
|
@@ -3156,9 +2564,10 @@ This includes online sessions, not offline sessions (those are retrieved with li
|
|
|
3156
2564
|
- id: [required] The client ID whose session must be retrieved
|
|
3157
2565
|
|
|
3158
2566
|
```js
|
|
2567
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3159
2568
|
|
|
3160
2569
|
// count active sessions
|
|
3161
|
-
const sessionCount = await
|
|
2570
|
+
const sessionCount = await KeycloakManager.clients.getSessionCount({
|
|
3162
2571
|
id: 'internal-client-id'
|
|
3163
2572
|
});
|
|
3164
2573
|
|
|
@@ -3175,9 +2584,10 @@ without requiring active login.
|
|
|
3175
2584
|
- id: [required] The ID of the client for which you want to count offline sessions.
|
|
3176
2585
|
|
|
3177
2586
|
```js
|
|
2587
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3178
2588
|
|
|
3179
2589
|
// count active sessions
|
|
3180
|
-
const sessionCount = await
|
|
2590
|
+
const sessionCount = await KeycloakManager.clients.getOfflineSessionCount({
|
|
3181
2591
|
id: 'internal-client-id'
|
|
3182
2592
|
});
|
|
3183
2593
|
|
|
@@ -3194,9 +2604,10 @@ client sessions and node information across multiple instances.
|
|
|
3194
2604
|
- id: [required] The ID of the client for which you want to add a cluster node.
|
|
3195
2605
|
- node: [required] The name or identifier of the cluster node to register.
|
|
3196
2606
|
```js
|
|
2607
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3197
2608
|
|
|
3198
2609
|
// Add Cluster Node
|
|
3199
|
-
await
|
|
2610
|
+
await KeycloakManager.clients.addClusterNode({
|
|
3200
2611
|
id: 'internal-client-id',
|
|
3201
2612
|
node:'127.0.0.1'
|
|
3202
2613
|
});
|
|
@@ -3214,9 +2625,10 @@ client session synchronization.
|
|
|
3214
2625
|
- id: [required] The ID of the client for which you want to remove a cluster node.
|
|
3215
2626
|
- node: [required] The name or identifier of the cluster node to remove.
|
|
3216
2627
|
```js
|
|
2628
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3217
2629
|
|
|
3218
2630
|
// Add Cluster Node
|
|
3219
|
-
await
|
|
2631
|
+
await KeycloakManager.clients.deleteClusterNode({
|
|
3220
2632
|
id: 'internal-client-id',
|
|
3221
2633
|
node:'127.0.0.1'
|
|
3222
2634
|
});
|
|
@@ -3240,6 +2652,7 @@ This is typically used for clients that require client credentials, JWT signing,
|
|
|
3240
2652
|
- realmCertificate: [optional] Indicates whether the realm certificate should be added to the keystore. Set to true to include it
|
|
3241
2653
|
|
|
3242
2654
|
```js
|
|
2655
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3243
2656
|
|
|
3244
2657
|
// set Configuration
|
|
3245
2658
|
const keystoreConfig = {
|
|
@@ -3253,7 +2666,7 @@ const keystoreConfig = {
|
|
|
3253
2666
|
const attr = "jwt.credential";
|
|
3254
2667
|
|
|
3255
2668
|
// Generate and download Key
|
|
3256
|
-
const result = await
|
|
2669
|
+
const result = await KeycloakManager.clients.generateAndDownloadKey(
|
|
3257
2670
|
{ id: internal-client-id, attr },
|
|
3258
2671
|
keystoreConfig,
|
|
3259
2672
|
);
|
|
@@ -3276,11 +2689,12 @@ Unlike clients.generateAndDownloadKey, this method only generates the key and st
|
|
|
3276
2689
|
- attr: [required] The name of the client attribute where the generated key will be saved
|
|
3277
2690
|
|
|
3278
2691
|
```js
|
|
2692
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3279
2693
|
|
|
3280
2694
|
const attr = "jwt.credential";
|
|
3281
2695
|
|
|
3282
2696
|
// Generate a Key
|
|
3283
|
-
const result = await
|
|
2697
|
+
const result = await KeycloakManager.clients.generateKey(
|
|
3284
2698
|
{ id: internal-client-id, attr }
|
|
3285
2699
|
);
|
|
3286
2700
|
|
|
@@ -3300,11 +2714,12 @@ It does not return the actual key material but provides information such as the
|
|
|
3300
2714
|
- attr: [optional] The name of the client attribute to get
|
|
3301
2715
|
|
|
3302
2716
|
```js
|
|
2717
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3303
2718
|
|
|
3304
2719
|
const attr = "jwt.credential";
|
|
3305
2720
|
|
|
3306
2721
|
// Get Key Info
|
|
3307
|
-
const keyInfo = await
|
|
2722
|
+
const keyInfo = await KeycloakManager.clients.getKeyInfo(
|
|
3308
2723
|
{ id: internal-client-id, attr }
|
|
3309
2724
|
);
|
|
3310
2725
|
|
|
@@ -3335,6 +2750,7 @@ This is typically used when you need to retrieve the public certificate of a cli
|
|
|
3335
2750
|
|
|
3336
2751
|
|
|
3337
2752
|
```js
|
|
2753
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3338
2754
|
|
|
3339
2755
|
// set Configuration
|
|
3340
2756
|
const keystoreConfig = {
|
|
@@ -3349,7 +2765,7 @@ const keystoreConfig = {
|
|
|
3349
2765
|
const attr = "jwt.credential";
|
|
3350
2766
|
|
|
3351
2767
|
// Generate and Key
|
|
3352
|
-
const cert = await
|
|
2768
|
+
const cert = await KeycloakManager.clients.downloadKey(
|
|
3353
2769
|
{ id: internal-client-id, attr },
|
|
3354
2770
|
keystoreConfig
|
|
3355
2771
|
);
|
|
@@ -3377,9 +2793,10 @@ that can later be linked to resources and policies.
|
|
|
3377
2793
|
- ... other scope representation fields
|
|
3378
2794
|
|
|
3379
2795
|
```js
|
|
2796
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3380
2797
|
|
|
3381
2798
|
// createAuthorizationScope
|
|
3382
|
-
await
|
|
2799
|
+
await KeycloakManager.clients.createAuthorizationScope(
|
|
3383
2800
|
{ id: 'internal-client-id' },
|
|
3384
2801
|
{
|
|
3385
2802
|
name: "manage-orders",
|
|
@@ -3399,9 +2816,10 @@ This includes both default scopes and optional scopes that can be assigned to th
|
|
|
3399
2816
|
|
|
3400
2817
|
|
|
3401
2818
|
```js
|
|
2819
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3402
2820
|
|
|
3403
2821
|
// Get scopes
|
|
3404
|
-
const scopes= await
|
|
2822
|
+
const scopes= await KeycloakManager.clients.listAllScopes({
|
|
3405
2823
|
id: 'internal-client-id'
|
|
3406
2824
|
});
|
|
3407
2825
|
|
|
@@ -3423,9 +2841,10 @@ Authorization scopes define permissions that can be used in policies and permiss
|
|
|
3423
2841
|
- .. other attributes: Additional attributes for the scope.
|
|
3424
2842
|
|
|
3425
2843
|
```js
|
|
2844
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3426
2845
|
|
|
3427
2846
|
// Update the scope-id authorization scope
|
|
3428
|
-
const scopes= await
|
|
2847
|
+
const scopes= await KeycloakManager.clients.updateAuthorizationScope(
|
|
3429
2848
|
{
|
|
3430
2849
|
id: 'internal-client-id',
|
|
3431
2850
|
scopeId: 'scope-id'
|
|
@@ -3451,9 +2870,10 @@ Authorization scopes define permissions that can be applied to resources and pol
|
|
|
3451
2870
|
- scopeId [required] The ID of the authorization scope to retrieve
|
|
3452
2871
|
|
|
3453
2872
|
```js
|
|
2873
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3454
2874
|
|
|
3455
2875
|
// get scope-id authorization scope
|
|
3456
|
-
const scope= await
|
|
2876
|
+
const scope= await KeycloakManager.clients.getAuthorizationScope({
|
|
3457
2877
|
id: 'internal-client-id',
|
|
3458
2878
|
scopeId: 'scope-id'
|
|
3459
2879
|
});
|
|
@@ -3471,9 +2891,10 @@ This allows you to see which resources are governed by a particular scope in the
|
|
|
3471
2891
|
- scopeId [required] The ID of the authorization scope whose associated resources you want to list.
|
|
3472
2892
|
|
|
3473
2893
|
```js
|
|
2894
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3474
2895
|
|
|
3475
2896
|
// List all resources by scope
|
|
3476
|
-
const resources= await
|
|
2897
|
+
const resources= await KeycloakManager.clients.listAllResourcesByScope({
|
|
3477
2898
|
id: 'internal-client-id',
|
|
3478
2899
|
scopeId: 'scope-id'
|
|
3479
2900
|
});
|
|
@@ -3492,9 +2913,10 @@ This is helpful for understanding which permissions (policies and rules) are app
|
|
|
3492
2913
|
- scopeId [required] The ID of the authorization scope whose associated permissions you want to list
|
|
3493
2914
|
|
|
3494
2915
|
```js
|
|
2916
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3495
2917
|
|
|
3496
2918
|
// list all permissions by scope
|
|
3497
|
-
const permissions= await
|
|
2919
|
+
const permissions= await KeycloakManager.clients.listAllPermissionsByScope({
|
|
3498
2920
|
id: 'internal-client-id',
|
|
3499
2921
|
scopeId: 'scope-id'
|
|
3500
2922
|
});
|
|
@@ -3517,9 +2939,10 @@ in Keycloak’s Authorization Services (UMA 2.0) framework.
|
|
|
3517
2939
|
- name: [optional] The name of the permission whose scopes should be retrieved
|
|
3518
2940
|
|
|
3519
2941
|
```js
|
|
2942
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3520
2943
|
|
|
3521
2944
|
// List permission scope
|
|
3522
|
-
const permissionScopes= await
|
|
2945
|
+
const permissionScopes= await KeycloakManager.clients.listPermissionScope({
|
|
3523
2946
|
id: 'internal-client-id',
|
|
3524
2947
|
name: "scope",
|
|
3525
2948
|
});
|
|
@@ -3541,9 +2964,10 @@ resources that a client can protect with policies and permissions.
|
|
|
3541
2964
|
- resource [required] The resource representation object. This typically includes attributes like name, uris, type, scopes, and other Keycloak resource configuration options.
|
|
3542
2965
|
|
|
3543
2966
|
```js
|
|
2967
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3544
2968
|
|
|
3545
2969
|
// import resource
|
|
3546
|
-
await
|
|
2970
|
+
await KeycloakManager.clients.importResource(
|
|
3547
2971
|
{
|
|
3548
2972
|
id: 'internal-client-id'
|
|
3549
2973
|
},
|
|
@@ -3573,9 +2997,10 @@ and associated permissions, which can then be backed up, replicated, or modified
|
|
|
3573
2997
|
- resourceId: [optional] The ID of the resource you want to export
|
|
3574
2998
|
|
|
3575
2999
|
```js
|
|
3000
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3576
3001
|
|
|
3577
3002
|
// resource export
|
|
3578
|
-
const exportedResource = await
|
|
3003
|
+
const exportedResource = await KeycloakManager.clients.exportResource({
|
|
3579
3004
|
id: 'internal-client-id'
|
|
3580
3005
|
});
|
|
3581
3006
|
|
|
@@ -3599,6 +3024,7 @@ a document, or any application-specific asset. This allows you to manage fine-gr
|
|
|
3599
3024
|
- owner: [optional] Defines the owner of the resource.
|
|
3600
3025
|
|
|
3601
3026
|
```js
|
|
3027
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3602
3028
|
|
|
3603
3029
|
// define a resource
|
|
3604
3030
|
const newResource = {
|
|
@@ -3608,7 +3034,7 @@ const newResource = {
|
|
|
3608
3034
|
type: 'REST',
|
|
3609
3035
|
};
|
|
3610
3036
|
// create resource
|
|
3611
|
-
const createdResource = await
|
|
3037
|
+
const createdResource = await KeycloakManager.clients.createResource(
|
|
3612
3038
|
{id: 'internal-client-id'},
|
|
3613
3039
|
newResource
|
|
3614
3040
|
);
|
|
@@ -3626,9 +3052,10 @@ that can have associated scopes, policies, and permissions for fine-grained acce
|
|
|
3626
3052
|
- id: [required] The ID of the client that owns the resource
|
|
3627
3053
|
- resourceId: [required] The ID of the resource you want to retrieve.
|
|
3628
3054
|
```js
|
|
3055
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3629
3056
|
|
|
3630
3057
|
// get resource
|
|
3631
|
-
const createdResource = await
|
|
3058
|
+
const createdResource = await KeycloakManager.clients.getResource({
|
|
3632
3059
|
id: 'internal-client-id',
|
|
3633
3060
|
resourceId: '12345-abcde',
|
|
3634
3061
|
});
|
|
@@ -3646,11 +3073,11 @@ meaning it can define resources, scopes, permissions, and policies for fine-grai
|
|
|
3646
3073
|
- id: [required] The ID of the client whose resource server configuration you want to retrieve
|
|
3647
3074
|
|
|
3648
3075
|
```js
|
|
3076
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3649
3077
|
|
|
3650
3078
|
// get resource Server
|
|
3651
|
-
const resourceServer = await
|
|
3652
|
-
id: 'internal-client-id'
|
|
3653
|
-
resourceId: '12345-abcde',
|
|
3079
|
+
const resourceServer = await KeycloakManager.clients.getResourceServer({
|
|
3080
|
+
id: 'internal-client-id'
|
|
3654
3081
|
});
|
|
3655
3082
|
|
|
3656
3083
|
console.log('Resource Server:', resourceServer);
|
|
@@ -3670,6 +3097,7 @@ and policies that control fine-grained access to protected assets.
|
|
|
3670
3097
|
- Other resource server settings depending on your authorization model (resources, scopes, and permissions)
|
|
3671
3098
|
|
|
3672
3099
|
```js
|
|
3100
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3673
3101
|
|
|
3674
3102
|
//define resource Server
|
|
3675
3103
|
const resourceServerRepresentation={
|
|
@@ -3678,7 +3106,7 @@ const resourceServerRepresentation={
|
|
|
3678
3106
|
}
|
|
3679
3107
|
|
|
3680
3108
|
// update resource Server
|
|
3681
|
-
await
|
|
3109
|
+
await KeycloakManager.clients.updateResourceServer(
|
|
3682
3110
|
{ id: 'internal-client-id' },
|
|
3683
3111
|
resourceServerRepresentation
|
|
3684
3112
|
);
|
|
@@ -3696,10 +3124,11 @@ This is part of the Keycloak Authorization Services API and helps administrators
|
|
|
3696
3124
|
- resourceId: [required] The ID of the resource for which to list permissions.
|
|
3697
3125
|
|
|
3698
3126
|
```js
|
|
3127
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3699
3128
|
|
|
3700
3129
|
|
|
3701
3130
|
// List permissions by resource
|
|
3702
|
-
const permissions= await
|
|
3131
|
+
const permissions= await KeycloakManager.clients.listPermissionsByResource({
|
|
3703
3132
|
id: 'internal-client-id',
|
|
3704
3133
|
resourceId: 'resource-id'
|
|
3705
3134
|
});
|
|
@@ -3723,9 +3152,10 @@ based on policies you configure. This is part of Keycloak’s Authorization Serv
|
|
|
3723
3152
|
- policies [required] Array of policy IDs associated with this permission
|
|
3724
3153
|
|
|
3725
3154
|
```js
|
|
3155
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3726
3156
|
|
|
3727
3157
|
// create a permission
|
|
3728
|
-
await
|
|
3158
|
+
await KeycloakManager.clients.createPermission({
|
|
3729
3159
|
id: 'internal-client-id',
|
|
3730
3160
|
type: "scope",
|
|
3731
3161
|
},
|
|
@@ -3758,9 +3188,10 @@ and this method allows you to list and filter them based on specific criteria.
|
|
|
3758
3188
|
- first: [optional] Index of the first result for pagination
|
|
3759
3189
|
- max: [optional] Maximum number of results to return
|
|
3760
3190
|
```js
|
|
3191
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3761
3192
|
|
|
3762
3193
|
// search permission
|
|
3763
|
-
const permissions= await
|
|
3194
|
+
const permissions= await KeycloakManager.clients.findPermissions({
|
|
3764
3195
|
id: 'internal-client-id',
|
|
3765
3196
|
name: "View Orders",
|
|
3766
3197
|
type: "resource",
|
|
@@ -3781,9 +3212,10 @@ Fine-grained permissions allow you to control which users/roles can manage diffe
|
|
|
3781
3212
|
- status: JSON structure that defines the fine grain permission
|
|
3782
3213
|
- enabled: [required] Whether fine-grained permissions should be enabled or disabled.
|
|
3783
3214
|
```js
|
|
3215
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3784
3216
|
|
|
3785
3217
|
// enable fine-grained permissions for this client
|
|
3786
|
-
await
|
|
3218
|
+
await KeycloakManager.clients.updateFineGrainPermission(
|
|
3787
3219
|
{ id: 'internal-client-id'},
|
|
3788
3220
|
{ enabled: true }
|
|
3789
3221
|
);
|
|
@@ -3798,9 +3230,10 @@ This is useful for checking which permissions are configured (e.g., managing rol
|
|
|
3798
3230
|
- filter: JSON structure that defines the filter parameters:
|
|
3799
3231
|
- id: [required] The ID of the client (the resource server) where permissions are defined
|
|
3800
3232
|
```js
|
|
3233
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3801
3234
|
|
|
3802
3235
|
// enable fine-grained permissions for this client
|
|
3803
|
-
const permissions= await
|
|
3236
|
+
const permissions= await KeycloakManager.clients.listFineGrainPermissions(
|
|
3804
3237
|
{ id: 'internal-client-id'},
|
|
3805
3238
|
{ enabled: true }
|
|
3806
3239
|
);
|
|
@@ -3818,9 +3251,10 @@ In Keycloak’s Authorization Services, permissions can be linked to one or more
|
|
|
3818
3251
|
- permissionId: [required] The ID of the permission whose associated scopes you want to retrieve.
|
|
3819
3252
|
|
|
3820
3253
|
```js
|
|
3254
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3821
3255
|
|
|
3822
3256
|
// List associated scope
|
|
3823
|
-
const scopes= await
|
|
3257
|
+
const scopes= await KeycloakManager.clients.getAssociatedScopes({
|
|
3824
3258
|
id: 'internal-client-id',
|
|
3825
3259
|
permissionId: "123e4567-e89b-12d3-a456-426614174000",
|
|
3826
3260
|
});
|
|
@@ -3837,9 +3271,10 @@ n Keycloak Authorization Services, permissions can be tied to one or more polici
|
|
|
3837
3271
|
- permissionId: [required] The ID of the permission whose associated policies you want to retrieve.
|
|
3838
3272
|
|
|
3839
3273
|
```js
|
|
3274
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3840
3275
|
|
|
3841
3276
|
// List associated policies
|
|
3842
|
-
const policies= await
|
|
3277
|
+
const policies= await KeycloakManager.clients.getAssociatedPolicies({
|
|
3843
3278
|
id: 'internal-client-id',
|
|
3844
3279
|
permissionId: "123e4567-e89b-12d3-a456-426614174000",
|
|
3845
3280
|
});
|
|
@@ -3858,9 +3293,10 @@ In Keycloak Authorization Services, permissions can be scoped to one or more res
|
|
|
3858
3293
|
- permissionId: [required] The ID of the permission for which you want to fetch associated resources.
|
|
3859
3294
|
|
|
3860
3295
|
```js
|
|
3296
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3861
3297
|
|
|
3862
3298
|
// List associated resources
|
|
3863
|
-
const resources= await
|
|
3299
|
+
const resources= await KeycloakManager.clients.getAssociatedResources({
|
|
3864
3300
|
id: 'internal-client-id',
|
|
3865
3301
|
permissionId: "123e4567-e89b-12d3-a456-426614174000",
|
|
3866
3302
|
});
|
|
@@ -3879,10 +3315,11 @@ This allows administrators to understand which scopes are directly linked to a p
|
|
|
3879
3315
|
- resourceId: [required] The ID of the resource for which to list scopes.
|
|
3880
3316
|
|
|
3881
3317
|
```js
|
|
3318
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3882
3319
|
|
|
3883
3320
|
|
|
3884
3321
|
// List permissions by resource
|
|
3885
|
-
const scopes= await
|
|
3322
|
+
const scopes= await KeycloakManager.clients.listScopesByResource({
|
|
3886
3323
|
id: 'internal-client-id',
|
|
3887
3324
|
resourceId: 'resource-id'
|
|
3888
3325
|
});
|
|
@@ -3906,12 +3343,12 @@ Resources represent protected entities (such as APIs, files, or services) that c
|
|
|
3906
3343
|
- owner: [optional] Filters resources by owner
|
|
3907
3344
|
|
|
3908
3345
|
```js
|
|
3346
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3909
3347
|
|
|
3910
3348
|
|
|
3911
3349
|
// List resources
|
|
3912
|
-
const resources= await
|
|
3913
|
-
id: 'internal-client-id'
|
|
3914
|
-
resourceId: 'resource-id'
|
|
3350
|
+
const resources= await KeycloakManager.clients.listResources({
|
|
3351
|
+
id: 'internal-client-id'
|
|
3915
3352
|
});
|
|
3916
3353
|
|
|
3917
3354
|
console.log("Resources:", resources);
|
|
@@ -3936,10 +3373,11 @@ Resources represent protected entities (APIs, files, services, etc.) that can be
|
|
|
3936
3373
|
|
|
3937
3374
|
|
|
3938
3375
|
```js
|
|
3376
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3939
3377
|
|
|
3940
3378
|
|
|
3941
3379
|
// Update resource
|
|
3942
|
-
await
|
|
3380
|
+
await KeycloakManager.clients.updateResource(
|
|
3943
3381
|
{
|
|
3944
3382
|
id: 'internal-client-id',
|
|
3945
3383
|
resourceId: 'resource-id'
|
|
@@ -3980,10 +3418,11 @@ They can be based on users, roles, groups, conditions, or custom logic.
|
|
|
3980
3418
|
|
|
3981
3419
|
|
|
3982
3420
|
```js
|
|
3421
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
3983
3422
|
|
|
3984
3423
|
|
|
3985
3424
|
// create new policy
|
|
3986
|
-
await
|
|
3425
|
+
await KeycloakManager.clients.createPolicy(
|
|
3987
3426
|
{
|
|
3988
3427
|
id: 'internal-client-id',
|
|
3989
3428
|
type: "role",
|
|
@@ -4016,10 +3455,11 @@ This is useful when you want to understand how a policy is referenced by other p
|
|
|
4016
3455
|
- policyId: [required] The ID of the policy for which you want to list dependent policies.
|
|
4017
3456
|
|
|
4018
3457
|
```js
|
|
3458
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4019
3459
|
|
|
4020
3460
|
|
|
4021
3461
|
// create new policy
|
|
4022
|
-
const dependentPolicies= await
|
|
3462
|
+
const dependentPolicies= await KeycloakManager.clients.listDependentPolicies(
|
|
4023
3463
|
{
|
|
4024
3464
|
id: 'internal-client-id',
|
|
4025
3465
|
policyId: "1234-abcd-policy-id",
|
|
@@ -4040,8 +3480,9 @@ contents without performing a full user login. This can help you verify client r
|
|
|
4040
3480
|
- id: [required] ID of the client for which you want to generate or evaluate the access token
|
|
4041
3481
|
|
|
4042
3482
|
```js
|
|
3483
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4043
3484
|
// generate accesstoken
|
|
4044
|
-
const token = await
|
|
3485
|
+
const token = await KeycloakManager.clients.evaluateGenerateAccessToken({
|
|
4045
3486
|
id: 'internal-client-id'
|
|
4046
3487
|
});
|
|
4047
3488
|
|
|
@@ -4066,8 +3507,9 @@ token for the client.
|
|
|
4066
3507
|
- id: [required] ID of the client for which you want to generate or evaluate the ID token
|
|
4067
3508
|
|
|
4068
3509
|
```js
|
|
3510
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4069
3511
|
// generate id token
|
|
4070
|
-
const token = await
|
|
3512
|
+
const token = await KeycloakManager.clients.evaluateGenerateIdToken({
|
|
4071
3513
|
id: 'internal-client-id',
|
|
4072
3514
|
});
|
|
4073
3515
|
|
|
@@ -4091,8 +3533,9 @@ UserInfo response without performing a full login flow.
|
|
|
4091
3533
|
- id: [required] The ID of the client for which you want to generate the UserInfo response
|
|
4092
3534
|
|
|
4093
3535
|
```js
|
|
3536
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4094
3537
|
// generate toke user info
|
|
4095
|
-
const userInfo = await
|
|
3538
|
+
const userInfo = await KeycloakManager.clients.evaluateGenerateUserInfo({
|
|
4096
3539
|
id: 'internal-client-id',
|
|
4097
3540
|
});
|
|
4098
3541
|
|
|
@@ -4121,8 +3564,9 @@ Protocol mappers define how user information (claims) is mapped into tokens (lik
|
|
|
4121
3564
|
- id: [required] ID of the client for which you want to list or evaluate protocol mappers.
|
|
4122
3565
|
|
|
4123
3566
|
```js
|
|
3567
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4124
3568
|
// List protocol mappers for client
|
|
4125
|
-
const protocolMappers = await
|
|
3569
|
+
const protocolMappers = await KeycloakManager.clients.evaluateListProtocolMapper({
|
|
4126
3570
|
id: 'internal-client-id',
|
|
4127
3571
|
});
|
|
4128
3572
|
|
|
@@ -4155,8 +3599,9 @@ Protocol mappers define how data from user/client models is added to tokens (e.g
|
|
|
4155
3599
|
- ....
|
|
4156
3600
|
|
|
4157
3601
|
```js
|
|
3602
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4158
3603
|
// add single protocol mapper
|
|
4159
|
-
await
|
|
3604
|
+
await KeycloakManager.clients.addProtocolMapper(
|
|
4160
3605
|
{id: 'internal-client-id'},
|
|
4161
3606
|
{
|
|
4162
3607
|
name: "become-a-farmer",
|
|
@@ -4198,8 +3643,9 @@ The method is used to update an existing protocol mapper for a specific client i
|
|
|
4198
3643
|
- ....
|
|
4199
3644
|
|
|
4200
3645
|
```js
|
|
3646
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4201
3647
|
// update protocol mappe
|
|
4202
|
-
await
|
|
3648
|
+
await KeycloakManager.clients.updateProtocolMapper(
|
|
4203
3649
|
{id: 'internal-client-id', mapperId:'mapper-id'},
|
|
4204
3650
|
{
|
|
4205
3651
|
name: "become-a-farmer",
|
|
@@ -4238,8 +3684,9 @@ This batch operation is efficient when you want to configure multiple mappings w
|
|
|
4238
3684
|
- ....
|
|
4239
3685
|
|
|
4240
3686
|
```js
|
|
3687
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4241
3688
|
// add multiple protocol mappers
|
|
4242
|
-
await
|
|
3689
|
+
await KeycloakManager.clients.addMultipleProtocolMappers(
|
|
4243
3690
|
{id: 'internal-client-id'},
|
|
4244
3691
|
[
|
|
4245
3692
|
{
|
|
@@ -4290,8 +3737,9 @@ It is particularly useful when you want to verify if a mapper exists or fetch it
|
|
|
4290
3737
|
- name: [required] The name of the protocol mapper to look up. (usually "openid-connect" or "saml").
|
|
4291
3738
|
|
|
4292
3739
|
```js
|
|
3740
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4293
3741
|
// find Protocol Mapper ByName
|
|
4294
|
-
await
|
|
3742
|
+
await KeycloakManager.clients.findProtocolMapperByName({
|
|
4295
3743
|
id: 'internal-client-id',
|
|
4296
3744
|
name: 'protocol-name',
|
|
4297
3745
|
});
|
|
@@ -4309,8 +3757,9 @@ The method returns all protocol mappers associated with a client, filtered by a
|
|
|
4309
3757
|
- "saml"
|
|
4310
3758
|
|
|
4311
3759
|
```js
|
|
3760
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4312
3761
|
// find protocol mappers by protocol
|
|
4313
|
-
const mappers = await
|
|
3762
|
+
const mappers = await KeycloakManager.clients.findProtocolMappersByProtocol({
|
|
4314
3763
|
id: 'internal-client-id',
|
|
4315
3764
|
protocol: 'openid-connect',
|
|
4316
3765
|
});
|
|
@@ -4329,8 +3778,9 @@ The method retrieves the details of a specific protocol mapper by its ID for a g
|
|
|
4329
3778
|
- mapperId: [required] The ID of the protocol mapper you want to fetch.
|
|
4330
3779
|
|
|
4331
3780
|
```js
|
|
3781
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4332
3782
|
// find Protocol Mapper By Id
|
|
4333
|
-
const mapper = await
|
|
3783
|
+
const mapper = await KeycloakManager.clients.findProtocolMapperById({
|
|
4334
3784
|
id: 'internal-client-id',
|
|
4335
3785
|
mapperId: 'protocol-id',
|
|
4336
3786
|
});
|
|
@@ -4348,8 +3798,9 @@ This method is useful for inspecting or managing the token contents of a client.
|
|
|
4348
3798
|
- id: [required] The internal ID of the client whose protocol mappers you want to list.
|
|
4349
3799
|
|
|
4350
3800
|
```js
|
|
3801
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4351
3802
|
// list protocol mappers
|
|
4352
|
-
const protocolMappers = await
|
|
3803
|
+
const protocolMappers = await KeycloakManager.clients.listProtocolMappers({
|
|
4353
3804
|
id: 'internal-client-id',
|
|
4354
3805
|
});
|
|
4355
3806
|
console.log("Protocol Mappers:", protocolMappers);
|
|
@@ -4367,8 +3818,9 @@ This method is useful when you want to remove an existing mapper from a client c
|
|
|
4367
3818
|
- mapperId: [required] The ID of the protocol mapper to delete
|
|
4368
3819
|
|
|
4369
3820
|
```js
|
|
3821
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4370
3822
|
// Del Protocol Mapper
|
|
4371
|
-
await
|
|
3823
|
+
await KeycloakManager.clients.delProtocolMapper({
|
|
4372
3824
|
id: 'internal-client-id',
|
|
4373
3825
|
mapperId: 'mapper-id',
|
|
4374
3826
|
});
|
|
@@ -4388,8 +3840,9 @@ method is used to create a new client scope in a Keycloak realm.
|
|
|
4388
3840
|
A client scope defines a set of protocol mappers and roles that can be applied to clients,
|
|
4389
3841
|
such as during login or token generation.
|
|
4390
3842
|
```js
|
|
3843
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4391
3844
|
// create a group called my-group
|
|
4392
|
-
await
|
|
3845
|
+
await KeycloakManager.clientScopes.create({
|
|
4393
3846
|
name: "scope-name",
|
|
4394
3847
|
description: "scope-description",
|
|
4395
3848
|
protocol: "openid-connect",
|
|
@@ -4411,8 +3864,9 @@ You can modify properties such as the scope’s name, description, attributes, o
|
|
|
4411
3864
|
- other scope fields....
|
|
4412
3865
|
|
|
4413
3866
|
```js
|
|
3867
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4414
3868
|
// update a scope called my-scope-id
|
|
4415
|
-
await
|
|
3869
|
+
await KeycloakManager.clientScopes.update(
|
|
4416
3870
|
{id:'my-scope-id'},
|
|
4417
3871
|
{
|
|
4418
3872
|
name: "scope-name",
|
|
@@ -4432,8 +3886,9 @@ Once deleted, the client scope will no longer be available for assignment to cli
|
|
|
4432
3886
|
- id: [required] The unique ID of the client scope to delete.
|
|
4433
3887
|
- realm: [optional] The realm where the client scope is defined.
|
|
4434
3888
|
```js
|
|
3889
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4435
3890
|
// delete client scope
|
|
4436
|
-
await
|
|
3891
|
+
await KeycloakManager.clientScopes.del({
|
|
4437
3892
|
id: "scope-id",
|
|
4438
3893
|
});
|
|
4439
3894
|
```
|
|
@@ -4447,8 +3902,9 @@ It's an alternative to deleting by ID when the scope's name is known.
|
|
|
4447
3902
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
4448
3903
|
- name: [required] The name of the client scope to delete. This must match exactly with the registered name in the realm.
|
|
4449
3904
|
```js
|
|
3905
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4450
3906
|
// cleanup client scopes
|
|
4451
|
-
await
|
|
3907
|
+
await KeycloakManager.clientScopes.delByName({
|
|
4452
3908
|
name: "scope-name",
|
|
4453
3909
|
});
|
|
4454
3910
|
```
|
|
@@ -4465,8 +3921,9 @@ Client scopes represent a set of protocol mappers and roles that can be assigned
|
|
|
4465
3921
|
- first: [optional] Index of the first result (for pagination).
|
|
4466
3922
|
- max: [optional] Maximum number of results to return.
|
|
4467
3923
|
```js
|
|
3924
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4468
3925
|
// Find client Scope
|
|
4469
|
-
const scope = await
|
|
3926
|
+
const scope = await KeycloakManager.clientScopes.find({
|
|
4470
3927
|
max: 10
|
|
4471
3928
|
});
|
|
4472
3929
|
console.log("Search Result:",scope);
|
|
@@ -4482,8 +3939,9 @@ It’s useful when you need the full configuration of a particular client scope,
|
|
|
4482
3939
|
- realm: [optional] The realm where the client scope is defined.
|
|
4483
3940
|
|
|
4484
3941
|
```js
|
|
3942
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4485
3943
|
// Find one client Scope
|
|
4486
|
-
const scope = await
|
|
3944
|
+
const scope = await KeycloakManager.clientScopes.findOne({
|
|
4487
3945
|
id: 'my-scope-id'
|
|
4488
3946
|
});
|
|
4489
3947
|
console.log("Search Result:",scope);
|
|
@@ -4498,8 +3956,9 @@ including its ID, protocol, and other settings.
|
|
|
4498
3956
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
4499
3957
|
- name: [required] The name of the client scope you're searching for.
|
|
4500
3958
|
```js
|
|
3959
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4501
3960
|
// Find client Scope by name
|
|
4502
|
-
const scope = await
|
|
3961
|
+
const scope = await KeycloakManager.clientScopes.findOneByName({
|
|
4503
3962
|
name: "scope-name",
|
|
4504
3963
|
});
|
|
4505
3964
|
console.log("Search Result:",scope);
|
|
@@ -4516,8 +3975,9 @@ Default client scopes are automatically assigned to newly created clients in tha
|
|
|
4516
3975
|
- first: [optional] Index of the first result (for pagination).
|
|
4517
3976
|
- max: [optional] Maximum number of results to return.
|
|
4518
3977
|
```js
|
|
3978
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4519
3979
|
// list default client scopes
|
|
4520
|
-
const scopes = await
|
|
3980
|
+
const scopes = await KeycloakManager.clientScopes.listDefaultClientScopes({
|
|
4521
3981
|
realm: "realm-name",
|
|
4522
3982
|
});
|
|
4523
3983
|
console.log("Search Result:",scopes);
|
|
@@ -4533,8 +3993,9 @@ Default client scopes are automatically assigned to all newly created clients wi
|
|
|
4533
3993
|
- id: [required] The ID of the client scope to add as a default.
|
|
4534
3994
|
- realm: [optional] The realm where the client scopes are defined.
|
|
4535
3995
|
```js
|
|
3996
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4536
3997
|
// add default client scope
|
|
4537
|
-
await
|
|
3998
|
+
await KeycloakManager.clientScopes.addDefaultClientScope({
|
|
4538
3999
|
id: "client-scope-id",
|
|
4539
4000
|
});
|
|
4540
4001
|
|
|
@@ -4552,8 +4013,9 @@ Removing one prevents it from being included by default.
|
|
|
4552
4013
|
- realm:: [optional] The realm where the client scope is defined.
|
|
4553
4014
|
|
|
4554
4015
|
```js
|
|
4016
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4555
4017
|
// delete default client Scope
|
|
4556
|
-
await
|
|
4018
|
+
await KeycloakManager.clientScopes.delDefaultClientScope({
|
|
4557
4019
|
realm: "myrealm-name",
|
|
4558
4020
|
id: "default-profile-scope-id",
|
|
4559
4021
|
});
|
|
@@ -4571,8 +4033,9 @@ Optional client scopes are available for clients to select but are not automatic
|
|
|
4571
4033
|
- realm:: [optional] The realm where the client scope is defined.
|
|
4572
4034
|
|
|
4573
4035
|
```js
|
|
4036
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4574
4037
|
// list default optional client scopes
|
|
4575
|
-
const optionalScopes= await
|
|
4038
|
+
const optionalScopes= await KeycloakManager.clientScopes.listDefaultOptionalClientScopes({
|
|
4576
4039
|
realm: "myrealm-name",
|
|
4577
4040
|
id: "default-profile-scope-id",
|
|
4578
4041
|
});
|
|
@@ -4591,8 +4054,9 @@ Optional client scopes are available to clients for selection but are not automa
|
|
|
4591
4054
|
- realm:: [optional] The realm where the client scope is defined.
|
|
4592
4055
|
|
|
4593
4056
|
```js
|
|
4057
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4594
4058
|
// add default optional client scope
|
|
4595
|
-
await
|
|
4059
|
+
await KeycloakManager.clientScopes.addDefaultOptionalClientScope({
|
|
4596
4060
|
realm: "myrealm-name",
|
|
4597
4061
|
id: "default-profile-scope-id",
|
|
4598
4062
|
});
|
|
@@ -4613,8 +4077,9 @@ Removing one prevents it from being listed as optional for new clients.
|
|
|
4613
4077
|
- realm:: [optional] The realm where the client scope is defined.
|
|
4614
4078
|
|
|
4615
4079
|
```js
|
|
4080
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4616
4081
|
// delete optional client Scope
|
|
4617
|
-
await
|
|
4082
|
+
await KeycloakManager.clientScopes.delDefaultOptionalClientScope({
|
|
4618
4083
|
realm: "myrealm-name",
|
|
4619
4084
|
id: "default-profile-scope-id",
|
|
4620
4085
|
});
|
|
@@ -4634,8 +4099,9 @@ Protocol mappers define how user attributes, roles, or other data are mapped int
|
|
|
4634
4099
|
- name: [optional] The name of the protocol mapper to find.
|
|
4635
4100
|
|
|
4636
4101
|
```js
|
|
4102
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4637
4103
|
// find protocol mapper by name
|
|
4638
|
-
const mapper= await
|
|
4104
|
+
const mapper= await KeycloakManager.clientScopes.findProtocolMapperByName({
|
|
4639
4105
|
realm: "myrealm-name",
|
|
4640
4106
|
id: "mapper-id-protocol",
|
|
4641
4107
|
name: "username",
|
|
@@ -4659,8 +4125,9 @@ Protocol mappers define how user attributes, roles, or other information are map
|
|
|
4659
4125
|
- realm: [optional] The realm where the client scope is defined.
|
|
4660
4126
|
|
|
4661
4127
|
```js
|
|
4128
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4662
4129
|
// find protocol mapper by name
|
|
4663
|
-
const mapper= await
|
|
4130
|
+
const mapper= await KeycloakManager.clientScopes.findProtocolMapper({
|
|
4664
4131
|
realm: "myrealm-name",
|
|
4665
4132
|
id: "client-scope-id",
|
|
4666
4133
|
mapperId: "mapper-id-123",
|
|
@@ -4684,8 +4151,9 @@ This is useful when you want to filter protocol mappers by the authentication pr
|
|
|
4684
4151
|
- realm: [optional] The realm where the client scope is defined.
|
|
4685
4152
|
|
|
4686
4153
|
```js
|
|
4154
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4687
4155
|
// find protocol mapper by protocol
|
|
4688
|
-
const mapper= await
|
|
4156
|
+
const mapper= await KeycloakManager.clientScopes.findProtocolMappersByProtocol({
|
|
4689
4157
|
realm: "myrealm-name",
|
|
4690
4158
|
id: "client-scope-id",
|
|
4691
4159
|
protocol: "openid-connect",
|
|
@@ -4710,9 +4178,10 @@ Deleting a mapper removes its configuration from the client scope.
|
|
|
4710
4178
|
- realm: [optional] The realm where the client scope is defined.
|
|
4711
4179
|
|
|
4712
4180
|
```js
|
|
4181
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4713
4182
|
|
|
4714
4183
|
// Del Protocol Mapper
|
|
4715
|
-
await
|
|
4184
|
+
await KeycloakManager.clientScopes.delProtocolMapper({
|
|
4716
4185
|
realm: "my-realm-id",
|
|
4717
4186
|
id: "client-id",
|
|
4718
4187
|
mapperId: "mapper-id-123",
|
|
@@ -4731,9 +4200,10 @@ Protocol mappers define how user attributes, roles, or other data are mapped int
|
|
|
4731
4200
|
- realm: [optional] The realm where the client scope is defined.
|
|
4732
4201
|
|
|
4733
4202
|
```js
|
|
4203
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4734
4204
|
|
|
4735
4205
|
// list protocol mapper
|
|
4736
|
-
const mappers= await
|
|
4206
|
+
const mappers= await KeycloakManager.clientScopes.listProtocolMappers({
|
|
4737
4207
|
realm: "myrealm-name",
|
|
4738
4208
|
id: "mapper-id",
|
|
4739
4209
|
});
|
|
@@ -4759,9 +4229,10 @@ With this method, you can configure several mappers in a single request.
|
|
|
4759
4229
|
- consentRequired: [optional] Whether user consent is required.
|
|
4760
4230
|
|
|
4761
4231
|
```js
|
|
4232
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4762
4233
|
|
|
4763
4234
|
// add multiple protocol mappers
|
|
4764
|
-
await
|
|
4235
|
+
await KeycloakManager.clientScopes.addMultipleProtocolMappers(
|
|
4765
4236
|
{ id: 'client-scope-id' },
|
|
4766
4237
|
[
|
|
4767
4238
|
{
|
|
@@ -4805,9 +4276,10 @@ Protocol mappers define how user attributes, roles, or other information are map
|
|
|
4805
4276
|
- consentRequired: [optional] Whether user consent is required.
|
|
4806
4277
|
|
|
4807
4278
|
```js
|
|
4279
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4808
4280
|
|
|
4809
4281
|
// add protocol mapper
|
|
4810
|
-
await
|
|
4282
|
+
await KeycloakManager.clientScopes.addProtocolMapper(
|
|
4811
4283
|
{ id: 'client-scope-id' },
|
|
4812
4284
|
|
|
4813
4285
|
{
|
|
@@ -4847,9 +4319,10 @@ With this method, you can modify an existing mapper’s configuration.
|
|
|
4847
4319
|
- consentRequired: [optional] Whether user consent is required.
|
|
4848
4320
|
|
|
4849
4321
|
```js
|
|
4322
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4850
4323
|
|
|
4851
4324
|
// add protocol mapper
|
|
4852
|
-
await
|
|
4325
|
+
await KeycloakManager.clientScopes.updateProtocolMapper(
|
|
4853
4326
|
{ id: 'client-scope-id' , mapperId: "mapper-id-123",},
|
|
4854
4327
|
|
|
4855
4328
|
{
|
|
@@ -4881,9 +4354,10 @@ These roles determine the permissions and access tokens issued for clients using
|
|
|
4881
4354
|
- realm: [optional] The realm where the client scope is defined.
|
|
4882
4355
|
|
|
4883
4356
|
```js
|
|
4357
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4884
4358
|
|
|
4885
4359
|
// list scope mapping
|
|
4886
|
-
const scopeMappings= await
|
|
4360
|
+
const scopeMappings= await KeycloakManager.clientScopes.listScopeMappings({
|
|
4887
4361
|
realm: "myrealm-name",
|
|
4888
4362
|
id: "client-scope-id",
|
|
4889
4363
|
});
|
|
@@ -4904,9 +4378,10 @@ This helps identify which roles from a specific client are still available to be
|
|
|
4904
4378
|
- realm: [optional] The realm where the client scope is defined.
|
|
4905
4379
|
|
|
4906
4380
|
```js
|
|
4381
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4907
4382
|
|
|
4908
4383
|
// list available client scope mapping
|
|
4909
|
-
const availableRoles= await
|
|
4384
|
+
const availableRoles= await KeycloakManager.clientScopes.listAvailableClientScopeMappings({
|
|
4910
4385
|
realm: "myrealm-name",
|
|
4911
4386
|
id: "client-scope-id",
|
|
4912
4387
|
client:'client-id'
|
|
@@ -4935,9 +4410,10 @@ This means the client scope will include the selected roles, and any client usin
|
|
|
4935
4410
|
- containerId: [optional] The ID of the client containing the role.
|
|
4936
4411
|
|
|
4937
4412
|
```js
|
|
4413
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4938
4414
|
|
|
4939
4415
|
// add client scope mapping
|
|
4940
|
-
const availableRoles= await
|
|
4416
|
+
const availableRoles= await KeycloakManager.clientScopes.addClientScopeMappings(
|
|
4941
4417
|
{
|
|
4942
4418
|
realm: "myrealm-name",
|
|
4943
4419
|
id: "client-scope-id",
|
|
@@ -4981,9 +4457,10 @@ This allows you to revoke previously assigned client roles so they are no longer
|
|
|
4981
4457
|
- containerId: [optional] The ID of the client containing the role.
|
|
4982
4458
|
|
|
4983
4459
|
```js
|
|
4460
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
4984
4461
|
|
|
4985
4462
|
// add client scope mapping
|
|
4986
|
-
const availableRoles= await
|
|
4463
|
+
const availableRoles= await KeycloakManager.clientScopes.delClientScopeMappings(
|
|
4987
4464
|
{
|
|
4988
4465
|
realm: "myrealm-name",
|
|
4989
4466
|
id: "client-scope-id",
|
|
@@ -5021,9 +4498,10 @@ This allows you to check which roles from a particular client are already includ
|
|
|
5021
4498
|
- realm: [optional] The realm where the client scope is defined.
|
|
5022
4499
|
|
|
5023
4500
|
```js
|
|
4501
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5024
4502
|
|
|
5025
4503
|
// list client scope mapping
|
|
5026
|
-
const mappedRoles= await
|
|
4504
|
+
const mappedRoles= await KeycloakManager.clientScopes.listClientScopeMappings({
|
|
5027
4505
|
realm: "myrealm-name",
|
|
5028
4506
|
id: "client-scope-id",
|
|
5029
4507
|
client: "client-id",
|
|
@@ -5045,9 +4523,10 @@ This is useful when you want to see the final set of roles available in a client
|
|
|
5045
4523
|
- realm: [optional] The realm where the client scope is defined.
|
|
5046
4524
|
|
|
5047
4525
|
```js
|
|
4526
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5048
4527
|
|
|
5049
4528
|
// list client scope mapping
|
|
5050
|
-
const mappedRoles= await
|
|
4529
|
+
const mappedRoles= await KeycloakManager.clientScopes.listCompositeClientScopeMappings({
|
|
5051
4530
|
realm: "myrealm-name",
|
|
5052
4531
|
id: "client-scope-id",
|
|
5053
4532
|
client: "client-id",
|
|
@@ -5068,9 +4547,10 @@ This helps you determine which realm-level roles can still be added to the clien
|
|
|
5068
4547
|
- realm: [optional] The realm where the client scope is defined.
|
|
5069
4548
|
|
|
5070
4549
|
```js
|
|
4550
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5071
4551
|
|
|
5072
4552
|
// list available realm scope mappings
|
|
5073
|
-
const availableRealmRoles= await
|
|
4553
|
+
const availableRealmRoles= await KeycloakManager.clientScopes.listAvailableRealmScopeMappings({
|
|
5074
4554
|
realm: "myrealm-name",
|
|
5075
4555
|
id: "client-scope-id",
|
|
5076
4556
|
});
|
|
@@ -5096,9 +4576,10 @@ This means that any client using this client scope will inherit the specified re
|
|
|
5096
4576
|
- containerId: [optional] The ID of the realm containing the role.
|
|
5097
4577
|
|
|
5098
4578
|
```js
|
|
4579
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5099
4580
|
|
|
5100
4581
|
// add realm scope mappings
|
|
5101
|
-
const availableRealmRoles= await
|
|
4582
|
+
const availableRealmRoles= await KeycloakManager.clientScopes.addRealmScopeMappings(
|
|
5102
4583
|
{
|
|
5103
4584
|
realm: "myrealm-name",
|
|
5104
4585
|
id: "client-scope-idb"
|
|
@@ -5130,9 +4611,10 @@ This revokes previously assigned realm roles, so clients using this scope will n
|
|
|
5130
4611
|
- containerId: [optional] The ID of the realm containing the role.
|
|
5131
4612
|
|
|
5132
4613
|
```js
|
|
4614
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5133
4615
|
|
|
5134
4616
|
// del realm scope mappings
|
|
5135
|
-
const availableRealmRoles= await
|
|
4617
|
+
const availableRealmRoles= await KeycloakManager.clientScopes.delRealmScopeMappings(
|
|
5136
4618
|
{
|
|
5137
4619
|
realm: "myrealm-name",
|
|
5138
4620
|
id: "client-scope-id"
|
|
@@ -5158,9 +4640,10 @@ This allows you to see which realm-level permissions are already assigned to the
|
|
|
5158
4640
|
- realm: [optional] The realm where the client scope is defined.
|
|
5159
4641
|
|
|
5160
4642
|
```js
|
|
4643
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5161
4644
|
|
|
5162
4645
|
// list realm scope mappings
|
|
5163
|
-
const mappedRealmRoles= await
|
|
4646
|
+
const mappedRealmRoles= await KeycloakManager.clientScopes.listRealmScopeMappings({
|
|
5164
4647
|
realm: "myrealm-name",
|
|
5165
4648
|
id: "client-id-scope",
|
|
5166
4649
|
});
|
|
@@ -5179,9 +4662,10 @@ This is useful to see the complete set of realm-level permissions a client scope
|
|
|
5179
4662
|
- realm: [optional] The realm where the client scope is defined.
|
|
5180
4663
|
|
|
5181
4664
|
```js
|
|
4665
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5182
4666
|
|
|
5183
4667
|
// list composite realm scope mappings
|
|
5184
|
-
const mappedRealmRoles= await
|
|
4668
|
+
const mappedRealmRoles= await KeycloakManager.clientScopes.listCompositeRealmScopeMappings({
|
|
5185
4669
|
realm: "myrealm-name",
|
|
5186
4670
|
id: "client-id-scope",
|
|
5187
4671
|
});
|
|
@@ -5215,8 +4699,9 @@ This method requires specifying an alias, the provider type, and configuration s
|
|
|
5215
4699
|
- firstBrokerLoginFlowAlias: [optional] Flow to use on first login.
|
|
5216
4700
|
- config : [optional] Provider-specific configuration, e.g., client ID, client secret, endpoints, etc.
|
|
5217
4701
|
```js
|
|
4702
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5218
4703
|
// create a gidentity provider
|
|
5219
|
-
|
|
4704
|
+
KeycloakManager.identityProviders.create({
|
|
5220
4705
|
alias: "google",
|
|
5221
4706
|
providerId: "google",
|
|
5222
4707
|
enabled: true,
|
|
@@ -5242,8 +4727,9 @@ The mapper defines how attributes, roles, or claims from the Identity Provider a
|
|
|
5242
4727
|
- alias: [required] The alias of the Identity Provider to which the mapper will be attached.
|
|
5243
4728
|
- identityProviderMapper: [required] The mapper configuration object, which includes details like the mapper type, name, and configuration values
|
|
5244
4729
|
```js
|
|
4730
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5245
4731
|
// create a mapper
|
|
5246
|
-
|
|
4732
|
+
KeycloakManager.identityProviders.createMapper({
|
|
5247
4733
|
alias: 'currentIdpAlias',
|
|
5248
4734
|
identityProviderMapper: {
|
|
5249
4735
|
name: "email-mapper",
|
|
@@ -5267,8 +4753,9 @@ These mappers define how attributes, roles, or claims from the external Identity
|
|
|
5267
4753
|
- filter: pparameter provided as a JSON object that accepts the following filter:
|
|
5268
4754
|
- alias: [required] TThe alias of the Identity Provider whose mappers you want to fetch.
|
|
5269
4755
|
```js
|
|
4756
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5270
4757
|
// find a mapper
|
|
5271
|
-
const mappers= await
|
|
4758
|
+
const mappers= await KeycloakManager.identityProviders.findMappers({
|
|
5272
4759
|
alias: 'currentIdpAlias',
|
|
5273
4760
|
|
|
5274
4761
|
});
|
|
@@ -5287,8 +4774,9 @@ This is useful when you need to remove a mapping rule that translates attributes
|
|
|
5287
4774
|
- alias: [required] The alias of the Identity Provider that owns the mapper.
|
|
5288
4775
|
- id : [required] The unique ID of the mapper to be deleted.
|
|
5289
4776
|
```js
|
|
4777
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5290
4778
|
// delete a mapper
|
|
5291
|
-
await
|
|
4779
|
+
await KeycloakManager.identityProviders.delMapper({
|
|
5292
4780
|
alias: 'currentIdpAlias',
|
|
5293
4781
|
id: 'mapperId'
|
|
5294
4782
|
});
|
|
@@ -5306,8 +4794,9 @@ This allows you to inspect a mapper’s configuration, such as how attributes or
|
|
|
5306
4794
|
- alias: [required] The alias of the Identity Provider.
|
|
5307
4795
|
- id: [required] The unique ID of the mapper to retrieve.
|
|
5308
4796
|
```js
|
|
4797
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5309
4798
|
// find a mapper
|
|
5310
|
-
const mapper= await
|
|
4799
|
+
const mapper= await KeycloakManager.identityProviders.findOneMapper({
|
|
5311
4800
|
alias: 'currentIdpAlias',
|
|
5312
4801
|
id: 'mapperId'
|
|
5313
4802
|
});
|
|
@@ -5324,8 +4813,9 @@ After deletion, users will no longer be able to authenticate using that Identity
|
|
|
5324
4813
|
- filter: pparameter provided as a JSON object that accepts the following filter:
|
|
5325
4814
|
- alias: [required] The alias of the Identity Provider you want to delete.
|
|
5326
4815
|
```js
|
|
4816
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5327
4817
|
// delete
|
|
5328
|
-
await
|
|
4818
|
+
await KeycloakManager.identityProviders.del({
|
|
5329
4819
|
alias: 'currentIdpAlias'
|
|
5330
4820
|
});
|
|
5331
4821
|
|
|
@@ -5340,8 +4830,9 @@ It is useful when you need to inspect the provider’s settings, such as its ali
|
|
|
5340
4830
|
- filter: pparameter provided as a JSON object that accepts the following filter:
|
|
5341
4831
|
- alias: [required] The alias of the Identity Provider you want to find.
|
|
5342
4832
|
```js
|
|
4833
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5343
4834
|
// find one
|
|
5344
|
-
const idp= await
|
|
4835
|
+
const idp= await KeycloakManager.identityProviders.findOne({
|
|
5345
4836
|
alias: 'currentIdpAlias'
|
|
5346
4837
|
});
|
|
5347
4838
|
|
|
@@ -5358,8 +4849,9 @@ The method retrieves a list of all configured Identity Providers in the current
|
|
|
5358
4849
|
It allows you to see which providers (e.g., Google, GitHub, SAML, etc.) are available and get their basic configuration details.
|
|
5359
4850
|
|
|
5360
4851
|
```js
|
|
4852
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5361
4853
|
// find
|
|
5362
|
-
const provider= await
|
|
4854
|
+
const provider= await KeycloakManager.identityProviders.find();
|
|
5363
4855
|
|
|
5364
4856
|
console.log("Configured Identity Providers:");
|
|
5365
4857
|
providers.forEach((provider) => {
|
|
@@ -5379,8 +4871,9 @@ It allows you to modify settings such as client ID, secret, authorization URLs,
|
|
|
5379
4871
|
- providerId: [required] The provider type (e.g., "google", "saml").
|
|
5380
4872
|
- Other optional fields like displayName, config object, etc.
|
|
5381
4873
|
```js
|
|
4874
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5382
4875
|
// update one
|
|
5383
|
-
await
|
|
4876
|
+
await KeycloakManager.identityProviders.update(
|
|
5384
4877
|
{ alias: 'currentIdpAlias' },
|
|
5385
4878
|
{
|
|
5386
4879
|
// alias and providerId are required to update
|
|
@@ -5400,8 +4893,9 @@ This is useful when you want to check what configuration options are supported b
|
|
|
5400
4893
|
- filter: pparameter provided as a JSON object that accepts the following filter:
|
|
5401
4894
|
- providerId: [required] The ID of the Identity Provider factory to look up (e.g., "oidc", "saml", "google").
|
|
5402
4895
|
```js
|
|
4896
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5403
4897
|
// find factory
|
|
5404
|
-
const factory= await
|
|
4898
|
+
const factory= await KeycloakManager.identityProviders.findFactory({
|
|
5405
4899
|
providerId: "oidc",
|
|
5406
4900
|
});
|
|
5407
4901
|
|
|
@@ -5419,8 +4913,9 @@ This is useful to list all transformations and mappings applied to users authent
|
|
|
5419
4913
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
5420
4914
|
- alias: [required] The alias of the Identity Provider (set when the provider was created).
|
|
5421
4915
|
```js
|
|
4916
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5422
4917
|
// find one
|
|
5423
|
-
const mappers= await
|
|
4918
|
+
const mappers= await KeycloakManager.identityProviders.findMappers({
|
|
5424
4919
|
alias: "google",
|
|
5425
4920
|
});
|
|
5426
4921
|
|
|
@@ -5436,8 +4931,9 @@ It’s useful when you need to inspect the configuration of a mapper before upda
|
|
|
5436
4931
|
- alias: [required] The alias of the Identity Provider.
|
|
5437
4932
|
- id: [required] The unique ID of the mapper to fetch.
|
|
5438
4933
|
```js
|
|
4934
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5439
4935
|
// find one
|
|
5440
|
-
const mapper= await
|
|
4936
|
+
const mapper= await KeycloakManager.identityProviders.findOneMapper({
|
|
5441
4937
|
alias: "google",
|
|
5442
4938
|
id: "1234-abcd-5678-efgh",
|
|
5443
4939
|
});
|
|
@@ -5465,8 +4961,9 @@ This method allows you to change the configuration of an existing mapper (e.g.,
|
|
|
5465
4961
|
- identityProviderMapper: [optional] The type of mapper (e.g., "oidc-user-attribute-idp-mapper").
|
|
5466
4962
|
- config: [optional] The new mapping configuration.
|
|
5467
4963
|
```js
|
|
4964
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5468
4965
|
// update one Mapper
|
|
5469
|
-
const mappers= await
|
|
4966
|
+
const mappers= await KeycloakManager.identityProviders.updateMapper(
|
|
5470
4967
|
{
|
|
5471
4968
|
alias: "google",
|
|
5472
4969
|
id: "1234-abcd-5678-efgh", // Mapper ID
|
|
@@ -5488,7 +4985,7 @@ console.log("Mapper updated successfully!");
|
|
|
5488
4985
|
|
|
5489
4986
|
|
|
5490
4987
|
|
|
5491
|
-
##### `function identityProviders.importFromUrl(filter
|
|
4988
|
+
##### `function identityProviders.importFromUrl(filter)`
|
|
5492
4989
|
The method lets you import an Identity Provider configuration directly from a metadata URL (e.g., OIDC discovery document or SAML metadata XML).
|
|
5493
4990
|
This saves you from manually entering configuration details, since Keycloak can auto-fill them from the provided URL.
|
|
5494
4991
|
@parameters:
|
|
@@ -5498,8 +4995,9 @@ This saves you from manually entering configuration details, since Keycloak can
|
|
|
5498
4995
|
- trustEmail: [optional] Whether to automatically trust emails from this IdP.
|
|
5499
4996
|
- alias: [optional] Alias for the Identity Provider (unique name).
|
|
5500
4997
|
```js
|
|
4998
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5501
4999
|
// import one Mapper
|
|
5502
|
-
const mappers= await
|
|
5000
|
+
const mappers= await KeycloakManager.identityProviders.importFromUrl({
|
|
5503
5001
|
fromUrl: "https://accounts.google.com/.well-known/openid-configuration",
|
|
5504
5002
|
providerId: "oidc",
|
|
5505
5003
|
alias: "google",
|
|
@@ -5521,8 +5019,9 @@ When enabled, Keycloak creates client roles (scopes) that let you define which u
|
|
|
5521
5019
|
- realm: [optional] The realm where the IdP is defined.
|
|
5522
5020
|
- other permisssion fields
|
|
5523
5021
|
```js
|
|
5022
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5524
5023
|
// import one permission
|
|
5525
|
-
const updatedPermissions= await
|
|
5024
|
+
const updatedPermissions= await KeycloakManager.identityProviders.updatePermission(
|
|
5526
5025
|
{ alias: "google"},
|
|
5527
5026
|
{ enabled: true }
|
|
5528
5027
|
);
|
|
@@ -5539,8 +5038,9 @@ It returns whether permissions are enabled and, if so, which scope roles are ass
|
|
|
5539
5038
|
- alias: [required] The alias of the Identity Provider.
|
|
5540
5039
|
- realm: [optional] The realm where the IdP is defined.
|
|
5541
5040
|
```js
|
|
5041
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5542
5042
|
// import one permission
|
|
5543
|
-
const permissions= await
|
|
5043
|
+
const permissions= await KeycloakManager.identityProviders.listPermissions({
|
|
5544
5044
|
alias: "google",
|
|
5545
5045
|
realm: "myrealm",
|
|
5546
5046
|
});
|
|
@@ -5559,9 +5059,19 @@ Groups help organize users and assign permissions in a scalable way
|
|
|
5559
5059
|
#### `entity groups functions`
|
|
5560
5060
|
##### `function create(groupRappresentation)`
|
|
5561
5061
|
Create a new group in the current realme
|
|
5062
|
+
@parameters:
|
|
5063
|
+
- groupRepresentation:An object representing the new state of the group. You can update properties such as:
|
|
5064
|
+
- name: [optional] New name of the group
|
|
5065
|
+
- attributes: [optional] Custom attributes up field
|
|
5066
|
+
- path: [optional] full path of the group
|
|
5067
|
+
- subGroups: [optional] List of child groups (can also be updated separately)
|
|
5068
|
+
- description: [optional] the new group Description
|
|
5069
|
+
- {other [optional] group descriprion fields}
|
|
5070
|
+
|
|
5562
5071
|
```js
|
|
5072
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5563
5073
|
// create a group called my-group
|
|
5564
|
-
|
|
5074
|
+
KeycloakManager.groups.create({name: "my-group"});
|
|
5565
5075
|
```
|
|
5566
5076
|
|
|
5567
5077
|
|
|
@@ -5575,13 +5085,14 @@ Searching by attributes is only available from Keycloak > 15
|
|
|
5575
5085
|
- max: A pagination parameter used to define the maximum number of groups to return (limit).
|
|
5576
5086
|
- first: A pagination parameter used to define the number of groups to skip before starting to return results (offset/limit).
|
|
5577
5087
|
```js
|
|
5088
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5578
5089
|
// find a 100 groups
|
|
5579
|
-
const groups = await
|
|
5090
|
+
const groups = await KeycloakManager.groups.find({ max: 100 });
|
|
5580
5091
|
if(groups) console.log('Groups found:', groups);
|
|
5581
5092
|
else console.log('Groups not found');
|
|
5582
5093
|
|
|
5583
5094
|
// find a 100 groups and skip the first 50
|
|
5584
|
-
groups = await
|
|
5095
|
+
groups = await KeycloakManager.groups.find({ max: 100, first:50 });
|
|
5585
5096
|
if(groups) console.log('Groups found:', groups);
|
|
5586
5097
|
else console.log('Groups not found');
|
|
5587
5098
|
```
|
|
@@ -5590,8 +5101,9 @@ else console.log('Groups not found');
|
|
|
5590
5101
|
findOne is method used to retrieve a specific group's details by their unique identifier (id) within a given realm.
|
|
5591
5102
|
It returns the full group representation if the group exists.
|
|
5592
5103
|
```js
|
|
5104
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5593
5105
|
// find a group with id:'group-id'
|
|
5594
|
-
const group = await
|
|
5106
|
+
const group = await KeycloakManager.groups.findOne({ id: 'group-id' });
|
|
5595
5107
|
if(group) console.log('Group found:', group);
|
|
5596
5108
|
else console.log('Group not found');
|
|
5597
5109
|
```
|
|
@@ -5604,8 +5116,9 @@ Return a promise that resolves when the group is successfully deleted. No conten
|
|
|
5604
5116
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
5605
5117
|
- id: The ID of the group to delete.
|
|
5606
5118
|
```js
|
|
5119
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5607
5120
|
// delete a group with id:'group-id'
|
|
5608
|
-
const group = await
|
|
5121
|
+
const group = await KeycloakManager.groups.del({ id: 'group-id' });
|
|
5609
5122
|
```
|
|
5610
5123
|
|
|
5611
5124
|
|
|
@@ -5617,12 +5130,13 @@ This is useful for pagination, reporting, or general statistics regarding group
|
|
|
5617
5130
|
- realm: [optional] The name of the realm. If omitted, the default realm is used.
|
|
5618
5131
|
- search: [optional] A text string to filter the group count by name.
|
|
5619
5132
|
```js
|
|
5133
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5620
5134
|
// count groups
|
|
5621
|
-
const result = await
|
|
5135
|
+
const result = await KeycloakManager.groups.count();
|
|
5622
5136
|
console.log('Total groups:', result.count);
|
|
5623
5137
|
|
|
5624
5138
|
// count groups with filter
|
|
5625
|
-
const result = await
|
|
5139
|
+
const result = await KeycloakManager.groups.count({ search: "cool-group" });
|
|
5626
5140
|
console.log('Total cool-group groups:', result.count);
|
|
5627
5141
|
|
|
5628
5142
|
```
|
|
@@ -5644,8 +5158,9 @@ You can modify the group’s name, attributes, or hierarchy by providing the gro
|
|
|
5644
5158
|
- description: [optional] the new group Description
|
|
5645
5159
|
- other [optional] group descriprion fields
|
|
5646
5160
|
```js
|
|
5161
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5647
5162
|
// update single group
|
|
5648
|
-
await
|
|
5163
|
+
await KeycloakManager.groups.update(
|
|
5649
5164
|
{ id: 'group-id' },
|
|
5650
5165
|
{ name: "another-group-name", description: "another-group-description" },
|
|
5651
5166
|
);
|
|
@@ -5663,8 +5178,9 @@ This method is useful when navigating hierarchical group structures within a Key
|
|
|
5663
5178
|
- briefRepresentation: [optional] If true, returns a lightweight version of each group (default is true).
|
|
5664
5179
|
- realm: [optional] Realm name.
|
|
5665
5180
|
```js
|
|
5181
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5666
5182
|
// list 10 subgroups
|
|
5667
|
-
await
|
|
5183
|
+
await KeycloakManager.groups.listSubGroups({
|
|
5668
5184
|
parentId: 'gropd-id',
|
|
5669
5185
|
first: 0,
|
|
5670
5186
|
max: 10,
|
|
@@ -5683,8 +5199,9 @@ This operation grants all users within that group the associated realm roles, ef
|
|
|
5683
5199
|
- roles: [required] An array of role(RoleRepresentation) objects to assign.
|
|
5684
5200
|
|
|
5685
5201
|
```js
|
|
5202
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5686
5203
|
// add a role to group
|
|
5687
|
-
await
|
|
5204
|
+
await KeycloakManager.groups.addRealmRoleMappings({
|
|
5688
5205
|
id: 'gropd-id',
|
|
5689
5206
|
// at least id and name should appear
|
|
5690
5207
|
roles: [{
|
|
@@ -5706,8 +5223,9 @@ This helps in identifying which roles are still eligible for addition to the gro
|
|
|
5706
5223
|
Return an array of RoleRepresentation objects representing the assignable realm roles for the group.
|
|
5707
5224
|
|
|
5708
5225
|
```js
|
|
5226
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5709
5227
|
// list available role-mappings
|
|
5710
|
-
const availableRoles= await
|
|
5228
|
+
const availableRoles= await KeycloakManager.groups.listAvailableRealmRoleMappings({
|
|
5711
5229
|
id: 'gropd-id'
|
|
5712
5230
|
});
|
|
5713
5231
|
console.log('Available realm roles for group:', availableRoles);
|
|
@@ -5726,8 +5244,9 @@ Return an object with two arrays:
|
|
|
5726
5244
|
- clientMappings: a map of client IDs to the client-level roles assigned for each client.
|
|
5727
5245
|
|
|
5728
5246
|
```js
|
|
5247
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5729
5248
|
// list role-mappings
|
|
5730
|
-
const roleMappings= await
|
|
5249
|
+
const roleMappings= await KeycloakManager.groups.listRoleMappings({
|
|
5731
5250
|
id: 'gropd-id'
|
|
5732
5251
|
});
|
|
5733
5252
|
console.log('Realm roles:', roleMappings.realmMappings);
|
|
@@ -5745,8 +5264,9 @@ These roles are defined at the realm level and are not tied to any specific clie
|
|
|
5745
5264
|
Return An array of RoleRepresentation objects
|
|
5746
5265
|
|
|
5747
5266
|
```js
|
|
5267
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5748
5268
|
// list realm role-mappings of group
|
|
5749
|
-
const realmRoles= await
|
|
5269
|
+
const realmRoles= await KeycloakManager.groups.listRealmRoleMappings({
|
|
5750
5270
|
id: 'gropd-id'
|
|
5751
5271
|
});
|
|
5752
5272
|
console.log('Realm roles assigned to group:', realmRoles.map(role => role.name));
|
|
@@ -5763,8 +5283,9 @@ This includes both directly assigned roles and those inherited through composite
|
|
|
5763
5283
|
Return An array of RoleRepresentation objects that includes all realm roles, both directly assigned and inherited via composite roles.
|
|
5764
5284
|
|
|
5765
5285
|
```js
|
|
5286
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5766
5287
|
// List realm composite role-mappings of group
|
|
5767
|
-
const compositeRealmRoles= await
|
|
5288
|
+
const compositeRealmRoles= await KeycloakManager.groups.listCompositeRealmRoleMappings({
|
|
5768
5289
|
id: 'gropd-id'
|
|
5769
5290
|
});
|
|
5770
5291
|
console.log('All (composite) realm roles for group:', compositeRealmRoles.map(role => role.name));
|
|
@@ -5781,8 +5302,9 @@ Composite roles inherited indirectly will not be removed.
|
|
|
5781
5302
|
- roles: [required] Array of roles to be removed
|
|
5782
5303
|
|
|
5783
5304
|
```js
|
|
5305
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5784
5306
|
// Delete realm role-mappings from group
|
|
5785
|
-
await
|
|
5307
|
+
await KeycloakManager.groups.delRealmRoleMappings({
|
|
5786
5308
|
id: 'gropd-id',
|
|
5787
5309
|
// at least id and name should appear
|
|
5788
5310
|
roles: [{
|
|
@@ -5803,8 +5325,9 @@ This allows all users belonging to that group to inherit the specified roles for
|
|
|
5803
5325
|
- roles: [required] Array of client roles to assign to the group
|
|
5804
5326
|
|
|
5805
5327
|
```js
|
|
5328
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5806
5329
|
// add a client role to group
|
|
5807
|
-
await
|
|
5330
|
+
await KeycloakManager.groups.addClientRoleMappings({
|
|
5808
5331
|
id: 'gropd-id',
|
|
5809
5332
|
clientUniqueId:'internal-client-id',
|
|
5810
5333
|
// at least id and name should appear
|
|
@@ -5825,8 +5348,9 @@ This is useful when you want to show assignable roles for a group in a specific
|
|
|
5825
5348
|
- clientUniqueId: [required] The internal ID of the client
|
|
5826
5349
|
|
|
5827
5350
|
```js
|
|
5351
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5828
5352
|
// list available client role-mappings for group
|
|
5829
|
-
const availableRoles= await
|
|
5353
|
+
const availableRoles= await KeycloakManager.groups.listAvailableClientRoleMappings({
|
|
5830
5354
|
id: 'gropd-id',
|
|
5831
5355
|
clientUniqueId:'internal-client-id',
|
|
5832
5356
|
});
|
|
@@ -5843,8 +5367,9 @@ This allows you to see which roles from a client the group already has.
|
|
|
5843
5367
|
- clientUniqueId: [required] The internal ID of the client
|
|
5844
5368
|
|
|
5845
5369
|
```js
|
|
5370
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5846
5371
|
// list client role-mappings of group
|
|
5847
|
-
const availableRoles= await
|
|
5372
|
+
const availableRoles= await KeycloakManager.groups.listClientRoleMappings({
|
|
5848
5373
|
id: 'gropd-id',
|
|
5849
5374
|
clientUniqueId:'internal-client-id',
|
|
5850
5375
|
});
|
|
@@ -5861,8 +5386,9 @@ Composite roles are roles that aggregate other roles, so this method returns cli
|
|
|
5861
5386
|
- clientUniqueId: [required] The internal ID of the client
|
|
5862
5387
|
|
|
5863
5388
|
```js
|
|
5389
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5864
5390
|
// list composite client role-mappings for group
|
|
5865
|
-
const compositeClientRoles= await
|
|
5391
|
+
const compositeClientRoles= await KeycloakManager.groups.listCompositeClientRoleMappings({
|
|
5866
5392
|
id: 'gropd-id',
|
|
5867
5393
|
clientUniqueId:'internal-client-id',
|
|
5868
5394
|
});
|
|
@@ -5880,8 +5406,9 @@ This function deletes one or more client roles that were assigned to the group,
|
|
|
5880
5406
|
- roles: An array of role objects(RoleRepresentation) representing the client roles to be removed
|
|
5881
5407
|
|
|
5882
5408
|
```js
|
|
5409
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5883
5410
|
// delete the created role
|
|
5884
|
-
await
|
|
5411
|
+
await KeycloakManager.groups.delClientRoleMappings({
|
|
5885
5412
|
id: 'gropd-id',
|
|
5886
5413
|
clientUniqueId:'internal-client-id',
|
|
5887
5414
|
roles: [
|
|
@@ -5905,18 +5432,29 @@ It allows you to create, update, inspect, and delete both realm-level and client
|
|
|
5905
5432
|
##### `function create(role_dictionary)`
|
|
5906
5433
|
Create a new role
|
|
5907
5434
|
```js
|
|
5435
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5908
5436
|
// create a role name called my-role
|
|
5909
|
-
|
|
5437
|
+
KeycloakManager.roles.create({name:'my-role'});
|
|
5910
5438
|
```
|
|
5911
|
-
##### `function createComposite(
|
|
5912
|
-
Create a new composite role
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
as roles from different clients.
|
|
5916
|
-
they automatically inherit all the roles it contains.
|
|
5439
|
+
##### `function createComposite(filters,[roles])`
|
|
5440
|
+
Create a new composite role. Composite roles in Keycloak are roles that combine other roles,
|
|
5441
|
+
allowing you to group multiple permissions into a single, higher-level role.
|
|
5442
|
+
A composite role can include roles from the same realm as well
|
|
5443
|
+
as roles from different clients.
|
|
5444
|
+
When you assign a composite role to a user, they automatically inherit all the roles it contains.
|
|
5445
|
+
@parameters:
|
|
5446
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5447
|
+
- roleId: [required] The id of the role to which composite roles will be added.
|
|
5448
|
+
|
|
5449
|
+
- roles: (Array<RoleRepresentation>) [required] A list of roles to be added as composites. Each RoleRepresentation typically includes:
|
|
5450
|
+
- id: [required] The role’s unique ID.
|
|
5451
|
+
- name: [required] The role’s name.
|
|
5452
|
+
- containerId: [optional] The realm or client that owns the role.
|
|
5453
|
+
- clientRole: [optional] Whether the role belongs to a client.
|
|
5917
5454
|
|
|
5918
5455
|
|
|
5919
5456
|
```js
|
|
5457
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5920
5458
|
// create a composite role where "admin" include anche "reader".
|
|
5921
5459
|
const adminRole = await client.roles.findOneByName({ name: 'admin' });
|
|
5922
5460
|
const readerRole = await client.roles.findOneByName({ name: 'reader' });
|
|
@@ -5924,86 +5462,137 @@ const readerRole = await client.roles.findOneByName({ name: 'reader' });
|
|
|
5924
5462
|
await client.roles.createComposite({ roleId: adminRole.id }, [readerRole]);
|
|
5925
5463
|
```
|
|
5926
5464
|
|
|
5927
|
-
##### `function find()`
|
|
5465
|
+
##### `function find(filters)`
|
|
5928
5466
|
get all realm roles and return a JSON
|
|
5467
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5468
|
+
- name (string, optional): Search string to filter roles by name
|
|
5469
|
+
- realm (string, optional: if set globally in the client): The realm from which to retrieve roles.
|
|
5470
|
+
- first (number, optional): Index of the first result to return (used for pagination).
|
|
5471
|
+
- max (number, optional): Maximum number of results to return.
|
|
5929
5472
|
```js
|
|
5930
|
-
|
|
5473
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5474
|
+
KeycloakManager.roles.find();
|
|
5931
5475
|
```
|
|
5932
|
-
##### `function findOneByName(
|
|
5933
|
-
|
|
5476
|
+
##### `function findOneByName(filters)`
|
|
5477
|
+
Get a role by name
|
|
5478
|
+
@parameters:
|
|
5479
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5480
|
+
- name (string, required) — The exact name of the role to retrieve.
|
|
5481
|
+
- realm (string, optional if set globally) — The realm where the role is defined.
|
|
5934
5482
|
```js
|
|
5483
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5935
5484
|
// get information about 'my-role' role
|
|
5936
|
-
|
|
5485
|
+
KeycloakManager.roles.findOneByName({ name: 'my-role' });
|
|
5937
5486
|
```
|
|
5938
5487
|
|
|
5939
|
-
##### `function findOneById(
|
|
5940
|
-
|
|
5488
|
+
##### `function findOneById(filters)`
|
|
5489
|
+
Get a role by its Id
|
|
5490
|
+
@parameters:
|
|
5491
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5492
|
+
- Id (string, required) — The Id of the role to retrieve.
|
|
5493
|
+
- realm (string, optional if set globally) — The realm where the role is defined.
|
|
5941
5494
|
```js
|
|
5495
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5942
5496
|
// get information about 'my-role-id' role
|
|
5943
|
-
|
|
5497
|
+
KeycloakManager.roles.findOneById({ id: 'my-role-id' });
|
|
5944
5498
|
```
|
|
5945
5499
|
|
|
5946
|
-
##### `function updateByName(
|
|
5947
|
-
|
|
5500
|
+
##### `function updateByName(filters,role_dictionary)`
|
|
5501
|
+
Update a role by its name
|
|
5502
|
+
@parameters:
|
|
5503
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5504
|
+
- name (string, required) — The exact name of the role to retrieve.
|
|
5505
|
+
- realm (string, optional if set globally) — The realm where the role is defined.
|
|
5506
|
+
- role_dictionary: A JSON object representing a role dictionary as defined in Keycloak
|
|
5948
5507
|
```js
|
|
5508
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5949
5509
|
// update 'my-role' role with a new description
|
|
5950
|
-
|
|
5510
|
+
KeycloakManager.roles.updateByName({ name: 'my-role' }, {description:"new Description"});
|
|
5951
5511
|
```
|
|
5952
5512
|
|
|
5953
|
-
##### `function updateById(
|
|
5954
|
-
|
|
5513
|
+
##### `function updateById(filters,role_dictionary)`
|
|
5514
|
+
Update a role by its Id
|
|
5515
|
+
@parameters:
|
|
5516
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5517
|
+
- name (string, required) — The exact name of the role to retrieve.
|
|
5518
|
+
- realm (string, optional if set globally) — The realm where the role is defined.
|
|
5519
|
+
- role_dictionary: A JSON object representing a role dictionary as defined in Keycloak
|
|
5955
5520
|
```js
|
|
5521
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5956
5522
|
// update role by id 'my-role-id' with a new description
|
|
5957
|
-
|
|
5523
|
+
KeycloakManager.roles.updateById({ id: 'my-role-id' }, {description:"new Description"});
|
|
5958
5524
|
```
|
|
5959
5525
|
|
|
5960
|
-
##### `function delByName(
|
|
5961
|
-
|
|
5526
|
+
##### `function delByName(filters)`
|
|
5527
|
+
Delete a role by its name
|
|
5528
|
+
@parameters:
|
|
5529
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5530
|
+
- name (string, required) — The exact name of the role to retrieve.
|
|
5531
|
+
- realm (string, optional if set globally) — The realm where the role is defined.
|
|
5962
5532
|
```js
|
|
5533
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5963
5534
|
// delete role 'my-role'
|
|
5964
|
-
|
|
5535
|
+
KeycloakManager.roles.delByName({ name: 'my-role' });
|
|
5965
5536
|
```
|
|
5966
5537
|
|
|
5967
|
-
##### `function findUsersWithRole(
|
|
5968
|
-
Find all users associated with a specific role
|
|
5538
|
+
##### `function findUsersWithRole(filters)`
|
|
5539
|
+
Find all users associated with a specific role
|
|
5540
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5541
|
+
- name: (string, optional) — The exact name of the role to retrieve.
|
|
5542
|
+
- id: (string, optional) — The Id of the role to retrieve.
|
|
5543
|
+
- realm: (string, optional if set globally) — The realm where the role is defined.
|
|
5969
5544
|
```js
|
|
5545
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5970
5546
|
// Find all users associated with role named 'my-role'
|
|
5971
|
-
|
|
5547
|
+
KeycloakManager.roles.findUsersWithRole({ name: 'my-role' });
|
|
5972
5548
|
```
|
|
5973
5549
|
|
|
5974
|
-
##### `function getCompositeRoles(
|
|
5975
|
-
Find all composite roles associated with a specific
|
|
5550
|
+
##### `function getCompositeRoles(filters)`
|
|
5551
|
+
Find all composite roles associated with a specific role.
|
|
5552
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5553
|
+
- name: (string, optional) — The exact name of the role to retrieve.
|
|
5554
|
+
- id: (string, optional) — The id of the role to retrieve.
|
|
5976
5555
|
```js
|
|
5556
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5977
5557
|
// Find all composite role named 'my-role' and id 'my-role-id'
|
|
5978
|
-
|
|
5558
|
+
KeycloakManager.roles.getCompositeRoles({ id: 'my-role-id' });
|
|
5979
5559
|
```
|
|
5980
5560
|
|
|
5981
5561
|
##### `function getCompositeRolesForRealm({roleId:roleid})`
|
|
5982
|
-
The getCompositeRolesForRealm function is used to
|
|
5983
|
-
|
|
5984
|
-
When a role is defined as composite, it can include other roles either from the same
|
|
5562
|
+
The getCompositeRolesForRealm function is used to retrieve all realm-level roles that are
|
|
5563
|
+
associated with a given composite role.
|
|
5564
|
+
When a role is defined as composite, it can include other roles either from the same
|
|
5985
5565
|
realm or from different clients. This specific method returns only the realm-level roles
|
|
5986
|
-
that have been added to the composite role. It requires the roleId of the target role as a
|
|
5566
|
+
that have been added to the composite role. It requires the roleId of the target role as a
|
|
5987
5567
|
parameter and returns an array of RoleRepresentation objects. If the role is not composite
|
|
5988
|
-
or has no associated realm roles, the result will be an empty array. This method is useful
|
|
5568
|
+
or has no associated realm roles, the result will be an empty array. This method is useful
|
|
5989
5569
|
for understanding and managing hierarchical role structures within a realm in Keycloak.
|
|
5570
|
+
@parameters:
|
|
5571
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5572
|
+
- roleId: (string, required) — The Id of the role to retrieve.
|
|
5990
5573
|
```js
|
|
5991
|
-
const
|
|
5574
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5575
|
+
const compositeRoles = await KeycloakManager.roles.getCompositeRolesForRealm({ roleId: 'role-id' });
|
|
5992
5576
|
console.log('admin composite roles:', compositeRoles.map(r => r.name));
|
|
5993
5577
|
|
|
5994
5578
|
```
|
|
5995
5579
|
|
|
5996
5580
|
##### `function getCompositeRolesForClient({roleId:'roleid', clientId:'clientId'})`
|
|
5997
|
-
The getCompositeRolesForClient function is used to retrieve
|
|
5998
|
-
|
|
5581
|
+
The getCompositeRolesForClient function is used to retrieve all client-level roles that are
|
|
5582
|
+
associated with a given composite role.
|
|
5999
5583
|
Composite roles in Keycloak can include roles from different clients,
|
|
6000
5584
|
and this method specifically returns the roles belonging to a specified client that
|
|
6001
|
-
are part of the composite role. It requires the roleId of the composite role
|
|
5585
|
+
are part of the composite role. It requires the roleId of the composite role
|
|
6002
5586
|
and the clientId of the client whose roles you want to retrieve. The function returns an array of
|
|
6003
|
-
RoleRepresentation objects representing the client roles included in the composite.
|
|
5587
|
+
RoleRepresentation objects representing the client roles included in the composite.
|
|
6004
5588
|
This helps manage and inspect client-specific role hierarchies within the composite role structure in Keycloak.
|
|
5589
|
+
@parameters:
|
|
5590
|
+
- filters: parameter provided as a JSON object that accepts the following parameters:
|
|
5591
|
+
- roleId: (string, required) — The Id of the role to retrieve
|
|
5592
|
+
- clientId: (string, required) — The id of the client to search for composite roles
|
|
6005
5593
|
```js
|
|
6006
|
-
const
|
|
5594
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
5595
|
+
const compositeRoles = await KeycloakManager.roles.getCompositeRolesForClient({
|
|
6007
5596
|
roleId: 'compositeRole-Id',
|
|
6008
5597
|
clientId: 'client-Id'
|
|
6009
5598
|
});
|
|
@@ -6020,7 +5609,7 @@ Components in Keycloak are modular and pluggable, and this API lets you create,
|
|
|
6020
5609
|
|
|
6021
5610
|
#### `entity components functions`
|
|
6022
5611
|
|
|
6023
|
-
##### `function create(
|
|
5612
|
+
##### `function create(componentReppresentation)`
|
|
6024
5613
|
The method creates a new component in a Keycloak realm.
|
|
6025
5614
|
Components are modular providers in Keycloak, such as user federation providers (LDAP, Kerberos), authenticators, identity providers, or other pluggable extensions.
|
|
6026
5615
|
|
|
@@ -6030,10 +5619,16 @@ Components are modular providers in Keycloak, such as user federation providers
|
|
|
6030
5619
|
- providerId: [required] The provider ID (e.g., "ldap", "kerberos", "totp").
|
|
6031
5620
|
- providerType: [required] The type/class of the provider (e.g., "org.keycloak.storage.UserStorageProvider").
|
|
6032
5621
|
- parentId: [optional] The ID of the parent component (if hierarchical).
|
|
6033
|
-
- config: [optional] A map of configuration options, where each property is an array of strings (Keycloak convention).
|
|
6034
|
-
|
|
5622
|
+
- config: [optional] A map of configuration options, where each property is an array of strings (Keycloak convention). Example:
|
|
5623
|
+
- enabled: ["true"],
|
|
5624
|
+
- connectionUrl: ["ldap://ldap.example.com"],
|
|
5625
|
+
- bindDn: ["cn=admin,dc=example,dc=com"],
|
|
5626
|
+
- bindCredential: ["secret"],
|
|
5627
|
+
- usersDn: ["ou=users,dc=example,dc=com"]
|
|
5628
|
+
```js
|
|
5629
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6035
5630
|
// create a component called my-ldap
|
|
6036
|
-
const newComponent= await
|
|
5631
|
+
const newComponent= await KeycloakManager.components.create({
|
|
6037
5632
|
name: "my-ldap",
|
|
6038
5633
|
providerId: "ldap",
|
|
6039
5634
|
providerType: "org.keycloak.storage.UserStorageProvider",
|
|
@@ -6051,22 +5646,29 @@ console.log("Created component:", newComponent);
|
|
|
6051
5646
|
```
|
|
6052
5647
|
|
|
6053
5648
|
|
|
6054
|
-
##### `function update(
|
|
5649
|
+
##### `function update(componentReppresentation)`
|
|
6055
5650
|
The method updates an existing component in a Keycloak realm.
|
|
6056
|
-
Components represent pluggable extensions such as user federation providers (LDAP, Kerberos),
|
|
5651
|
+
Components represent pluggable extensions such as user federation providers (LDAP, Kerberos),
|
|
5652
|
+
protocol mappers, authenticator factories, or other custom integrations.
|
|
6057
5653
|
|
|
6058
5654
|
@parameters:
|
|
6059
5655
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6060
|
-
|
|
6061
|
-
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
5656
|
+
- id: [required] The unique ID of the component to update.
|
|
5657
|
+
- componentRepresentation: An object representing the component to update.
|
|
5658
|
+
- name: [required] A human-readable name for the component.
|
|
5659
|
+
- providerId: [required] The provider ID (e.g., "ldap", "kerberos", "totp").
|
|
5660
|
+
- providerType: [required] The type/class of the provider (e.g., "org.keycloak.storage.UserStorageProvider").
|
|
5661
|
+
- parentId: [optional] The ID of the parent component (if hierarchical).
|
|
5662
|
+
- config: [optional] A map of configuration options, where each property is an array of strings (Keycloak convention). Example:
|
|
5663
|
+
- enabled: ["true"],
|
|
5664
|
+
- connectionUrl: ["ldap://ldap.example.com"],
|
|
5665
|
+
- bindDn: ["cn=admin,dc=example,dc=com"],
|
|
5666
|
+
- bindCredential: ["secret"],
|
|
5667
|
+
- usersDn: ["ou=users,dc=example,dc=com"]
|
|
5668
|
+
```js
|
|
5669
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6068
5670
|
// update a component
|
|
6069
|
-
await
|
|
5671
|
+
await KeycloakManager.components.update(
|
|
6070
5672
|
{id:'component-id'},
|
|
6071
5673
|
{
|
|
6072
5674
|
name: "my-ldap",
|
|
@@ -6094,8 +5696,9 @@ Components in Keycloak represent pluggable providers such as LDAP user federatio
|
|
|
6094
5696
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6095
5697
|
- id: [required] The unique ID of the component to retrieve.
|
|
6096
5698
|
```js
|
|
5699
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6097
5700
|
// find one by Id
|
|
6098
|
-
component = await
|
|
5701
|
+
component = await KeycloakManager.components.findOne({
|
|
6099
5702
|
id: "component-id",
|
|
6100
5703
|
});
|
|
6101
5704
|
|
|
@@ -6117,8 +5720,9 @@ You can optionally filter components by their parent ID and/or provider type (e.
|
|
|
6117
5720
|
- max: A pagination parameter used to define the maximum number of components to return (limit).
|
|
6118
5721
|
- first: A pagination parameter used to define the number of components to skip before starting to return results (offset/limit).
|
|
6119
5722
|
```js
|
|
5723
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6120
5724
|
// find by Id
|
|
6121
|
-
component = await
|
|
5725
|
+
component = await KeycloakManager.components.find({
|
|
6122
5726
|
id: "component-id",
|
|
6123
5727
|
});
|
|
6124
5728
|
|
|
@@ -6139,8 +5743,9 @@ Components include user federation providers (e.g., LDAP, Kerberos), authenticat
|
|
|
6139
5743
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6140
5744
|
- id: [required] The unique ID of the component to delete.
|
|
6141
5745
|
```js
|
|
5746
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6142
5747
|
// del one by Id
|
|
6143
|
-
await
|
|
5748
|
+
await KeycloakManager.components.del({
|
|
6144
5749
|
id: "component-id",
|
|
6145
5750
|
});
|
|
6146
5751
|
|
|
@@ -6159,8 +5764,9 @@ This is useful when working with hierarchical components, for example:
|
|
|
6159
5764
|
- id: [required] The ID of the parent component.
|
|
6160
5765
|
- type: [optional] Filters sub-components by their provider type (e.g., "org.keycloak.protocol.mapper.ProtocolMapper").
|
|
6161
5766
|
```js
|
|
5767
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6162
5768
|
// del one by Id
|
|
6163
|
-
const subComponents= await
|
|
5769
|
+
const subComponents= await KeycloakManager.components.listSubComponents({
|
|
6164
5770
|
id: "component-id",
|
|
6165
5771
|
type: "org.keycloak.protocol.mapper.ProtocolMapper",
|
|
6166
5772
|
});
|
|
@@ -6200,8 +5806,9 @@ By deleting a required action, it will no longer be available for assignment to
|
|
|
6200
5806
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6201
5807
|
- alias: [required] The unique alias of the required action to delete (e.g., "UPDATE_PASSWORD").
|
|
6202
5808
|
```js
|
|
5809
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6203
5810
|
// del one by Id
|
|
6204
|
-
const subComponents= await
|
|
5811
|
+
const subComponents= await KeycloakManager.authenticationManagement.deleteRequiredAction({
|
|
6205
5812
|
alias: "UPDATE_PROFILE",
|
|
6206
5813
|
});
|
|
6207
5814
|
|
|
@@ -6225,8 +5832,9 @@ This method is typically used after checking available actions via getUnregister
|
|
|
6225
5832
|
- priority: [optional] Determines the execution order among required actions.
|
|
6226
5833
|
- config: [optional] Extra configuration options (usually empty for built-in actions).
|
|
6227
5834
|
```js
|
|
5835
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6228
5836
|
// register required action
|
|
6229
|
-
const subComponents= await
|
|
5837
|
+
const subComponents= await KeycloakManager.authenticationManagement.registerRequiredAction({
|
|
6230
5838
|
providerId: "terms_and_conditions",
|
|
6231
5839
|
name: "Terms and Conditions",
|
|
6232
5840
|
description: "Require user to accept terms before continuing",
|
|
@@ -6246,8 +5854,9 @@ The method retrieves all available required actions that exist in Keycloak but a
|
|
|
6246
5854
|
This is useful if you want to see which built-in or custom required actions can still be added to the realm (e.g., custom scripts, OTP setup, email verification).
|
|
6247
5855
|
|
|
6248
5856
|
```js
|
|
5857
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6249
5858
|
// get unregistered required actions
|
|
6250
|
-
const unregistered= await
|
|
5859
|
+
const unregistered= await KeycloakManager.authenticationManagement.getUnregisteredRequiredActions();
|
|
6251
5860
|
|
|
6252
5861
|
console.log("Unregistered required actions:", unregistered);
|
|
6253
5862
|
|
|
@@ -6263,8 +5872,9 @@ Required actions are tasks that users may be required to perform during authenti
|
|
|
6263
5872
|
- others...
|
|
6264
5873
|
|
|
6265
5874
|
```js
|
|
5875
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6266
5876
|
// get required actions
|
|
6267
|
-
const requiredActions= await
|
|
5877
|
+
const requiredActions= await KeycloakManager.authenticationManagement.getRequiredActions();
|
|
6268
5878
|
|
|
6269
5879
|
console.log("Registered required actions:", requiredActions);
|
|
6270
5880
|
|
|
@@ -6279,8 +5889,9 @@ This method is useful when you want details about a specific required action wit
|
|
|
6279
5889
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6280
5890
|
- alias: [required] The unique alias of the required action to retrieve (e.g., "UPDATE_PASSWORD").
|
|
6281
5891
|
```js
|
|
5892
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6282
5893
|
// get required action for alias
|
|
6283
|
-
const requiredAction= await
|
|
5894
|
+
const requiredAction= await KeycloakManager.authenticationManagement.getRequiredActionForAlias({
|
|
6284
5895
|
alias:'UPDATE_PASSWORD'
|
|
6285
5896
|
});
|
|
6286
5897
|
|
|
@@ -6296,8 +5907,9 @@ Priority determines the order in which required actions are executed for a user
|
|
|
6296
5907
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6297
5908
|
- alias: [required] The alias (providerId) of the required action to modify.
|
|
6298
5909
|
```js
|
|
5910
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6299
5911
|
// Lower required action priority
|
|
6300
|
-
await
|
|
5912
|
+
await KeycloakManager.authenticationManagement.lowerRequiredActionPriority({
|
|
6301
5913
|
alias:'UPDATE_PASSWORD'
|
|
6302
5914
|
});
|
|
6303
5915
|
|
|
@@ -6314,8 +5926,9 @@ Raising the priority moves the action higher in the execution order, meaning it
|
|
|
6314
5926
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6315
5927
|
- alias: [required] The alias (providerId) of the required action to modify.
|
|
6316
5928
|
```js
|
|
5929
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6317
5930
|
// raise required action priority
|
|
6318
|
-
await
|
|
5931
|
+
await KeycloakManager.authenticationManagement.raiseRequiredActionPriority({
|
|
6319
5932
|
alias:'UPDATE_PASSWORD'
|
|
6320
5933
|
});
|
|
6321
5934
|
|
|
@@ -6331,8 +5944,9 @@ This includes details about the configurable options available for that required
|
|
|
6331
5944
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6332
5945
|
- alias: [required] The alias (providerId) of the required action.
|
|
6333
5946
|
```js
|
|
5947
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6334
5948
|
// Get required action config description
|
|
6335
|
-
const configDescription= await
|
|
5949
|
+
const configDescription= await KeycloakManager.authenticationManagement.getRequiredActionConfigDescription({
|
|
6336
5950
|
alias: "CONFIGURE_OTP",
|
|
6337
5951
|
});
|
|
6338
5952
|
|
|
@@ -6349,8 +5963,9 @@ This allows you to see the settings that have been applied to a required action,
|
|
|
6349
5963
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6350
5964
|
- alias: [required] The alias (providerId) of the required action.
|
|
6351
5965
|
```js
|
|
5966
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6352
5967
|
// Get required action config
|
|
6353
|
-
const config= await
|
|
5968
|
+
const config= await KeycloakManager.authenticationManagement.getRequiredActionConfig({
|
|
6354
5969
|
alias: "CONFIGURE_OTP",
|
|
6355
5970
|
});
|
|
6356
5971
|
|
|
@@ -6366,8 +5981,9 @@ This removes any customized settings for the action, effectively resetting it to
|
|
|
6366
5981
|
- filter: parameter provided as a JSON object that accepts the following filter:
|
|
6367
5982
|
- alias: [required] The alias (providerId) of the required action.
|
|
6368
5983
|
```js
|
|
5984
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6369
5985
|
// Remove required action config
|
|
6370
|
-
await
|
|
5986
|
+
await KeycloakManager.authenticationManagement.removeRequiredActionConfig({
|
|
6371
5987
|
alias: "CONFIGURE_OTP",
|
|
6372
5988
|
});
|
|
6373
5989
|
|
|
@@ -6399,8 +6015,9 @@ This method allows you to modify attributes such as enabled, defaultAction, prio
|
|
|
6399
6015
|
- config: [optional] Extra configuration.
|
|
6400
6016
|
|
|
6401
6017
|
```js
|
|
6018
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6402
6019
|
// update required action
|
|
6403
|
-
const requiredAction= await
|
|
6020
|
+
const requiredAction= await KeycloakManager.authenticationManagement.updateRequiredAction(
|
|
6404
6021
|
{ alias: "VERIFY_EMAIL" },
|
|
6405
6022
|
{
|
|
6406
6023
|
providerId: "VERIFY_EMAIL",
|
|
@@ -6428,8 +6045,9 @@ This allows you to modify settings such as OTP policies, password requirements,
|
|
|
6428
6045
|
|
|
6429
6046
|
|
|
6430
6047
|
```js
|
|
6048
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6431
6049
|
// update required action config
|
|
6432
|
-
const requiredAction= await
|
|
6050
|
+
const requiredAction= await KeycloakManager.authenticationManagement.updateRequiredActionConfig(
|
|
6433
6051
|
{ alias: "VERIFY_EMAIL" },
|
|
6434
6052
|
{
|
|
6435
6053
|
max_auth_age: "301",
|
|
@@ -6454,8 +6072,9 @@ This method is useful for configuring client authentication flows and assigning
|
|
|
6454
6072
|
|
|
6455
6073
|
|
|
6456
6074
|
```js
|
|
6075
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6457
6076
|
// Get client authenticator providers
|
|
6458
|
-
const clientAuthenticators= await
|
|
6077
|
+
const clientAuthenticators= await KeycloakManager.authenticationManagement.getClientAuthenticatorProviders();
|
|
6459
6078
|
|
|
6460
6079
|
console.log("Client authenticator providers:", clientAuthenticators);
|
|
6461
6080
|
|
|
@@ -6473,8 +6092,9 @@ Form action providers are used during authentication flows to perform specific a
|
|
|
6473
6092
|
This method is useful for configuring authentication flows that require specific user interactions.
|
|
6474
6093
|
|
|
6475
6094
|
```js
|
|
6095
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6476
6096
|
// Get form action providers
|
|
6477
|
-
const formActions= await
|
|
6097
|
+
const formActions= await KeycloakManager.authenticationManagement.getFormActionProviders();
|
|
6478
6098
|
|
|
6479
6099
|
console.log("Form action providers:", formActions);
|
|
6480
6100
|
|
|
@@ -6491,8 +6111,9 @@ Authenticators are used in authentication flows to verify users or perform speci
|
|
|
6491
6111
|
This method is useful for configuring authentication flows and adding or replacing authenticators.
|
|
6492
6112
|
|
|
6493
6113
|
```js
|
|
6114
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6494
6115
|
// Get authenticator providers
|
|
6495
|
-
const authenticators= await
|
|
6116
|
+
const authenticators= await KeycloakManager.authenticationManagement.getAuthenticatorProviders();
|
|
6496
6117
|
|
|
6497
6118
|
|
|
6498
6119
|
console.log("Authenticator providers:", authenticators);
|
|
@@ -6511,8 +6132,9 @@ Form providers are used in authentication flows to render or handle user-facing
|
|
|
6511
6132
|
This method is useful for configuring authentication flows that require user interaction through forms.
|
|
6512
6133
|
|
|
6513
6134
|
```js
|
|
6135
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6514
6136
|
// Get form providers
|
|
6515
|
-
const forms= await
|
|
6137
|
+
const forms= await KeycloakManager.authenticationManagement.getFormProviders();
|
|
6516
6138
|
|
|
6517
6139
|
|
|
6518
6140
|
|
|
@@ -6527,8 +6149,9 @@ Authentication flows define the sequence of authenticators and required actions
|
|
|
6527
6149
|
This method allows you to inspect existing flows, including built-in flows like browser, direct grant, or registration, as well as custom flows.
|
|
6528
6150
|
|
|
6529
6151
|
```js
|
|
6152
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6530
6153
|
// Get flows
|
|
6531
|
-
const flows= await
|
|
6154
|
+
const flows= await KeycloakManager.authenticationManagement.getFlows();
|
|
6532
6155
|
|
|
6533
6156
|
console.log("Authentication flows:", flows);
|
|
6534
6157
|
|
|
@@ -6549,8 +6172,9 @@ This method is useful for inspecting or modifying a particular flow.
|
|
|
6549
6172
|
- authenticationExecutions: [optional] Executions to include in the flow.
|
|
6550
6173
|
|
|
6551
6174
|
```js
|
|
6175
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6552
6176
|
// Create flow
|
|
6553
|
-
await
|
|
6177
|
+
await KeycloakManager.authenticationManagement.createFlow({
|
|
6554
6178
|
alias: "custom-browser-flow",
|
|
6555
6179
|
description: "Custom browser authentication flow",
|
|
6556
6180
|
providerId: "basic-flow",
|
|
@@ -6580,8 +6204,9 @@ filter: Parameter provided as a JSON object that accepts the following filter:
|
|
|
6580
6204
|
- authenticationExecutions: [optional] Executions to include in the flow.
|
|
6581
6205
|
|
|
6582
6206
|
```js
|
|
6207
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6583
6208
|
// Update flow
|
|
6584
|
-
await
|
|
6209
|
+
await KeycloakManager.authenticationManagement.updateFlow(
|
|
6585
6210
|
{ flowId:'flow-id' },
|
|
6586
6211
|
{
|
|
6587
6212
|
alias: "custom-browser-flow",
|
|
@@ -6608,8 +6233,9 @@ filter: Parameter provided as a JSON object that accepts the following filter:
|
|
|
6608
6233
|
- flowId: [required] The id of the source flow to update.
|
|
6609
6234
|
|
|
6610
6235
|
```js
|
|
6236
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6611
6237
|
// Delete flow
|
|
6612
|
-
await
|
|
6238
|
+
await KeycloakManager.authenticationManagement.deleteFlow({
|
|
6613
6239
|
flowId:'flow-id'
|
|
6614
6240
|
});
|
|
6615
6241
|
|
|
@@ -6627,8 +6253,9 @@ This is useful for creating a custom flow based on an existing built-in or custo
|
|
|
6627
6253
|
- newName: [required] The alias of the new copied flow.
|
|
6628
6254
|
|
|
6629
6255
|
```js
|
|
6256
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6630
6257
|
// Copy flow
|
|
6631
|
-
await
|
|
6258
|
+
await KeycloakManager.authenticationManagement.copyFlow({
|
|
6632
6259
|
flow: "browser",
|
|
6633
6260
|
newName: "custom-browser-flow"
|
|
6634
6261
|
});
|
|
@@ -6648,8 +6275,9 @@ This method is useful for inspecting or modifying a particular flow.
|
|
|
6648
6275
|
- flowId: [required] The id of the authentication flow to retrieve
|
|
6649
6276
|
|
|
6650
6277
|
```js
|
|
6278
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6651
6279
|
// Get flows
|
|
6652
|
-
const flow= await
|
|
6280
|
+
const flow= await KeycloakManager.authenticationManagement.getFlow({
|
|
6653
6281
|
flowId:'flow.id'
|
|
6654
6282
|
});
|
|
6655
6283
|
|
|
@@ -6672,8 +6300,9 @@ This method is useful to inspect or modify the steps of a flow.
|
|
|
6672
6300
|
- flow: [required] The alias of the authentication flow whose executions you want to retrieve.
|
|
6673
6301
|
|
|
6674
6302
|
```js
|
|
6303
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6675
6304
|
// Get executions
|
|
6676
|
-
const executions= await
|
|
6305
|
+
const executions= await KeycloakManager.authenticationManagement.getExecutions({
|
|
6677
6306
|
flow:'browser'
|
|
6678
6307
|
});
|
|
6679
6308
|
|
|
@@ -6697,8 +6326,9 @@ This method allows you to extend a flow with additional steps or subflows.
|
|
|
6697
6326
|
- authenticatorFlow: [optional] Boolean indicating if the execution is a nested flow
|
|
6698
6327
|
|
|
6699
6328
|
```js
|
|
6329
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6700
6330
|
// add execution to flow
|
|
6701
|
-
await
|
|
6331
|
+
await KeycloakManager.authenticationManagement.addExecutionToFlow({
|
|
6702
6332
|
flow: "browser",
|
|
6703
6333
|
provider: "auth-otp-form",
|
|
6704
6334
|
});
|
|
@@ -6720,8 +6350,9 @@ This allows you to nest flows, creating complex authentication sequences where o
|
|
|
6720
6350
|
- description: [optional] A human-readable description of the subflow.
|
|
6721
6351
|
|
|
6722
6352
|
```js
|
|
6353
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6723
6354
|
// add flow to flow
|
|
6724
|
-
const flow= await
|
|
6355
|
+
const flow= await KeycloakManager.authenticationManagement.addFlowToFlow({
|
|
6725
6356
|
flow: "browser",
|
|
6726
6357
|
alias: "subFlow",
|
|
6727
6358
|
description: "",
|
|
@@ -6750,8 +6381,9 @@ Executions are individual authenticators or subflows within a flow, and this met
|
|
|
6750
6381
|
|
|
6751
6382
|
|
|
6752
6383
|
```js
|
|
6384
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6753
6385
|
// Update execution
|
|
6754
|
-
await
|
|
6386
|
+
await KeycloakManager.authenticationManagement.updateExecution(
|
|
6755
6387
|
{ flow: "browser" },
|
|
6756
6388
|
{
|
|
6757
6389
|
id: "exec1-abc",
|
|
@@ -6775,8 +6407,9 @@ Executions are individual authenticators or subflows within a flow, and this met
|
|
|
6775
6407
|
|
|
6776
6408
|
|
|
6777
6409
|
```js
|
|
6410
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6778
6411
|
// Dell execution
|
|
6779
|
-
await
|
|
6412
|
+
await KeycloakManager.authenticationManagement.delExecution({
|
|
6780
6413
|
id: "exececution-id"
|
|
6781
6414
|
});
|
|
6782
6415
|
|
|
@@ -6795,8 +6428,9 @@ Increasing the priority moves the execution earlier in the flow sequence, affect
|
|
|
6795
6428
|
|
|
6796
6429
|
|
|
6797
6430
|
```js
|
|
6431
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6798
6432
|
// raise priority execution
|
|
6799
|
-
await
|
|
6433
|
+
await KeycloakManager.authenticationManagement.raisePriorityExecution({
|
|
6800
6434
|
id: "exececution-id"
|
|
6801
6435
|
});
|
|
6802
6436
|
|
|
@@ -6814,8 +6448,9 @@ Lowering the priority moves the execution later in the flow sequence, affecting
|
|
|
6814
6448
|
|
|
6815
6449
|
|
|
6816
6450
|
```js
|
|
6451
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6817
6452
|
// lower priority execution
|
|
6818
|
-
await
|
|
6453
|
+
await KeycloakManager.authenticationManagement.lowerPriorityExecution({
|
|
6819
6454
|
id: "exececution-id"
|
|
6820
6455
|
});
|
|
6821
6456
|
|
|
@@ -6835,8 +6470,9 @@ Configurations allow you to customize the behavior of an authenticator or requir
|
|
|
6835
6470
|
|
|
6836
6471
|
|
|
6837
6472
|
```js
|
|
6473
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6838
6474
|
// Create config
|
|
6839
|
-
const config= await
|
|
6475
|
+
const config= await KeycloakManager.authenticationManagement.createConfig({
|
|
6840
6476
|
id: 'execution-id',
|
|
6841
6477
|
alias: "test",
|
|
6842
6478
|
});
|
|
@@ -6855,8 +6491,9 @@ Configurations define additional settings for authenticators or required actions
|
|
|
6855
6491
|
|
|
6856
6492
|
|
|
6857
6493
|
```js
|
|
6494
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6858
6495
|
// Get config
|
|
6859
|
-
const config= await
|
|
6496
|
+
const config= await KeycloakManager.authenticationManagement.getConfig({
|
|
6860
6497
|
id: 'execution-id',
|
|
6861
6498
|
});
|
|
6862
6499
|
|
|
@@ -6876,8 +6513,9 @@ This allows you to modify existing settings, such as OTP policies, password rule
|
|
|
6876
6513
|
|
|
6877
6514
|
|
|
6878
6515
|
```js
|
|
6516
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6879
6517
|
// Update config
|
|
6880
|
-
await
|
|
6518
|
+
await KeycloakManager.authenticationManagement.updateConfig({
|
|
6881
6519
|
id: 'config-id',
|
|
6882
6520
|
config:{
|
|
6883
6521
|
defaultProvider: "stringa"
|
|
@@ -6899,8 +6537,9 @@ This is useful for removing obsolete or unwanted settings from a required action
|
|
|
6899
6537
|
|
|
6900
6538
|
|
|
6901
6539
|
```js
|
|
6540
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6902
6541
|
// del config
|
|
6903
|
-
await
|
|
6542
|
+
await KeycloakManager.authenticationManagement.delConfig({
|
|
6904
6543
|
id: 'config-id',
|
|
6905
6544
|
});
|
|
6906
6545
|
|
|
@@ -6926,8 +6565,9 @@ This is useful for dynamically generating forms for configuring required actions
|
|
|
6926
6565
|
|
|
6927
6566
|
|
|
6928
6567
|
```js
|
|
6568
|
+
const KeycloakManager = require('keycloak-api-manager');
|
|
6929
6569
|
// Get config description
|
|
6930
|
-
const configDescription= await
|
|
6570
|
+
const configDescription= await KeycloakManager.authenticationManagement.getConfigDescription({
|
|
6931
6571
|
providerId: 'provider-id',
|
|
6932
6572
|
});
|
|
6933
6573
|
|