@adatechnology/keycloak-admin 0.1.6 → 0.1.8
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/dist/index.js +67 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -72,12 +72,13 @@ var KEYCLOAK_ADMIN_AUTHORIZATION_HEADER = "Authorization";
|
|
|
72
72
|
var KEYCLOAK_ADMIN_BEARER_PREFIX = "Bearer ";
|
|
73
73
|
var KEYCLOAK_ADMIN_ENDPOINTS = {
|
|
74
74
|
MASTER_TOKEN: "/realms/master/protocol/openid-connect/token",
|
|
75
|
-
ADMIN_USERS: /* @__PURE__ */ __name((baseUrl, realm, userId) => `${baseUrl}/admin/realms/${realm}/users/${userId}`, "ADMIN_USERS"),
|
|
75
|
+
ADMIN_USERS: /* @__PURE__ */ __name((baseUrl, realm, userId) => userId ? `${baseUrl}/admin/realms/${realm}/users/${userId}` : `${baseUrl}/admin/realms/${realm}/users`, "ADMIN_USERS"),
|
|
76
76
|
ADMIN_RESET_PASSWORD: /* @__PURE__ */ __name((baseUrl, realm, userId) => `${baseUrl}/admin/realms/${realm}/users/${userId}/reset-password`, "ADMIN_RESET_PASSWORD"),
|
|
77
77
|
ADMIN_SEND_VERIFY_EMAIL: /* @__PURE__ */ __name((baseUrl, realm, userId) => `${baseUrl}/admin/realms/${realm}/users/${userId}/send-verify-email`, "ADMIN_SEND_VERIFY_EMAIL")
|
|
78
78
|
};
|
|
79
79
|
var KEYCLOAK_ADMIN_ERROR_CODES = {
|
|
80
80
|
ADMIN_TOKEN_ERROR: "KEYCLOAK_ADMIN_TOKEN_ERROR",
|
|
81
|
+
CREATE_USER_ERROR: "KEYCLOAK_CREATE_USER_ERROR",
|
|
81
82
|
UPDATE_USER_ERROR: "KEYCLOAK_UPDATE_USER_ERROR",
|
|
82
83
|
RESET_PASSWORD_ERROR: "KEYCLOAK_RESET_PASSWORD_ERROR",
|
|
83
84
|
TOGGLE_ENABLED_ERROR: "KEYCLOAK_TOGGLE_ENABLED_ERROR",
|
|
@@ -197,6 +198,71 @@ var _KeycloakAdminClient = class _KeycloakAdminClient {
|
|
|
197
198
|
});
|
|
198
199
|
}
|
|
199
200
|
}
|
|
201
|
+
async createUser(params) {
|
|
202
|
+
var _a, _b;
|
|
203
|
+
const method = "createUser";
|
|
204
|
+
const { username, email, firstName, lastName, enabled, emailVerified, credentials, attributes, adminToken } = params;
|
|
205
|
+
this.log("info", `${method} - Start`, method, {
|
|
206
|
+
username,
|
|
207
|
+
email
|
|
208
|
+
});
|
|
209
|
+
const url = KEYCLOAK_ADMIN_ENDPOINTS.ADMIN_USERS(this.config.baseUrl, this.config.realm);
|
|
210
|
+
const userData = {
|
|
211
|
+
username,
|
|
212
|
+
email,
|
|
213
|
+
firstName,
|
|
214
|
+
lastName,
|
|
215
|
+
enabled,
|
|
216
|
+
emailVerified,
|
|
217
|
+
...credentials ? {
|
|
218
|
+
credentials
|
|
219
|
+
} : {},
|
|
220
|
+
...attributes ? {
|
|
221
|
+
attributes
|
|
222
|
+
} : {}
|
|
223
|
+
};
|
|
224
|
+
try {
|
|
225
|
+
const response = await this.httpProvider.post({
|
|
226
|
+
url,
|
|
227
|
+
data: userData,
|
|
228
|
+
config: {
|
|
229
|
+
headers: {
|
|
230
|
+
[KEYCLOAK_ADMIN_AUTHORIZATION_HEADER]: `${KEYCLOAK_ADMIN_BEARER_PREFIX}${adminToken}`,
|
|
231
|
+
"Content-Type": KEYCLOAK_ADMIN_CONTENT_TYPE_JSON
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
const locationHeader = ((_a = response.headers) == null ? void 0 : _a["location"]) ?? ((_b = response.headers) == null ? void 0 : _b["Location"]);
|
|
236
|
+
const userId = typeof locationHeader === "string" ? locationHeader.split("/").pop() ?? "" : "";
|
|
237
|
+
this.log("info", `${method} - Success`, method, {
|
|
238
|
+
username,
|
|
239
|
+
email,
|
|
240
|
+
userId
|
|
241
|
+
});
|
|
242
|
+
return userId;
|
|
243
|
+
} catch (err) {
|
|
244
|
+
const { statusCode, details, errorCode } = extractHttpError(err);
|
|
245
|
+
this.log("error", `${method} - Failed`, method, {
|
|
246
|
+
username,
|
|
247
|
+
email,
|
|
248
|
+
statusCode,
|
|
249
|
+
errorCode
|
|
250
|
+
});
|
|
251
|
+
throw new KeycloakAdminError({
|
|
252
|
+
message: "Keycloak create user failed",
|
|
253
|
+
statusCode: statusCode ?? 502,
|
|
254
|
+
code: KEYCLOAK_ADMIN_ERROR_CODES.CREATE_USER_ERROR,
|
|
255
|
+
context: {
|
|
256
|
+
url,
|
|
257
|
+
method: "POST",
|
|
258
|
+
username,
|
|
259
|
+
email,
|
|
260
|
+
details,
|
|
261
|
+
errorCode
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
200
266
|
async updateUser(params) {
|
|
201
267
|
const method = "updateUser";
|
|
202
268
|
const { userId, userData, adminToken } = params;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adatechnology/keycloak-admin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@adatechnology/http-client": "0.0.
|
|
15
|
-
"@adatechnology/logger": "0.0.
|
|
14
|
+
"@adatechnology/http-client": "0.0.16",
|
|
15
|
+
"@adatechnology/logger": "0.0.12"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"@nestjs/common": "^11.0.16",
|