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,196 @@
|
|
|
1
|
+
const Keycloak = require("keycloak-connect");
|
|
2
|
+
/**
|
|
3
|
+
* **************************************************************************************************
|
|
4
|
+
* **************************************************************************************************
|
|
5
|
+
* The roles entity refers to Keycloak's roles management functionality, part of the Admin REST API.
|
|
6
|
+
* It allows you to create, update, inspect, and delete both realm-level and client-level roles.
|
|
7
|
+
* **************************************************************************************************
|
|
8
|
+
* **************************************************************************************************
|
|
9
|
+
*/
|
|
10
|
+
let kcAdminClientHandler=null;
|
|
11
|
+
exports.setKcAdminClient=function(kcAdminClient){
|
|
12
|
+
kcAdminClientHandler=kcAdminClient;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* ***************************** - CREATE - *******************************
|
|
17
|
+
* Create a new role
|
|
18
|
+
* @parameters:
|
|
19
|
+
* - role_dictionary: A JSON object representing a role dictionary as defined in Keycloak
|
|
20
|
+
*/
|
|
21
|
+
exports.create=function(role_dictionary){
|
|
22
|
+
return (kcAdminClientHandler.roles.create(role_dictionary));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* ***************************** - createComposite - *******************************
|
|
29
|
+
* Create a new composite role. Composite roles in Keycloak are roles that combine other roles,
|
|
30
|
+
* allowing you to group multiple permissions into a single, higher-level role.
|
|
31
|
+
* A composite role can include roles from the same realm as well
|
|
32
|
+
* as roles from different clients.
|
|
33
|
+
* When you assign a composite role to a user, they automatically inherit all the roles it contains.
|
|
34
|
+
* @parameters:
|
|
35
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
36
|
+
* - roleId: [required] The id of the role to which composite roles will be added.
|
|
37
|
+
*
|
|
38
|
+
* - roles: (Array<RoleRepresentation>) [required] A list of roles to be added as composites. Each RoleRepresentation typically includes:
|
|
39
|
+
* - id: [required] The role’s unique ID.
|
|
40
|
+
* - name: [required] The role’s name.
|
|
41
|
+
* - containerId: [optional] The realm or client that owns the role.
|
|
42
|
+
* - clientRole: [optional] Whether the role belongs to a client.
|
|
43
|
+
*/
|
|
44
|
+
exports.createComposite=function(filters,roles){
|
|
45
|
+
return (kcAdminClientHandler.roles.createComposite(filters,roles));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* ***************************** - find - *******************************
|
|
53
|
+
* Get all realm roles and return a JSON
|
|
54
|
+
* @parameters:
|
|
55
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
56
|
+
* - realm (string, optional: if set globally in the client): The realm from which to retrieve roles.
|
|
57
|
+
* - first (number, optional): Index of the first result to return (used for pagination).
|
|
58
|
+
* - max (number, optional): Maximum number of results to return.
|
|
59
|
+
* - name (string, optional): Search string to filter roles by name.
|
|
60
|
+
*/
|
|
61
|
+
exports.find=function(filters){
|
|
62
|
+
return (kcAdminClientHandler.roles.find(filters));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* ***************************** - findOneByName - *******************************
|
|
68
|
+
* get a role by name
|
|
69
|
+
* @parameters:
|
|
70
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
71
|
+
* - name (string, required) — The exact name of the role to retrieve.
|
|
72
|
+
* - realm (string, optional if set globally) — The realm where the role is defined.
|
|
73
|
+
*/
|
|
74
|
+
exports.findOneByName=function(filters){
|
|
75
|
+
return (kcAdminClientHandler.roles.findOneByName(filters));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* ***************************** - findOneById - *******************************
|
|
82
|
+
* Get a role by its Id
|
|
83
|
+
* @parameters:
|
|
84
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
85
|
+
* - Id (string, required) — The Id of the role to retrieve.
|
|
86
|
+
* - realm (string, optional if set globally) — The realm where the role is defined.
|
|
87
|
+
*/
|
|
88
|
+
exports.findOneById=function(filters){
|
|
89
|
+
return (kcAdminClientHandler.roles.findOneById(filters));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* ***************************** - updateByName - *******************************
|
|
95
|
+
* Update a role by its name
|
|
96
|
+
* @parameters:
|
|
97
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
98
|
+
* - name (string, required) — The exact name of the role to retrieve.
|
|
99
|
+
* - realm (string, optional if set globally) — The realm where the role is defined.
|
|
100
|
+
* - role_dictionary: A JSON object representing a role dictionary as defined in Keycloak
|
|
101
|
+
*/
|
|
102
|
+
exports.updateByName=function(filters,role_dictionary){
|
|
103
|
+
return (kcAdminClientHandler.roles.updateByName(filters,role_dictionary));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* ***************************** - updateById - *******************************
|
|
110
|
+
* Update a role by its Id
|
|
111
|
+
* @parameters:
|
|
112
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
113
|
+
* - name (string, required) — The exact name of the role to retrieve.
|
|
114
|
+
* - realm (string, optional if set globally) — The realm where the role is defined.
|
|
115
|
+
* - role_dictionary: A JSON object representing a role dictionary as defined in Keycloak
|
|
116
|
+
*/
|
|
117
|
+
exports.updateById=function(filters,role_dictionary){
|
|
118
|
+
return (kcAdminClientHandler.roles.updateById(filters,role_dictionary));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* ***************************** - delByName - *******************************
|
|
124
|
+
* Delete a role by its name
|
|
125
|
+
* @parameters:
|
|
126
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
127
|
+
* - name (string, required) — The exact name of the role to retrieve.
|
|
128
|
+
* - realm (string, optional if set globally) — The realm where the role is defined.
|
|
129
|
+
*/
|
|
130
|
+
exports.delByName=function(filters){
|
|
131
|
+
return (kcAdminClientHandler.roles.delByName(filters));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* ***************************** - findUsersWithRole - *******************************
|
|
136
|
+
* Find all users associated with a specific role
|
|
137
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
138
|
+
* - name: (string, optional) — The exact name of the role to retrieve.
|
|
139
|
+
* - id: (string, optional) — The Id of the role to retrieve.
|
|
140
|
+
* - realm: (string, optional if set globally) — The realm where the role is defined.
|
|
141
|
+
*/
|
|
142
|
+
exports.findUsersWithRole=function(filters){
|
|
143
|
+
return (kcAdminClientHandler.roles.findUsersWithRole(filters));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* ***************************** - getCompositeRoles - *******************************
|
|
150
|
+
* Find all composite roles associated with a specific role.
|
|
151
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
152
|
+
* - name: (string, optional) — The exact name of the role to retrieve.
|
|
153
|
+
* - id: (string, optional) — The Id of the role to retrieve.
|
|
154
|
+
*/
|
|
155
|
+
exports.getCompositeRoles=function(filters){
|
|
156
|
+
return (kcAdminClientHandler.roles.getCompositeRoles(filters));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* ***************************** - getCompositeRolesForRealm - *******************************
|
|
161
|
+
* The getCompositeRolesForRealm function is used to retrieve all realm-level roles that are
|
|
162
|
+
* associated with a given composite role.
|
|
163
|
+
* When a role is defined as composite, it can include other roles either from the same
|
|
164
|
+
* realm or from different clients. This specific method returns only the realm-level roles
|
|
165
|
+
* that have been added to the composite role. It requires the roleId of the target role as a
|
|
166
|
+
* parameter and returns an array of RoleRepresentation objects. If the role is not composite
|
|
167
|
+
* or has no associated realm roles, the result will be an empty array. This method is useful
|
|
168
|
+
* for understanding and managing hierarchical role structures within a realm in Keycloak.
|
|
169
|
+
* @parameters:
|
|
170
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
171
|
+
* - roleId: (string, required) — The Id of the role to retrieve
|
|
172
|
+
*/
|
|
173
|
+
exports.getCompositeRolesForRealm=function(filters){
|
|
174
|
+
return (kcAdminClientHandler.roles.getCompositeRolesForRealm(filters));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* ***************************** - getCompositeRolesForClient - *******************************
|
|
180
|
+
* The getCompositeRolesForClient function is used to retrieve all client-level roles that are
|
|
181
|
+
* associated with a given composite role.
|
|
182
|
+
* Composite roles in Keycloak can include roles from different clients,
|
|
183
|
+
* and this method specifically returns the roles belonging to a specified client that
|
|
184
|
+
* are part of the composite role. It requires the roleId of the composite role
|
|
185
|
+
* and the clientId of the client whose roles you want to retrieve. The function returns an array of
|
|
186
|
+
* RoleRepresentation objects representing the client roles included in the composite.
|
|
187
|
+
* This helps manage and inspect client-specific role hierarchies within the composite role structure in Keycloak.
|
|
188
|
+
* @parameters:
|
|
189
|
+
* - filters: parameter provided as a JSON object that accepts the following parameters:
|
|
190
|
+
* - roleId: (string, required) — The Id of the role to retrieve
|
|
191
|
+
* - clientId: (string, required) — The Id of the client to search for composite roles
|
|
192
|
+
*
|
|
193
|
+
*/
|
|
194
|
+
exports.getCompositeRolesForClient=function(filters){
|
|
195
|
+
return (kcAdminClientHandler.roles.getCompositeRolesForClient(filters));
|
|
196
|
+
}
|