@l-v-yonsama/multi-platform-database-drivers 0.1.213 → 0.1.214
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/built/src/drivers/Auth0Driver.d.ts +58 -0
- package/built/src/drivers/Auth0Driver.js +669 -0
- package/built/src/drivers/Auth0Driver.js.map +1 -0
- package/built/src/drivers/DBDriverResolver.js +4 -0
- package/built/src/drivers/DBDriverResolver.js.map +1 -1
- package/built/src/drivers/KeycloakDriver.d.ts +1 -0
- package/built/src/drivers/KeycloakDriver.js +43 -26
- package/built/src/drivers/KeycloakDriver.js.map +1 -1
- package/built/src/drivers/index.d.ts +1 -0
- package/built/src/drivers/index.js +1 -0
- package/built/src/drivers/index.js.map +1 -1
- package/built/src/resource/DbResource.d.ts +24 -2
- package/built/src/resource/DbResource.js +64 -1
- package/built/src/resource/DbResource.js.map +1 -1
- package/built/src/types/resource/ConnectionSetting.d.ts +1 -0
- package/built/src/types/resource/DBType.d.ts +2 -1
- package/built/src/types/resource/DBType.js +1 -0
- package/built/src/types/resource/DBType.js.map +1 -1
- package/built/src/types/resource/ResourceType.d.ts +4 -1
- package/built/src/types/resource/ResourceType.js +4 -1
- package/built/src/types/resource/ResourceType.js.map +1 -1
- package/built/src/utils/strings.d.ts +3 -0
- package/built/src/utils/strings.js +13 -1
- package/built/src/utils/strings.js.map +1 -1
- package/package.json +7 -2
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth0Driver = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const BaseDriver_1 = require("./BaseDriver");
|
|
6
|
+
const resource_1 = require("../resource");
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const auth0_1 = require("auth0");
|
|
10
|
+
const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
|
|
11
|
+
class Auth0Driver extends BaseDriver_1.BaseDriver {
|
|
12
|
+
constructor(conRes) {
|
|
13
|
+
super(conRes);
|
|
14
|
+
}
|
|
15
|
+
connectSub() {
|
|
16
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
this.cachedAccessToken = undefined;
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.error(e);
|
|
22
|
+
return `failed to connect:${e.message}`;
|
|
23
|
+
}
|
|
24
|
+
return '';
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
test(with_connect = false) {
|
|
28
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
let errorReason = '';
|
|
30
|
+
try {
|
|
31
|
+
if (with_connect) {
|
|
32
|
+
const con_result = yield this.connect();
|
|
33
|
+
if (con_result) {
|
|
34
|
+
return con_result;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
yield this.getAvailableAccessToken();
|
|
38
|
+
if (with_connect) {
|
|
39
|
+
yield this.disconnect();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
errorReason = e.message;
|
|
44
|
+
}
|
|
45
|
+
return errorReason;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
getClients(params) {
|
|
49
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const list = [];
|
|
51
|
+
let page = 0;
|
|
52
|
+
let total = 0;
|
|
53
|
+
let sum = 0;
|
|
54
|
+
const { keyword, limit } = params !== null && params !== void 0 ? params : {};
|
|
55
|
+
const mngClient = yield this.getManagementClient();
|
|
56
|
+
do {
|
|
57
|
+
const r = yield mngClient.getClients({
|
|
58
|
+
include_totals: true,
|
|
59
|
+
page: page++,
|
|
60
|
+
});
|
|
61
|
+
total = r.total;
|
|
62
|
+
sum += r.clients.length;
|
|
63
|
+
if (keyword) {
|
|
64
|
+
list.push(...r.clients.filter((it) => (0, utils_1.containsIgnoreCase)(keyword, [it.description, it.name])));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
list.push(...r.clients);
|
|
68
|
+
}
|
|
69
|
+
if (limit !== undefined && list.length > limit) {
|
|
70
|
+
return list.slice(0, limit);
|
|
71
|
+
}
|
|
72
|
+
} while (sum < total);
|
|
73
|
+
return list;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getClient({ tenant, name, clientId, }) {
|
|
77
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
let page = 0;
|
|
79
|
+
let total = 0;
|
|
80
|
+
let sum = 0;
|
|
81
|
+
let client = undefined;
|
|
82
|
+
if (tenant === undefined && name === undefined && clientId === undefined) {
|
|
83
|
+
throw new Error('tenant or name or clientId must be defined.');
|
|
84
|
+
}
|
|
85
|
+
const mngClient = yield this.getManagementClient();
|
|
86
|
+
do {
|
|
87
|
+
const r = yield mngClient.getClients({
|
|
88
|
+
include_totals: true,
|
|
89
|
+
page: page++,
|
|
90
|
+
});
|
|
91
|
+
total = r.total;
|
|
92
|
+
sum += r.clients.length;
|
|
93
|
+
client = r.clients.find((it) => (tenant !== undefined && (0, utils_1.equalsIgnoreCase)(it.tenant, tenant)) ||
|
|
94
|
+
(clientId !== undefined &&
|
|
95
|
+
(0, utils_1.equalsIgnoreCase)(it.client_id, clientId)) ||
|
|
96
|
+
(name !== undefined && (0, utils_1.equalsIgnoreCase)(it.name, name)));
|
|
97
|
+
} while (sum < total);
|
|
98
|
+
return client;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
createClientGrants(data) {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const mngClient = yield this.getManagementClient();
|
|
105
|
+
const audience = (_a = data.audience) !== null && _a !== void 0 ? _a : this.getDefaultAudience();
|
|
106
|
+
const scope = (_b = data.scope) !== null && _b !== void 0 ? _b : this.getDefaultClientGrantScopes();
|
|
107
|
+
return yield mngClient.createClientGrant({
|
|
108
|
+
client_id: data.client_id,
|
|
109
|
+
audience,
|
|
110
|
+
scope,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
createClient(data) {
|
|
115
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
const mngClient = yield this.getManagementClient();
|
|
117
|
+
return yield mngClient.createClient(Object.assign({ app_type: 'non_interactive', is_first_party: true, oidc_conformant: true, jwt_configuration: {
|
|
118
|
+
alg: 'RS256',
|
|
119
|
+
lifetime_in_seconds: 36000,
|
|
120
|
+
}, token_endpoint_auth_method: 'client_secret_post', grant_types: ['client_credentials'] }, data));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
countOrganizations() {
|
|
124
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const mngClient = yield this.getManagementClient();
|
|
126
|
+
const { total } = yield mngClient.organizations.getAll({
|
|
127
|
+
include_totals: true,
|
|
128
|
+
page: 0,
|
|
129
|
+
per_page: 1,
|
|
130
|
+
});
|
|
131
|
+
return total;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
createOrganization(payload) {
|
|
135
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const mngClient = yield this.getManagementClient();
|
|
137
|
+
return yield mngClient.organizations.create(payload);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
updateOrganization(payload) {
|
|
141
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
const { id } = payload, data = tslib_1.__rest(payload, ["id"]);
|
|
143
|
+
const mngClient = yield this.getManagementClient();
|
|
144
|
+
return yield mngClient.organizations.update({ id }, data);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
getOrganizations(params) {
|
|
148
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const list = [];
|
|
150
|
+
let page = 0;
|
|
151
|
+
let total = 0;
|
|
152
|
+
let sum = 0;
|
|
153
|
+
const { keyword, limit } = params !== null && params !== void 0 ? params : {};
|
|
154
|
+
const mngClient = yield this.getManagementClient();
|
|
155
|
+
do {
|
|
156
|
+
const r = yield mngClient.organizations.getAll({
|
|
157
|
+
include_totals: true,
|
|
158
|
+
page: page++,
|
|
159
|
+
});
|
|
160
|
+
total = r.total;
|
|
161
|
+
sum += r.organizations.length;
|
|
162
|
+
if (keyword) {
|
|
163
|
+
list.push(...r.organizations.filter((it) => (0, utils_1.containsIgnoreCase)(keyword, [it.display_name, it.name])));
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
list.push(...r.organizations);
|
|
167
|
+
}
|
|
168
|
+
if (limit !== undefined && list.length > limit) {
|
|
169
|
+
return list.slice(0, limit);
|
|
170
|
+
}
|
|
171
|
+
} while (sum < total);
|
|
172
|
+
return list;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getOrganization({ id, name, }) {
|
|
176
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
if (name === undefined && id === undefined) {
|
|
178
|
+
throw new Error('name or id must be defined.');
|
|
179
|
+
}
|
|
180
|
+
const mngClient = yield this.getManagementClient();
|
|
181
|
+
if (id !== undefined) {
|
|
182
|
+
return yield mngClient.organizations.getByID({ id });
|
|
183
|
+
}
|
|
184
|
+
if (name !== undefined) {
|
|
185
|
+
return yield mngClient.organizations.getByName({ name });
|
|
186
|
+
}
|
|
187
|
+
return undefined;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
countRoles() {
|
|
191
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const mngClient = yield this.getManagementClient();
|
|
193
|
+
const { total } = yield mngClient.getRoles({
|
|
194
|
+
include_totals: true,
|
|
195
|
+
page: 0,
|
|
196
|
+
per_page: 1,
|
|
197
|
+
});
|
|
198
|
+
return total;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
createRole(payload) {
|
|
202
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
const mngClient = yield this.getManagementClient();
|
|
204
|
+
return yield mngClient.createRole(payload);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
updateRole(payload) {
|
|
208
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
const { id } = payload, data = tslib_1.__rest(payload, ["id"]);
|
|
210
|
+
const mngClient = yield this.getManagementClient();
|
|
211
|
+
return yield mngClient.updateRole({ id }, data);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
getRoles(params) {
|
|
215
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
const list = [];
|
|
217
|
+
let page = 0;
|
|
218
|
+
let total = 0;
|
|
219
|
+
let sum = 0;
|
|
220
|
+
const { keyword, limit } = params !== null && params !== void 0 ? params : {};
|
|
221
|
+
const mngClient = yield this.getManagementClient();
|
|
222
|
+
do {
|
|
223
|
+
const r = yield mngClient.getRoles({
|
|
224
|
+
name_filter: keyword,
|
|
225
|
+
include_totals: true,
|
|
226
|
+
page: page++,
|
|
227
|
+
});
|
|
228
|
+
total = r.total;
|
|
229
|
+
sum += r.roles.length;
|
|
230
|
+
list.push(...r.roles);
|
|
231
|
+
if (limit !== undefined && list.length > limit) {
|
|
232
|
+
return list.slice(0, limit);
|
|
233
|
+
}
|
|
234
|
+
} while (sum < total);
|
|
235
|
+
return list;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
getRole({ id, name }) {
|
|
239
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
if (id === undefined && name === undefined) {
|
|
241
|
+
throw new Error('id or name must be defined.');
|
|
242
|
+
}
|
|
243
|
+
if (id !== undefined) {
|
|
244
|
+
const mngClient = yield this.getManagementClient();
|
|
245
|
+
return yield mngClient.getRole({ id });
|
|
246
|
+
}
|
|
247
|
+
if (name !== undefined) {
|
|
248
|
+
const roles = this.getRoles({ keyword: name });
|
|
249
|
+
return (yield roles).find((it) => (0, utils_1.equalsIgnoreCase)(it.name, name));
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
countUsers() {
|
|
255
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
const mngClient = yield this.getManagementClient();
|
|
257
|
+
const { total } = yield mngClient.getUsers({
|
|
258
|
+
include_totals: true,
|
|
259
|
+
page: 0,
|
|
260
|
+
per_page: 1,
|
|
261
|
+
});
|
|
262
|
+
return total;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
getUsers(params) {
|
|
266
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
const list = [];
|
|
268
|
+
let page = 0;
|
|
269
|
+
let total = 0;
|
|
270
|
+
let sum = 0;
|
|
271
|
+
const { keyword, limit } = params !== null && params !== void 0 ? params : {};
|
|
272
|
+
const mngClient = yield this.getManagementClient();
|
|
273
|
+
do {
|
|
274
|
+
const r = yield mngClient.getUsers({
|
|
275
|
+
q: (keyword !== null && keyword !== void 0 ? keyword : '').length > 0
|
|
276
|
+
? `name:*${keyword}* OR email:*${keyword}*`
|
|
277
|
+
: undefined,
|
|
278
|
+
include_totals: true,
|
|
279
|
+
page: page++,
|
|
280
|
+
});
|
|
281
|
+
total = r.total;
|
|
282
|
+
sum += r.users.length;
|
|
283
|
+
list.push(...r.users);
|
|
284
|
+
if (limit !== undefined && list.length > limit) {
|
|
285
|
+
return list.slice(0, limit);
|
|
286
|
+
}
|
|
287
|
+
} while (sum < total);
|
|
288
|
+
return list;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
getMembers(orgId, params) {
|
|
292
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
293
|
+
const list = [];
|
|
294
|
+
let page = 0;
|
|
295
|
+
let total = 0;
|
|
296
|
+
let sum = 0;
|
|
297
|
+
const { keyword, limit } = params !== null && params !== void 0 ? params : {};
|
|
298
|
+
const mngClient = yield this.getManagementClient();
|
|
299
|
+
do {
|
|
300
|
+
const r = yield mngClient.organizations.getMembers({
|
|
301
|
+
id: orgId,
|
|
302
|
+
include_totals: true,
|
|
303
|
+
page: page++,
|
|
304
|
+
});
|
|
305
|
+
total = r.total;
|
|
306
|
+
sum += r.members.length;
|
|
307
|
+
if (keyword) {
|
|
308
|
+
list.push(...r.members.filter((it) => (0, utils_1.containsIgnoreCase)(keyword, [it.name, it.email])));
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
list.push(...r.members);
|
|
312
|
+
}
|
|
313
|
+
if (limit !== undefined && list.length > limit) {
|
|
314
|
+
return list.slice(0, limit);
|
|
315
|
+
}
|
|
316
|
+
} while (sum < total);
|
|
317
|
+
return list;
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
createUser(payload) {
|
|
321
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
322
|
+
const mngClient = yield this.getManagementClient();
|
|
323
|
+
return yield mngClient.createUser(Object.assign({ connection: 'Username-Password-Authentication' }, payload));
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
assignRolestoUser(userId, payload) {
|
|
327
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
328
|
+
const mngClient = yield this.getManagementClient();
|
|
329
|
+
yield mngClient.assignRolestoUser({ id: userId }, payload);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
addMembers(orgId, payload) {
|
|
333
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
const mngClient = yield this.getManagementClient();
|
|
335
|
+
yield mngClient.organizations.addMembers({ id: orgId }, payload);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
scan(params) {
|
|
339
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
340
|
+
const { targetResourceType, parentTarget, keyword, limit } = params;
|
|
341
|
+
switch (targetResourceType) {
|
|
342
|
+
case 'IamClient': {
|
|
343
|
+
const clients = yield this.getClients({
|
|
344
|
+
keyword,
|
|
345
|
+
limit,
|
|
346
|
+
});
|
|
347
|
+
const rdb = new resource_1.ResultSetDataBuilder([
|
|
348
|
+
(0, resource_1.createRdhKey)({ name: 'client_id', type: types_1.GeneralColumnType.TEXT }),
|
|
349
|
+
(0, resource_1.createRdhKey)({ name: 'name', type: types_1.GeneralColumnType.TEXT }),
|
|
350
|
+
(0, resource_1.createRdhKey)({ name: 'description', type: types_1.GeneralColumnType.TEXT }),
|
|
351
|
+
(0, resource_1.createRdhKey)({ name: 'tenant', type: types_1.GeneralColumnType.TEXT }),
|
|
352
|
+
(0, resource_1.createRdhKey)({ name: 'client_secret', type: types_1.GeneralColumnType.TEXT }),
|
|
353
|
+
(0, resource_1.createRdhKey)({ name: 'app_type', type: types_1.GeneralColumnType.TEXT }),
|
|
354
|
+
(0, resource_1.createRdhKey)({ name: 'logo_uri', type: types_1.GeneralColumnType.TEXT }),
|
|
355
|
+
(0, resource_1.createRdhKey)({
|
|
356
|
+
name: 'is_first_party',
|
|
357
|
+
type: types_1.GeneralColumnType.BOOLEAN,
|
|
358
|
+
}),
|
|
359
|
+
(0, resource_1.createRdhKey)({
|
|
360
|
+
name: 'oidc_conformant',
|
|
361
|
+
type: types_1.GeneralColumnType.BOOLEAN,
|
|
362
|
+
}),
|
|
363
|
+
(0, resource_1.createRdhKey)({ name: 'grant_types', type: types_1.GeneralColumnType.JSON }),
|
|
364
|
+
(0, resource_1.createRdhKey)({
|
|
365
|
+
name: 'custom_login_page_on',
|
|
366
|
+
type: types_1.GeneralColumnType.BOOLEAN,
|
|
367
|
+
}),
|
|
368
|
+
]);
|
|
369
|
+
clients.forEach((client) => {
|
|
370
|
+
rdb.addRow({
|
|
371
|
+
client_id: client.client_id,
|
|
372
|
+
name: client.name,
|
|
373
|
+
description: client.description,
|
|
374
|
+
tenant: client.tenant,
|
|
375
|
+
client_secret: client.client_secret,
|
|
376
|
+
app_type: client.app_type,
|
|
377
|
+
logo_uri: client.logo_uri,
|
|
378
|
+
is_first_party: client.is_first_party,
|
|
379
|
+
oidc_conformant: client.oidc_conformant,
|
|
380
|
+
grant_types: JSON.stringify(client.grant_types),
|
|
381
|
+
custom_login_page_on: client.custom_login_page_on,
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
return rdb.build();
|
|
385
|
+
}
|
|
386
|
+
case 'IamUser': {
|
|
387
|
+
if (parentTarget) {
|
|
388
|
+
const members = yield this.getMembers(parentTarget, {
|
|
389
|
+
limit,
|
|
390
|
+
keyword,
|
|
391
|
+
});
|
|
392
|
+
const rdb = new resource_1.ResultSetDataBuilder([
|
|
393
|
+
(0, resource_1.createRdhKey)({ name: 'user_id', type: types_1.GeneralColumnType.TEXT }),
|
|
394
|
+
(0, resource_1.createRdhKey)({ name: 'name', type: types_1.GeneralColumnType.TEXT }),
|
|
395
|
+
(0, resource_1.createRdhKey)({ name: 'email', type: types_1.GeneralColumnType.TEXT }),
|
|
396
|
+
(0, resource_1.createRdhKey)({ name: 'picture', type: types_1.GeneralColumnType.TEXT }),
|
|
397
|
+
]);
|
|
398
|
+
members.forEach((user) => {
|
|
399
|
+
rdb.addRow({
|
|
400
|
+
user_id: user.user_id,
|
|
401
|
+
name: user.name,
|
|
402
|
+
email: user.email,
|
|
403
|
+
picture: user.picture,
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
return rdb.build();
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
const users = yield this.getUsers({
|
|
410
|
+
keyword,
|
|
411
|
+
limit,
|
|
412
|
+
});
|
|
413
|
+
const rdb = new resource_1.ResultSetDataBuilder([
|
|
414
|
+
(0, resource_1.createRdhKey)({ name: 'user_id', type: types_1.GeneralColumnType.TEXT }),
|
|
415
|
+
(0, resource_1.createRdhKey)({ name: 'name', type: types_1.GeneralColumnType.TEXT }),
|
|
416
|
+
(0, resource_1.createRdhKey)({ name: 'email', type: types_1.GeneralColumnType.TEXT }),
|
|
417
|
+
(0, resource_1.createRdhKey)({
|
|
418
|
+
name: 'created_at',
|
|
419
|
+
type: types_1.GeneralColumnType.TIMESTAMP,
|
|
420
|
+
}),
|
|
421
|
+
(0, resource_1.createRdhKey)({ name: 'last_login', type: types_1.GeneralColumnType.TEXT }),
|
|
422
|
+
(0, resource_1.createRdhKey)({
|
|
423
|
+
name: 'last_password_reset',
|
|
424
|
+
type: types_1.GeneralColumnType.TEXT,
|
|
425
|
+
}),
|
|
426
|
+
(0, resource_1.createRdhKey)({
|
|
427
|
+
name: 'logins_count',
|
|
428
|
+
type: types_1.GeneralColumnType.INTEGER,
|
|
429
|
+
}),
|
|
430
|
+
(0, resource_1.createRdhKey)({ name: 'blocked', type: types_1.GeneralColumnType.BOOLEAN }),
|
|
431
|
+
(0, resource_1.createRdhKey)({
|
|
432
|
+
name: 'email_verified',
|
|
433
|
+
type: types_1.GeneralColumnType.BOOLEAN,
|
|
434
|
+
}),
|
|
435
|
+
(0, resource_1.createRdhKey)({
|
|
436
|
+
name: 'app_metadata',
|
|
437
|
+
type: types_1.GeneralColumnType.JSON,
|
|
438
|
+
}),
|
|
439
|
+
(0, resource_1.createRdhKey)({
|
|
440
|
+
name: 'user_metadata',
|
|
441
|
+
type: types_1.GeneralColumnType.JSON,
|
|
442
|
+
}),
|
|
443
|
+
]);
|
|
444
|
+
users.forEach((user) => {
|
|
445
|
+
rdb.addRow({
|
|
446
|
+
user_id: user.user_id,
|
|
447
|
+
username: user.name,
|
|
448
|
+
email: user.email,
|
|
449
|
+
createdTimestamp: (0, utils_1.toDate)(user.created_at),
|
|
450
|
+
last_login: user.last_login,
|
|
451
|
+
last_password_reset: user.last_password_reset,
|
|
452
|
+
logins_count: user.logins_count,
|
|
453
|
+
blocked: user.blocked,
|
|
454
|
+
email_verified: user.email_verified,
|
|
455
|
+
app_metadata: JSON.stringify(user.app_metadata),
|
|
456
|
+
user_metadata: JSON.stringify(user.user_metadata),
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
return rdb.build();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
case 'IamOrganization': {
|
|
463
|
+
const orgs = yield this.getOrganizations({
|
|
464
|
+
keyword,
|
|
465
|
+
limit,
|
|
466
|
+
});
|
|
467
|
+
const rdb = new resource_1.ResultSetDataBuilder([
|
|
468
|
+
(0, resource_1.createRdhKey)({ name: 'id', type: types_1.GeneralColumnType.TEXT }),
|
|
469
|
+
(0, resource_1.createRdhKey)({ name: 'name', type: types_1.GeneralColumnType.TEXT }),
|
|
470
|
+
(0, resource_1.createRdhKey)({ name: 'display_name', type: types_1.GeneralColumnType.TEXT }),
|
|
471
|
+
(0, resource_1.createRdhKey)({
|
|
472
|
+
name: 'branding_logo_url',
|
|
473
|
+
type: types_1.GeneralColumnType.TEXT,
|
|
474
|
+
}),
|
|
475
|
+
(0, resource_1.createRdhKey)({ name: 'metadata', type: types_1.GeneralColumnType.JSON }),
|
|
476
|
+
]);
|
|
477
|
+
orgs.forEach((org) => {
|
|
478
|
+
var _a;
|
|
479
|
+
rdb.addRow({
|
|
480
|
+
id: org.id,
|
|
481
|
+
name: org.name,
|
|
482
|
+
display_name: org.display_name,
|
|
483
|
+
branding_logo_url: (_a = org.branding) === null || _a === void 0 ? void 0 : _a.logo_url,
|
|
484
|
+
metadata: JSON.stringify(org.metadata),
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
return rdb.build();
|
|
488
|
+
}
|
|
489
|
+
case 'IamRole': {
|
|
490
|
+
const roles = yield this.getRoles({
|
|
491
|
+
keyword,
|
|
492
|
+
limit,
|
|
493
|
+
});
|
|
494
|
+
const rdb = new resource_1.ResultSetDataBuilder([
|
|
495
|
+
(0, resource_1.createRdhKey)({ name: 'id', type: types_1.GeneralColumnType.TEXT }),
|
|
496
|
+
(0, resource_1.createRdhKey)({ name: 'name', type: types_1.GeneralColumnType.TEXT }),
|
|
497
|
+
(0, resource_1.createRdhKey)({ name: 'description', type: types_1.GeneralColumnType.TEXT }),
|
|
498
|
+
]);
|
|
499
|
+
roles.forEach((role) => {
|
|
500
|
+
rdb.addRow({
|
|
501
|
+
id: role.id,
|
|
502
|
+
name: role.name,
|
|
503
|
+
description: role.description,
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
return rdb.build();
|
|
507
|
+
}
|
|
508
|
+
default:
|
|
509
|
+
throw new Error(`Not supported resource type ${targetResourceType}`);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
getInfomationSchemasSub() {
|
|
514
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
515
|
+
if (!this.conRes) {
|
|
516
|
+
return [];
|
|
517
|
+
}
|
|
518
|
+
const dbResources = new Array();
|
|
519
|
+
const db = new resource_1.Auth0Database('Auth0');
|
|
520
|
+
const promises = [];
|
|
521
|
+
const setUserCount = (res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
522
|
+
res.numOfUsers = yield this.countUsers();
|
|
523
|
+
});
|
|
524
|
+
const setOrganizationCount = (res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
525
|
+
res.numOfOrganizations = yield this.countOrganizations();
|
|
526
|
+
});
|
|
527
|
+
const setOrganizationRes = (res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
528
|
+
const organizations = yield this.getOrganizations({});
|
|
529
|
+
for (const organization of organizations) {
|
|
530
|
+
const orgRes = new resource_1.IamOrganization(organization.name);
|
|
531
|
+
orgRes['id'] = organization.id;
|
|
532
|
+
orgRes.comment = organization.display_name;
|
|
533
|
+
res.addChild(orgRes);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
promises.push(setUserCount(db));
|
|
537
|
+
promises.push(setOrganizationCount(db));
|
|
538
|
+
promises.push(setOrganizationRes(db));
|
|
539
|
+
yield Promise.all(promises);
|
|
540
|
+
db.comment = `${db.numOfOrganizations} ${(0, pluralize_1.default)('organization', db.numOfOrganizations)}, ${db.numOfUsers} ${(0, pluralize_1.default)('user', db.numOfUsers)}`;
|
|
541
|
+
dbResources.push(db);
|
|
542
|
+
return dbResources;
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
closeSub() {
|
|
546
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
547
|
+
this.cachedAccessToken = undefined;
|
|
548
|
+
return '';
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
getManagementClient() {
|
|
552
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
553
|
+
const { host, iamSolution } = this.conRes;
|
|
554
|
+
const { clientId, clientSecret } = iamSolution;
|
|
555
|
+
const token = yield this.getAvailableAccessToken();
|
|
556
|
+
const client = new auth0_1.ManagementClient({
|
|
557
|
+
domain: host,
|
|
558
|
+
clientId,
|
|
559
|
+
clientSecret,
|
|
560
|
+
token,
|
|
561
|
+
});
|
|
562
|
+
return client;
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
getAvailableAccessToken() {
|
|
566
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
567
|
+
if (this.cachedAccessToken) {
|
|
568
|
+
const payload = (0, utils_1.decodeToken)(this.cachedAccessToken);
|
|
569
|
+
if (payload.exp - 60 > Math.floor(new Date().getTime() / 1000)) {
|
|
570
|
+
return this.cachedAccessToken;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const { host, iamSolution } = this.conRes;
|
|
574
|
+
const { clientId, clientSecret } = iamSolution;
|
|
575
|
+
const client = new auth0_1.ManagementClient({
|
|
576
|
+
domain: host,
|
|
577
|
+
clientId,
|
|
578
|
+
clientSecret,
|
|
579
|
+
});
|
|
580
|
+
this.cachedAccessToken = yield client.getAccessToken();
|
|
581
|
+
return this.cachedAccessToken;
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
getDefaultAudience() {
|
|
585
|
+
return `https://${this.conRes.host}/api/v2/`;
|
|
586
|
+
}
|
|
587
|
+
getDefaultClientGrantScopes() {
|
|
588
|
+
return [
|
|
589
|
+
'read:client_grants',
|
|
590
|
+
'create:client_grants',
|
|
591
|
+
'delete:client_grants',
|
|
592
|
+
'update:client_grants',
|
|
593
|
+
'read:users',
|
|
594
|
+
'update:users',
|
|
595
|
+
'delete:users',
|
|
596
|
+
'create:users',
|
|
597
|
+
'read:users_app_metadata',
|
|
598
|
+
'update:users_app_metadata',
|
|
599
|
+
'delete:users_app_metadata',
|
|
600
|
+
'create:users_app_metadata',
|
|
601
|
+
'read:user_custom_blocks',
|
|
602
|
+
'create:user_custom_blocks',
|
|
603
|
+
'delete:user_custom_blocks',
|
|
604
|
+
'create:user_tickets',
|
|
605
|
+
'read:clients',
|
|
606
|
+
'update:clients',
|
|
607
|
+
'delete:clients',
|
|
608
|
+
'create:clients',
|
|
609
|
+
'read:connections',
|
|
610
|
+
'update:connections',
|
|
611
|
+
'delete:connections',
|
|
612
|
+
'create:connections',
|
|
613
|
+
'read:stats',
|
|
614
|
+
'read:insights',
|
|
615
|
+
'read:tenant_settings',
|
|
616
|
+
'update:tenant_settings',
|
|
617
|
+
'read:custom_domains',
|
|
618
|
+
'delete:custom_domains',
|
|
619
|
+
'create:custom_domains',
|
|
620
|
+
'update:custom_domains',
|
|
621
|
+
'read:email_templates',
|
|
622
|
+
'create:email_templates',
|
|
623
|
+
'update:email_templates',
|
|
624
|
+
'read:roles',
|
|
625
|
+
'create:roles',
|
|
626
|
+
'delete:roles',
|
|
627
|
+
'update:roles',
|
|
628
|
+
'read:branding',
|
|
629
|
+
'update:branding',
|
|
630
|
+
'delete:branding',
|
|
631
|
+
'create:signing_keys',
|
|
632
|
+
'read:signing_keys',
|
|
633
|
+
'update:signing_keys',
|
|
634
|
+
'read:limits',
|
|
635
|
+
'update:limits',
|
|
636
|
+
'create:role_members',
|
|
637
|
+
'read:role_members',
|
|
638
|
+
'delete:role_members',
|
|
639
|
+
'read:organizations_summary',
|
|
640
|
+
'create:authentication_methods',
|
|
641
|
+
'read:authentication_methods',
|
|
642
|
+
'update:authentication_methods',
|
|
643
|
+
'delete:authentication_methods',
|
|
644
|
+
'read:organizations',
|
|
645
|
+
'update:organizations',
|
|
646
|
+
'create:organizations',
|
|
647
|
+
'delete:organizations',
|
|
648
|
+
'create:organization_members',
|
|
649
|
+
'read:organization_members',
|
|
650
|
+
'delete:organization_members',
|
|
651
|
+
'create:organization_connections',
|
|
652
|
+
'read:organization_connections',
|
|
653
|
+
'update:organization_connections',
|
|
654
|
+
'delete:organization_connections',
|
|
655
|
+
'create:organization_member_roles',
|
|
656
|
+
'read:organization_member_roles',
|
|
657
|
+
'delete:organization_member_roles',
|
|
658
|
+
'create:organization_invitations',
|
|
659
|
+
'read:organization_invitations',
|
|
660
|
+
'delete:organization_invitations',
|
|
661
|
+
'read:client_credentials',
|
|
662
|
+
'create:client_credentials',
|
|
663
|
+
'update:client_credentials',
|
|
664
|
+
'delete:client_credentials',
|
|
665
|
+
];
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
exports.Auth0Driver = Auth0Driver;
|
|
669
|
+
//# sourceMappingURL=Auth0Driver.js.map
|