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
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **************************************************************************************************
|
|
3
|
+
* **************************************************************************************************
|
|
4
|
+
* The components entity allows you to manage Keycloak components, which are configuration entities
|
|
5
|
+
* such as user federation providers, authenticators, protocol mappers, themes, and more.
|
|
6
|
+
* Components in Keycloak are modular and pluggable, and this API lets you create, read, update,
|
|
7
|
+
* and delete them programmatically.
|
|
8
|
+
* **************************************************************************************************
|
|
9
|
+
* **************************************************************************************************
|
|
10
|
+
*/
|
|
11
|
+
let kcAdminClientHandler=null;
|
|
12
|
+
exports.setKcAdminClient=function(kcAdminClient){
|
|
13
|
+
kcAdminClientHandler=kcAdminClient;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* ***************************** - CREATE - *******************************
|
|
19
|
+
* The method creates a new component in a Keycloak realm.
|
|
20
|
+
* Components are modular providers in Keycloak, such as user federation providers (LDAP, Kerberos), authenticators, identity providers, or other pluggable extensions.
|
|
21
|
+
*
|
|
22
|
+
* @parameters:
|
|
23
|
+
* - componentRepresentation: An object representing the component to create.
|
|
24
|
+
* - name: [required] A human-readable name for the component.
|
|
25
|
+
* - providerId: [required] The provider ID (e.g., "ldap", "kerberos", "totp").
|
|
26
|
+
* - providerType: [required] The type/class of the provider (e.g., "org.keycloak.storage.UserStorageProvider").
|
|
27
|
+
* - parentId: [optional] The ID of the parent component (if hierarchical).
|
|
28
|
+
* - config: [optional] A map of configuration options, where each property is an array of strings (Keycloak convention). Example:
|
|
29
|
+
* - enabled: ["true"],
|
|
30
|
+
* - connectionUrl: ["ldap://ldap.example.com"],
|
|
31
|
+
* - bindDn: ["cn=admin,dc=example,dc=com"],
|
|
32
|
+
* - bindCredential: ["secret"],
|
|
33
|
+
* - usersDn: ["ou=users,dc=example,dc=com"]
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
exports.create=function(componentRepresentation){
|
|
37
|
+
return (kcAdminClientHandler.components.create(componentRepresentation));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* ***************************** - update - *******************************
|
|
44
|
+
* The method updates an existing component in a Keycloak realm.
|
|
45
|
+
* Components represent pluggable extensions such as user federation providers (LDAP, Kerberos),
|
|
46
|
+
* protocol mappers, authenticator factories, or other custom integrations.
|
|
47
|
+
*
|
|
48
|
+
* @parameters:
|
|
49
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
50
|
+
* - id: [required] The unique ID of the component to update.
|
|
51
|
+
* - componentRepresentation: An object representing the component to update.
|
|
52
|
+
* - name: [required] A human-readable name for the component.
|
|
53
|
+
* - providerId: [required] The provider ID (e.g., "ldap", "kerberos", "totp").
|
|
54
|
+
* - providerType: [required] The type/class of the provider (e.g., "org.keycloak.storage.UserStorageProvider").
|
|
55
|
+
* - parentId: [optional] The ID of the parent component (if hierarchical).
|
|
56
|
+
* - config: [optional] A map of configuration options, where each property is an array of strings (Keycloak convention). Example:
|
|
57
|
+
* - enabled: ["true"],
|
|
58
|
+
* - connectionUrl: ["ldap://ldap.example.com"],
|
|
59
|
+
* - bindDn: ["cn=admin,dc=example,dc=com"],
|
|
60
|
+
* - bindCredential: ["secret"],
|
|
61
|
+
* - usersDn: ["ou=users,dc=example,dc=com"]
|
|
62
|
+
*/
|
|
63
|
+
exports.update=function(filters, componentRepresentation){
|
|
64
|
+
return (kcAdminClientHandler.components.update(filters, componentRepresentation));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* ***************************** - findOne - *******************************
|
|
72
|
+
* The method retrieves a single component from a realm by its ID.
|
|
73
|
+
* Components in Keycloak represent pluggable providers such as LDAP user federation, authenticators, protocol mappers, or other extensions.
|
|
74
|
+
*
|
|
75
|
+
* @parameters:
|
|
76
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
77
|
+
* - id: [required] The unique ID of the component to retrieve.
|
|
78
|
+
*/
|
|
79
|
+
exports.findOne=function(filter){
|
|
80
|
+
return (kcAdminClientHandler.components.findOne(filter));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* ***************************** - find - *******************************
|
|
87
|
+
* The method retrieves a list of components in a Keycloak realm.
|
|
88
|
+
* You can optionally filter components by their parent ID and/or provider type (e.g., LDAP user federation providers, authenticators, protocol mappers).
|
|
89
|
+
*
|
|
90
|
+
* @parameters:
|
|
91
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
92
|
+
* - {builtin attribute}: To find components by builtin attributes such as name, id
|
|
93
|
+
* - max: A pagination parameter used to define the maximum number of components to return (limit).
|
|
94
|
+
* - first: A pagination parameter used to define the number of components to skip before starting to return results (offset/limit).
|
|
95
|
+
*/
|
|
96
|
+
exports.find=function(filter){
|
|
97
|
+
return (kcAdminClientHandler.components.find(filter));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* ***************************** - del - *******************************
|
|
104
|
+
* The method deletes a specific component from a Keycloak realm.
|
|
105
|
+
* Components include user federation providers (e.g., LDAP, Kerberos), authenticator providers, protocol mappers, or other pluggable extensions.
|
|
106
|
+
*
|
|
107
|
+
* @parameters:
|
|
108
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
109
|
+
* - id: [required] The unique ID of the component to delete.
|
|
110
|
+
*/
|
|
111
|
+
exports.del=function(filter){
|
|
112
|
+
return (kcAdminClientHandler.components.del(filter));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* ***************************** - listSubComponents - *******************************
|
|
118
|
+
* The method retrieves all sub-components of a given parent component in a Keycloak realm.
|
|
119
|
+
* This is useful when working with hierarchical components, for example:
|
|
120
|
+
* - LDAP storage provider and protocol mappers as sub-components
|
|
121
|
+
* - Authenticator factories with nested components
|
|
122
|
+
*
|
|
123
|
+
* @parameters:
|
|
124
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
125
|
+
* - id: [required] The ID of the parent component.
|
|
126
|
+
* - type: [optional] Filters sub-components by their provider type (e.g., "org.keycloak.protocol.mapper.ProtocolMapper").
|
|
127
|
+
*/
|
|
128
|
+
exports.listSubComponents=function(filter){
|
|
129
|
+
return (kcAdminClientHandler.components.listSubComponents(filter));
|
|
130
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
const Keycloak = require("keycloak-connect");
|
|
2
|
+
/**
|
|
3
|
+
* **************************************************************************************************
|
|
4
|
+
* **************************************************************************************************
|
|
5
|
+
* The groups entity allows you to manage groups in a Keycloak realm.
|
|
6
|
+
* Groups are collections of users and can have roles and attributes assigned to them.
|
|
7
|
+
* Groups help organize users and assign permissions in a scalable way
|
|
8
|
+
* **************************************************************************************************
|
|
9
|
+
* **************************************************************************************************
|
|
10
|
+
*/
|
|
11
|
+
let kcAdminClientHandler=null;
|
|
12
|
+
exports.setKcAdminClient=function(kcAdminClient){
|
|
13
|
+
kcAdminClientHandler=kcAdminClient;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* ***************************** - CREATE - *******************************
|
|
18
|
+
* Create a new group in the current realme
|
|
19
|
+
* @parameters:
|
|
20
|
+
* - groupRepresentation:An object representing the new state of the group. You can update properties such as:
|
|
21
|
+
* - name: [optional] New name of the group
|
|
22
|
+
* - attributes: [optional] Custom attributes up field
|
|
23
|
+
* - path: [optional] full path of the group
|
|
24
|
+
* - subGroups: [optional] List of child groups (can also be updated separately)
|
|
25
|
+
* - description: [optional] the new group Description
|
|
26
|
+
* - {other [optional] group description fields}
|
|
27
|
+
*/
|
|
28
|
+
exports.create=function(groupRappresentation){
|
|
29
|
+
return (kcAdminClientHandler.groups.create(groupRappresentation));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ***************************** - find - *******************************
|
|
36
|
+
* find method is used to retrieve a list of groups in a specific realm.
|
|
37
|
+
* It supports optional filtering parameters.
|
|
38
|
+
* Searching by attributes is only available from Keycloak > 15
|
|
39
|
+
* @parameters:
|
|
40
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
41
|
+
* - {builtin attribute}: To find groups by builtin attributes such as name, id
|
|
42
|
+
* - max: A pagination parameter used to define the maximum number of groups to return (limit).
|
|
43
|
+
* - first: A pagination parameter used to define the number of groups to skip before starting to return results (offset/limit).
|
|
44
|
+
*/
|
|
45
|
+
exports.find=function(filter){
|
|
46
|
+
return (kcAdminClientHandler.groups.find(filter));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* ***************************** - findOne - *******************************
|
|
51
|
+
* findOne is method used to retrieve a specific group's details by their unique identifier (id) within a given realm.
|
|
52
|
+
* It returns the full group representation if the group exists.
|
|
53
|
+
* @parameters
|
|
54
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
55
|
+
* -id: the group id
|
|
56
|
+
*/
|
|
57
|
+
exports.findOne=function(filter){
|
|
58
|
+
return (kcAdminClientHandler.groups.findOne(filter));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* ***************************** - del - *******************************
|
|
64
|
+
* Deletes a group from the realm.
|
|
65
|
+
* Return a promise that resolves when the group is successfully deleted. No content is returned on success.
|
|
66
|
+
* @parameters:
|
|
67
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
68
|
+
* - id: The ID of the group to delete
|
|
69
|
+
*/
|
|
70
|
+
exports.del=function(filter){
|
|
71
|
+
return (kcAdminClientHandler.groups.del(filter));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* ***************************** - count - *******************************
|
|
77
|
+
* Retrieves the total number of groups present in the specified realm.
|
|
78
|
+
* This is useful for pagination, reporting, or general statistics regarding group usage in a Keycloak realm.
|
|
79
|
+
* @parameters:
|
|
80
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
81
|
+
* - realm: [optional] The name of the realm. If omitted, the default realm is used.
|
|
82
|
+
* - search: [optional] A text string to filter the group count by name
|
|
83
|
+
*/
|
|
84
|
+
exports.count=function(filter){
|
|
85
|
+
return (kcAdminClientHandler.groups.count(filter));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* ***************************** - update - *******************************
|
|
91
|
+
* Updates an existing group’s information in a Keycloak realm.
|
|
92
|
+
* You can modify the group’s name, attributes, or hierarchy by providing the group ID and the updated data.
|
|
93
|
+
* @parameters:
|
|
94
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
95
|
+
* - id: [required] The unique ID of the group you want to update.
|
|
96
|
+
* - realm: [optional] The realm name
|
|
97
|
+
* - groupRepresentation:An object representing the new state of the group. You can update properties such as:
|
|
98
|
+
* - name: [optional] New name of the group
|
|
99
|
+
* - attributes: [optional] Custom attributes up field
|
|
100
|
+
* - path: [optional] full path of the group
|
|
101
|
+
* - subGroups: [optional] List of child groups (can also be updated separately)
|
|
102
|
+
* - description: [optional] the new group Description
|
|
103
|
+
* - {other [optional] group description fields}
|
|
104
|
+
*/
|
|
105
|
+
exports.update=function(filter,groupRepresentation){
|
|
106
|
+
return (kcAdminClientHandler.groups.update(filter,groupRepresentation));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* ***************************** - listSubGroups - *******************************
|
|
114
|
+
* Retrieves a paginated list of direct subgroups for a specified parent group.
|
|
115
|
+
* This method is useful when navigating hierarchical group structures within a Keycloak realm.
|
|
116
|
+
* @parameters:
|
|
117
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
118
|
+
* - parentId: [required] ID of the parent group whose subgroups you want to list.
|
|
119
|
+
* - first: [optional] Index of the first result for pagination (default is 0).
|
|
120
|
+
* - max: [optional] Maximum number of results to return.
|
|
121
|
+
* - briefRepresentation: [optional] If true, returns a lightweight version of each group (default is true).
|
|
122
|
+
* - realm: [optional] Realm name
|
|
123
|
+
*/
|
|
124
|
+
exports.listSubGroups=function(filter){
|
|
125
|
+
return (kcAdminClientHandler.groups.listSubGroups(filter));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* ***************************** - addRealmRoleMappings - *******************************
|
|
131
|
+
* Adds one or more realm-level roles to a specific group.
|
|
132
|
+
* This operation grants all users within that group the associated realm roles,
|
|
133
|
+
* effectively assigning permissions at a group level.
|
|
134
|
+
* @parameters:
|
|
135
|
+
* - role_mapping: parameter provided as a JSON object that accepts the following parameters:
|
|
136
|
+
* - id: [required] The ID of the group to which roles will be added.
|
|
137
|
+
* - roles: [required] An array of role(RoleRepresentation) objects to assign.
|
|
138
|
+
*/
|
|
139
|
+
exports.addRealmRoleMappings=function(role_mapping){
|
|
140
|
+
return (kcAdminClientHandler.groups.addRealmRoleMappings(role_mapping));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* ***************************** - listAvailableRealmRoleMappings - *******************************
|
|
146
|
+
* Retrieves all available realm-level roles that can be assigned to a specific group but are not yet assigned.
|
|
147
|
+
* This helps in identifying which roles are still eligible for addition to the group.
|
|
148
|
+
* Return an array of RoleRepresentation objects representing the assignable realm roles for the group.
|
|
149
|
+
* @parameters:
|
|
150
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
151
|
+
* - id: [required] The ID of the group you want to inspect.
|
|
152
|
+
*/
|
|
153
|
+
exports.listAvailableRealmRoleMappings=function(filters){
|
|
154
|
+
return (kcAdminClientHandler.groups.listAvailableRealmRoleMappings(filters));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* ***************************** - listRoleMappings - *******************************
|
|
161
|
+
* Retrieves all role mappings for a specific group, including both realm roles and client roles.
|
|
162
|
+
* This method is useful for understanding the complete set of roles that are assigned to a group.
|
|
163
|
+
* Return an object with two arrays:
|
|
164
|
+
* - realmMappings: realm-level roles assigned to the group.
|
|
165
|
+
* - clientMappings: a map of client IDs to the client-level roles assigned for each client.
|
|
166
|
+
*
|
|
167
|
+
* @parameters:
|
|
168
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
169
|
+
* - id: [required] The ID of the group whose roles to fetch
|
|
170
|
+
*/
|
|
171
|
+
exports.listRoleMappings=function(filters){
|
|
172
|
+
return (kcAdminClientHandler.groups.listRoleMappings(filters));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* ***************************** - listRealmRoleMappings - *******************************
|
|
179
|
+
* Returns the list of realm-level roles that are directly assigned to a specific group.
|
|
180
|
+
* These roles are defined at the realm level and are not tied to any specific client.
|
|
181
|
+
* Return An array of RoleRepresentation objects
|
|
182
|
+
* @parameters:
|
|
183
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
184
|
+
* - id: [required] TThe ID of the group to retrieve roles for
|
|
185
|
+
*/
|
|
186
|
+
exports.listRealmRoleMappings=function(filters){
|
|
187
|
+
return (kcAdminClientHandler.groups.listRealmRoleMappings(filters));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* ***************************** - listCompositeRealmRoleMappings - *******************************
|
|
195
|
+
* Retrieves all composite realm-level roles assigned to a group.
|
|
196
|
+
* This includes both directly assigned roles and those inherited through composite roles.
|
|
197
|
+
* Return An array of RoleRepresentation objects that includes all realm roles, both directly assigned and inherited via composite roles.
|
|
198
|
+
* @parameters:
|
|
199
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
200
|
+
* - id: [required] TThe ID of the group to retrieve roles for
|
|
201
|
+
*/
|
|
202
|
+
exports.listCompositeRealmRoleMappings=function(filters){
|
|
203
|
+
return (kcAdminClientHandler.groups.listCompositeRealmRoleMappings(filters));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* ***************************** - delRealmRoleMappings - *******************************
|
|
209
|
+
* Removes one or more realm-level roles from a group's role mappings.
|
|
210
|
+
* This operation only affects roles that are directly assigned.
|
|
211
|
+
* Composite roles inherited indirectly will not be removed.
|
|
212
|
+
* @parameters:
|
|
213
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
214
|
+
* - id: [required] TThe ID of the group to retrieve roles for
|
|
215
|
+
* - roles: [required] Array of roles to be removed
|
|
216
|
+
*/
|
|
217
|
+
exports.delRealmRoleMappings=function(filters){
|
|
218
|
+
return (kcAdminClientHandler.groups.delRealmRoleMappings(filters));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* ***************************** - addClientRoleMappings - *******************************
|
|
223
|
+
* Assigns one or more client-level roles to a specific group.
|
|
224
|
+
* This allows all users belonging to that group to inherit the specified roles for a given client.
|
|
225
|
+
* @parameters:
|
|
226
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
227
|
+
* - id: [required] The ID of the group
|
|
228
|
+
* - clientUniqueId: [required] The internal ID of the client
|
|
229
|
+
* - roles: [required] Array of client roles to assign to the group
|
|
230
|
+
*/
|
|
231
|
+
exports.addClientRoleMappings=function(filters){
|
|
232
|
+
return (kcAdminClientHandler.groups.addClientRoleMappings(filters));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* ***************************** - listAvailableClientRoleMappings - *******************************
|
|
238
|
+
* Retrieves the list of client roles that are available to be assigned to a specific group but are not currently mapped.
|
|
239
|
+
* This is useful when you want to show assignable roles for a group in a specific client context.
|
|
240
|
+
* @parameters:
|
|
241
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
242
|
+
* - id: [required] The ID of the group
|
|
243
|
+
* - clientUniqueId: [required] The internal ID of the client
|
|
244
|
+
*/
|
|
245
|
+
exports.listAvailableClientRoleMappings=function(filters){
|
|
246
|
+
return (kcAdminClientHandler.groups.listAvailableClientRoleMappings(filters));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* ***************************** - listClientRoleMappings - *******************************
|
|
251
|
+
* Retrieves the list of client roles that are currently assigned (mapped) to a specific group for a given client.
|
|
252
|
+
* This allows you to see which roles from a client the group already has.
|
|
253
|
+
* @parameters:
|
|
254
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
255
|
+
* - id: [required] The ID of the group
|
|
256
|
+
* - clientUniqueId: [required] The internal ID of the client
|
|
257
|
+
*/
|
|
258
|
+
exports.listClientRoleMappings=function(filters){
|
|
259
|
+
return (kcAdminClientHandler.groups.listClientRoleMappings(filters));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* ***************************** - listCompositeClientRoleMappings - *******************************
|
|
266
|
+
* Retrieves the list of composite client roles assigned to a specific group.
|
|
267
|
+
* Composite roles are roles that aggregate other roles, so this method returns client roles that include one or more roles grouped under a composite role assigned to the group.
|
|
268
|
+
* @parameters:
|
|
269
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
270
|
+
* - id: [required] The ID of the group
|
|
271
|
+
* - clientUniqueId: [required] The internal ID of the client
|
|
272
|
+
*/
|
|
273
|
+
exports.listCompositeClientRoleMappings=function(filters){
|
|
274
|
+
return (kcAdminClientHandler.groups.listCompositeClientRoleMappings(filters));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* ***************************** - delClientRoleMappings - *******************************
|
|
281
|
+
* Removes specific client role mappings from a group.
|
|
282
|
+
* This function deletes one or more client roles that were assigned to the group, effectively
|
|
283
|
+
* revoking those client roles from the group.
|
|
284
|
+
* @parameters:
|
|
285
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
286
|
+
* - id: [required] The ID of the group
|
|
287
|
+
* - clientUniqueId: [required] The internal ID of the client
|
|
288
|
+
* - roles: An array of role objects(RoleRepresentation) representing the client roles to be removed
|
|
289
|
+
*/
|
|
290
|
+
exports.delClientRoleMappings=function(filters){
|
|
291
|
+
return (kcAdminClientHandler.groups.delClientRoleMappings(filters));
|
|
292
|
+
}
|
|
293
|
+
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **************************************************************************************************
|
|
3
|
+
* **************************************************************************************************
|
|
4
|
+
* identityProviders lets you manage Identity Providers (IdPs) configured in a realm.
|
|
5
|
+
* These are providers like Google, Facebook, GitHub, SAML, OIDC, etc.
|
|
6
|
+
* **************************************************************************************************
|
|
7
|
+
* **************************************************************************************************
|
|
8
|
+
*/
|
|
9
|
+
let kcAdminClientHandler=null;
|
|
10
|
+
exports.setKcAdminClient=function(kcAdminClient){
|
|
11
|
+
kcAdminClientHandler=kcAdminClient;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* ***************************** - create - *******************************
|
|
16
|
+
* The method is used to create a new Identity Provider (IdP) in a Keycloak realm.
|
|
17
|
+
* An IdP allows users to authenticate via external providers such as Google, Facebook, GitHub,
|
|
18
|
+
* or another SAML/OIDC provider.
|
|
19
|
+
* This method requires specifying an alias, the provider type, and configuration settings such as client ID, client secret, and any other provider-specific options.
|
|
20
|
+
* @parameters:
|
|
21
|
+
* - identityProvidersRappresentation: parameter provided as a JSON object containing the configuration of the Identity Provider
|
|
22
|
+
* - alias: [required] Unique name for the IdP within the realm.
|
|
23
|
+
* - providerId: [required] Type of provider (google, facebook, oidc, saml, etc.).
|
|
24
|
+
* - enabled: [optional] Whether the IdP is enabled. Default is true.
|
|
25
|
+
* - displayName: [optional] Display name for the login page.
|
|
26
|
+
* - trustEmail: [optional] Whether to trust the email from the IdP.
|
|
27
|
+
* - storeToken: [optional] Whether to store the token from the IdP.
|
|
28
|
+
* - linkOnly: [optional] If true, the IdP can only link accounts.
|
|
29
|
+
* - firstBrokerLoginFlowAlias: [optional] Flow to use on first login.
|
|
30
|
+
* - config : [optional] Provider-specific configuration, e.g., client ID, client secret, endpoints, etc.
|
|
31
|
+
*/
|
|
32
|
+
exports.create=function(identityProvidersRappresentation){
|
|
33
|
+
return (kcAdminClientHandler.identityProviders.create(identityProvidersRappresentation));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* ***************************** - createMapper - *******************************
|
|
38
|
+
* The method creates a new mapper for an existing Identity Provider in the current realm.
|
|
39
|
+
* The mapper defines how attributes, roles, or claims from the Identity Provider are mapped to the Keycloak user model.
|
|
40
|
+
* @parameters:
|
|
41
|
+
* - mapperParams: parameter provided as a JSON object containing the fields to create a new mapper
|
|
42
|
+
* - alias: [required] The alias of the Identity Provider to which the mapper will be attached.
|
|
43
|
+
* - identityProviderMapper: [required] The mapper configuration object, which includes details like the mapper type, name, and configuration values
|
|
44
|
+
*/
|
|
45
|
+
exports.createMapper=function(mapperParams){
|
|
46
|
+
return (kcAdminClientHandler.identityProviders.createMapper(mapperParams));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* ***************************** - findMappers - *******************************
|
|
52
|
+
* The method retrieves all mappers associated with a specific Identity Provider in the current realm.
|
|
53
|
+
* These mappers define how attributes, roles, or claims from the external Identity Provider are mapped to the Keycloak user model.
|
|
54
|
+
* @parameters:
|
|
55
|
+
* - filter: pparameter provided as a JSON object that accepts the following filter:
|
|
56
|
+
* - alias: [required] TThe alias of the Identity Provider whose mappers you want to fetch.
|
|
57
|
+
*/
|
|
58
|
+
exports.findMappers=function(filter){
|
|
59
|
+
return (kcAdminClientHandler.identityProviders.findMappers(filter));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* ***************************** - delMapper - *******************************
|
|
64
|
+
* The method deletes a specific mapper associated with an Identity Provider in the current realm.
|
|
65
|
+
* This is useful when you need to remove a mapping rule that translates attributes, roles, or claims from the external Identity Provider into Keycloak.
|
|
66
|
+
* @parameters:
|
|
67
|
+
* - filter: pparameter provided as a JSON object that accepts the following filter:
|
|
68
|
+
* - alias: [required] The alias of the Identity Provider that owns the mapper.
|
|
69
|
+
* - id : [required] The unique ID of the mapper to be deleted
|
|
70
|
+
*/
|
|
71
|
+
exports.delMapper=function(filter){
|
|
72
|
+
return (kcAdminClientHandler.identityProviders.delMapper(filter));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* ***************************** - findOneMapper - *******************************
|
|
78
|
+
* The method retrieves the details of a specific mapper associated with an Identity Provider in the current realm.
|
|
79
|
+
* This allows you to inspect a mapper’s configuration, such as how attributes or claims from the
|
|
80
|
+
* external Identity Provider are mapped into Keycloak.
|
|
81
|
+
* @parameters:
|
|
82
|
+
* - filter: pparameter provided as a JSON object that accepts the following filter:
|
|
83
|
+
* - alias: [required] The alias of the Identity Provider
|
|
84
|
+
* - id: [required] The unique ID of the mapper to retrieve
|
|
85
|
+
*/
|
|
86
|
+
exports.findOneMapper=function(filter){
|
|
87
|
+
return (kcAdminClientHandler.identityProviders.findOneMapper(filter));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* ***************************** - del - *******************************
|
|
93
|
+
* The method removes an Identity Provider from the current realm.
|
|
94
|
+
* This action deletes the provider configuration, including all its associated mappers and settings.
|
|
95
|
+
* After deletion, users will no longer be able to authenticate using that Identity Provider.
|
|
96
|
+
* @parameters:
|
|
97
|
+
* - filter: pparameter provided as a JSON object that accepts the following filter:
|
|
98
|
+
* - alias: [required] The alias of the Identity Provider you want to delete.
|
|
99
|
+
*/
|
|
100
|
+
exports.del=function(filter){
|
|
101
|
+
return (kcAdminClientHandler.identityProviders.del(filter));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* ***************************** - findOne - *******************************
|
|
107
|
+
* The method retrieves the configuration details of a specific Identity Provider in the current realm.
|
|
108
|
+
* It is useful when you need to inspect the provider’s settings, such as its alias, display name,
|
|
109
|
+
* authentication flow, or other configuration parameters.
|
|
110
|
+
* @parameters:
|
|
111
|
+
* - filter: pparameter provided as a JSON object that accepts the following filter:
|
|
112
|
+
* - alias: [required] The alias of the Identity Provider you want to find.
|
|
113
|
+
*/
|
|
114
|
+
exports.findOne=function(filter){
|
|
115
|
+
return (kcAdminClientHandler.identityProviders.findOne(filter));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* ***************************** - find - *******************************
|
|
120
|
+
* The method retrieves a list of all configured Identity Providers in the current realm.
|
|
121
|
+
* It allows you to see which providers (e.g., Google, GitHub, SAML, etc.)
|
|
122
|
+
* are available and get their basic configuration details.
|
|
123
|
+
*/
|
|
124
|
+
exports.find=function(){
|
|
125
|
+
return (kcAdminClientHandler.identityProviders.find());
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* ***************************** - update - *******************************
|
|
131
|
+
* The method updates the configuration of a specific Identity Provider in the current realm.
|
|
132
|
+
* It allows you to modify settings such as client ID, secret, authorization URLs, or any custom configuration fields exposed by the provider.
|
|
133
|
+
* @parameters:
|
|
134
|
+
* - filter: pparameter provided as a JSON object that accepts the following filter:
|
|
135
|
+
* - alias: [required] The alias of the Identity Provider to update.
|
|
136
|
+
* - identityProviderRepresentation: An object containing the updated configuration fields:
|
|
137
|
+
* - alias: [required] The alias of the Identity Provider.
|
|
138
|
+
* - providerId: [required] The provider type (e.g., "google", "saml").
|
|
139
|
+
* - {Other optional fields like displayName, config object}
|
|
140
|
+
*/
|
|
141
|
+
exports.update=function(filter,identityProviderRepresentation){
|
|
142
|
+
return (kcAdminClientHandler.identityProviders.update(filter,identityProviderRepresentation));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* ***************************** - findFactory - *******************************
|
|
148
|
+
* The method retrieves information about a specific Identity Provider factory available in Keycloak.
|
|
149
|
+
* A factory represents a provider type (e.g., "oidc", "saml", "github") and contains metadata about how that provider can be configured.
|
|
150
|
+
* This is useful when you want to check what configuration options are supported before creating or updating an Identity Provider.
|
|
151
|
+
* @parameters:
|
|
152
|
+
* - filter: pparameter provided as a JSON object that accepts the following filter:
|
|
153
|
+
* - providerId: [required] The ID of the Identity Provider factory to look up (e.g., "oidc", "saml", "google").
|
|
154
|
+
*/
|
|
155
|
+
exports.findFactory=function(filter){
|
|
156
|
+
return (kcAdminClientHandler.identityProviders.findFactory(filter));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* ***************************** - findMappers - *******************************
|
|
162
|
+
* The method retrieves all mappers associated with a specific Identity Provider in Keycloak.
|
|
163
|
+
* Mappers define how information from the external Identity Provider (e.g., Google, SAML, GitHub) is mapped into Keycloak attributes, roles, or claims.
|
|
164
|
+
* This is useful to list all transformations and mappings applied to users authenticating via that provider.
|
|
165
|
+
* @parameters:
|
|
166
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
167
|
+
* - alias: [required] The alias of the Identity Provider (set when the provider was created)
|
|
168
|
+
*/
|
|
169
|
+
exports.findMappers=function(filter){
|
|
170
|
+
return (kcAdminClientHandler.identityProviders.findMappers(filter));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* ***************************** - findOneMapper - *******************************
|
|
176
|
+
* The method retrieves a single mapper associated with a specific Identity Provider in Keycloak.
|
|
177
|
+
* It’s useful when you need to inspect the configuration of a mapper before updating or deleting it.
|
|
178
|
+
* @parameters:
|
|
179
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
180
|
+
* - alias: [required] The alias of the Identity Provider
|
|
181
|
+
* - id: [required] The unique ID of the mapper to fetch
|
|
182
|
+
*/
|
|
183
|
+
exports.findOneMapper=function(filter){
|
|
184
|
+
return (kcAdminClientHandler.identityProviders.findOneMapper(filter));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* ***************************** - updateMapper - *******************************
|
|
191
|
+
* The method updates an existing mapper for a given Identity Provider in Keycloak.
|
|
192
|
+
* Mappers define how attributes, roles, or claims from an external Identity Provider (e.g., Google, GitHub, SAML)
|
|
193
|
+
* are mapped into Keycloak user attributes or tokens.
|
|
194
|
+
* This method allows you to change the configuration of an existing mapper (e.g., modify the claim name, attribute name, or role assignment).
|
|
195
|
+
* @parameters:
|
|
196
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
197
|
+
* - alias: [required] The alias of the Identity Provider (set during IdP creation).
|
|
198
|
+
* - id: [required] The ID of the mapper to update.
|
|
199
|
+
* - mapperRepresentation: parameter provided as a JSON object that represent the updated mapper configuration object.
|
|
200
|
+
* - id : [optional] The mapper ID.
|
|
201
|
+
* - name: [optional] The mapper name.
|
|
202
|
+
* - identityProviderAlias: [optional] The IdP alias.
|
|
203
|
+
* - identityProviderMapper: [optional] The type of mapper (e.g., "oidc-user-attribute-idp-mapper").
|
|
204
|
+
* - config: [optional] The new mapping configuration.
|
|
205
|
+
*/
|
|
206
|
+
exports.updateMapper=function(filter,mapperRepresentation){
|
|
207
|
+
return (kcAdminClientHandler.identityProviders.updateMapper(filter,mapperRepresentation));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* ***************************** - importFromUrl - *******************************
|
|
214
|
+
* The method lets you import an Identity Provider configuration directly from a metadata URL (e.g., OIDC discovery document or SAML metadata XML).
|
|
215
|
+
* This saves you from manually entering configuration details, since Keycloak can auto-fill them from the provided URL.
|
|
216
|
+
* @parameters:
|
|
217
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
218
|
+
* - fromUrl : [required] The URL of the IdP metadata (OIDC discovery endpoint or SAML metadata).
|
|
219
|
+
* - providerId : [required]The type of IdP (e.g., "oidc", "saml").
|
|
220
|
+
* - trustEmail: [optional] Whether to automatically trust emails from this IdP.
|
|
221
|
+
* - alias: [optional] Alias for the Identity Provider (unique name).
|
|
222
|
+
*/
|
|
223
|
+
exports.importFromUrl=function(filter){
|
|
224
|
+
return (kcAdminClientHandler.identityProviders.importFromUrl(filter));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* ***************************** - updatePermission - *******************************
|
|
229
|
+
* The method allows you to enable or disable fine-grained admin permissions for a specific Identity Provider in Keycloak.
|
|
230
|
+
* When enabled, Keycloak creates client roles (scopes) that let you define which users or groups can view or manage the Identity Provider.
|
|
231
|
+
* @parameters:
|
|
232
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
233
|
+
* - alias: [required] The alias of the Identity Provider.
|
|
234
|
+
* - permissionRepresentation: parameter provided as a JSON object that represent the updated permission object.
|
|
235
|
+
* - enabled: [optional] true to enable permissions, false to disable.
|
|
236
|
+
* - realm: [optional] The realm where the IdP is defined.
|
|
237
|
+
* - {other permisssion fields}
|
|
238
|
+
*/
|
|
239
|
+
exports.updatePermission=function(filter,permissionRepresentation){
|
|
240
|
+
return (kcAdminClientHandler.identityProviders.updatePermission(filter,permissionRepresentation));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* ***************************** - listPermissions - *******************************
|
|
246
|
+
* The method retrieves the current fine-grained permission settings for a specific Identity Provider in Keycloak.
|
|
247
|
+
* It returns whether permissions are enabled and, if so, which scope roles are associated with managing and viewing the Identity Provider.
|
|
248
|
+
* @parameters:
|
|
249
|
+
* - filter: parameter provided as a JSON object that accepts the following filter:
|
|
250
|
+
* - alias: [required] The alias of the Identity Provider.
|
|
251
|
+
* - realm: [optional] The realm where the IdP is defined.
|
|
252
|
+
*/
|
|
253
|
+
exports.listPermissions=function(filter){
|
|
254
|
+
return (kcAdminClientHandler.identityProviders.listPermissions(filter));
|
|
255
|
+
}
|