auth0 3.3.0 → 4.0.0-beta.0
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/README.md +19 -15
- package/package.json +47 -33
- package/CHANGELOG.md +0 -673
- package/src/Auth0RestClient.js +0 -123
- package/src/RetryRestClient.js +0 -105
- package/src/auth/DatabaseAuthenticator.js +0 -282
- package/src/auth/OAUthWithIDTokenValidation.js +0 -124
- package/src/auth/OAuthAuthenticator.js +0 -405
- package/src/auth/PasswordlessAuthenticator.js +0 -303
- package/src/auth/TokensManager.js +0 -254
- package/src/auth/UsersManager.js +0 -161
- package/src/auth/clientAuthentication.js +0 -86
- package/src/auth/idToken.js +0 -167
- package/src/auth/index.js +0 -573
- package/src/errors.js +0 -60
- package/src/index.js +0 -11
- package/src/index.mjs +0 -11
- package/src/management/ActionsManager.js +0 -526
- package/src/management/AttackProtectionManager.js +0 -158
- package/src/management/BaseManager.js +0 -41
- package/src/management/BlacklistedTokensManager.js +0 -67
- package/src/management/BrandingManager.js +0 -250
- package/src/management/ClientCredentialsManager.js +0 -112
- package/src/management/ClientGrantsManager.js +0 -124
- package/src/management/ClientsManager.js +0 -184
- package/src/management/ConnectionsManager.js +0 -213
- package/src/management/CustomDomainsManager.js +0 -141
- package/src/management/DeviceCredentialsManager.js +0 -91
- package/src/management/EmailProviderManager.js +0 -101
- package/src/management/EmailTemplatesManager.js +0 -90
- package/src/management/GrantsManager.js +0 -84
- package/src/management/GuardianManager.js +0 -361
- package/src/management/HooksManager.js +0 -295
- package/src/management/JobsManager.js +0 -324
- package/src/management/LogStreamsManager.js +0 -136
- package/src/management/LogsManager.js +0 -82
- package/src/management/ManagementTokenProvider.js +0 -144
- package/src/management/MigrationsManager.js +0 -76
- package/src/management/OrganizationsManager.js +0 -721
- package/src/management/PromptsManager.js +0 -162
- package/src/management/ResourceServersManager.js +0 -143
- package/src/management/RolesManager.js +0 -329
- package/src/management/RulesConfigsManager.js +0 -86
- package/src/management/RulesManager.js +0 -148
- package/src/management/StatsManager.js +0 -84
- package/src/management/TenantManager.js +0 -76
- package/src/management/TicketsManager.js +0 -104
- package/src/management/UserBlocksManager.js +0 -121
- package/src/management/UsersManager.js +0 -882
- package/src/management/index.js +0 -3405
- package/src/utils.js +0 -60
|
@@ -1,882 +0,0 @@
|
|
|
1
|
-
const { ArgumentError } = require('rest-facade');
|
|
2
|
-
const BaseManager = require('./BaseManager');
|
|
3
|
-
|
|
4
|
-
const { sanitizeArguments } = require('../utils');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Abstracts interaction with the users endpoint.
|
|
8
|
-
*/
|
|
9
|
-
class UsersManager extends BaseManager {
|
|
10
|
-
/**
|
|
11
|
-
* @param {object} options The client options.
|
|
12
|
-
* @param {string} options.baseUrl The URL of the API.
|
|
13
|
-
* @param {object} [options.headers] Headers to be included in all requests.
|
|
14
|
-
* @param {object} [options.retry] Retry Policy Config
|
|
15
|
-
*/
|
|
16
|
-
constructor(options) {
|
|
17
|
-
super(options);
|
|
18
|
-
|
|
19
|
-
this.users = this._getRestClient('/users/:id');
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Provides an abstraction layer for consuming the
|
|
23
|
-
* {@link https://auth0.com/docs/api/v2#!/Users/delete_multifactor_by_provider
|
|
24
|
-
* Multifactor Provider endpoint}.
|
|
25
|
-
*
|
|
26
|
-
* @type {external:RestClient}
|
|
27
|
-
*/
|
|
28
|
-
this.multifactor = this._getRestClient('/users/:id/multifactor/:provider');
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Provides a simple abstraction layer for linking user accounts.
|
|
32
|
-
*
|
|
33
|
-
* @type {external:RestClient}
|
|
34
|
-
*/
|
|
35
|
-
this.identities = this._getRestClient('/users/:id/identities/:provider/:user_id');
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Provides a simple abstraction layer for user logs
|
|
39
|
-
*
|
|
40
|
-
* @type {external:RestClient}
|
|
41
|
-
*/
|
|
42
|
-
this.userLogs = this._getRestClient('/users/:id/logs');
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Provides an abstraction layer for retrieving Guardian enrollments.
|
|
46
|
-
*
|
|
47
|
-
* @type {external:RestClient}
|
|
48
|
-
*/
|
|
49
|
-
this.enrollments = this._getRestClient('/users/:id/enrollments');
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Provides an abstraction layer for the new "users-by-email" API
|
|
53
|
-
*
|
|
54
|
-
* @type {external:RestClient}
|
|
55
|
-
*/
|
|
56
|
-
this.usersByEmail = this._getRestClient('/users-by-email');
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Provides an abstraction layer for regenerating Guardian recovery codes.
|
|
60
|
-
*
|
|
61
|
-
* @type {external:RestClient}
|
|
62
|
-
*/
|
|
63
|
-
this.recoveryCodeRegenerations = this._getRestClient('/users/:id/recovery-code-regeneration');
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Provides an abstraction layer for invalidating all remembered browsers for MFA.
|
|
67
|
-
*
|
|
68
|
-
* @type {external:RestClient}
|
|
69
|
-
*/
|
|
70
|
-
this.invalidateRememberBrowsers = this._getRestClient(
|
|
71
|
-
'/users/:id/multifactor/actions/invalidate-remember-browser'
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Provides an abstraction layer for CRD on roles for a user
|
|
76
|
-
*
|
|
77
|
-
* @type {external:RestClient}
|
|
78
|
-
*/
|
|
79
|
-
this.roles = this._getRestClient('/users/:id/roles');
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Provides an abstraction layer for CRD on permissions directly on a user
|
|
83
|
-
*
|
|
84
|
-
* @type {external:RestClient}
|
|
85
|
-
*/
|
|
86
|
-
this.permissions = this._getRestClient('/users/:id/permissions');
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* For CRUD on user's authenticators
|
|
90
|
-
*
|
|
91
|
-
* @type {external:RestClient}
|
|
92
|
-
*/
|
|
93
|
-
this.authenticators = this._getRestClient('/users/:id/authenticators');
|
|
94
|
-
|
|
95
|
-
this.organizations = this._getRestClient('/users/:id/organizations');
|
|
96
|
-
|
|
97
|
-
this.authenticationMethods = this._getRestClient(
|
|
98
|
-
'/users/:id/authentication-methods/:authentication_method_id'
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Create a new user.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* management.users.create(data, function (err) {
|
|
107
|
-
* if (err) {
|
|
108
|
-
* // Handle error.
|
|
109
|
-
* }
|
|
110
|
-
*
|
|
111
|
-
* // User created.
|
|
112
|
-
* });
|
|
113
|
-
* @param {object} data User data.
|
|
114
|
-
* @param {Function} [cb] Callback function.
|
|
115
|
-
* @returns {Promise|undefined}
|
|
116
|
-
*/
|
|
117
|
-
create(data, cb) {
|
|
118
|
-
if (cb && cb instanceof Function) {
|
|
119
|
-
return this.users.create(data, cb);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return this.users.create(data);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Get all users.
|
|
127
|
-
*
|
|
128
|
-
* @example <caption>
|
|
129
|
-
* This method takes an optional object as first argument that may be used to
|
|
130
|
-
* specify pagination settings and the search query. If pagination options are
|
|
131
|
-
* not present, the first page of a limited number of results will be returned.
|
|
132
|
-
* </caption>
|
|
133
|
-
*
|
|
134
|
-
* // Pagination settings.
|
|
135
|
-
* var params = {
|
|
136
|
-
* per_page: 10,
|
|
137
|
-
* page: 0
|
|
138
|
-
* };
|
|
139
|
-
*
|
|
140
|
-
* management.users.getAll(params, function (err, users) {
|
|
141
|
-
* console.log(users.length);
|
|
142
|
-
* });
|
|
143
|
-
* @param {object} [params] Users params.
|
|
144
|
-
* @param {number} [params.per_page] Number of results per page.
|
|
145
|
-
* @param {number} [params.page] Page number, zero indexed.
|
|
146
|
-
* @param {Function} [cb] Callback function.
|
|
147
|
-
* @returns {Promise|undefined}
|
|
148
|
-
*/
|
|
149
|
-
getAll(...args) {
|
|
150
|
-
return this.users.getAll(...args);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Get Users by an Email Address
|
|
155
|
-
*
|
|
156
|
-
* @example <caption>
|
|
157
|
-
* This method takes a first argument as the Email address to look for
|
|
158
|
-
* users, and uses the /users-by-email API, not the search API
|
|
159
|
-
* </caption>
|
|
160
|
-
*
|
|
161
|
-
* management.users.getByEmail('email@address', function (err, users) {
|
|
162
|
-
* console.log(users);
|
|
163
|
-
* });
|
|
164
|
-
* @param {string} [email] Email address of user(s) to find
|
|
165
|
-
* @param {object} [options] Additional options to pass to the endpoint
|
|
166
|
-
* @param {string} [options.fields] Comma-separated list of fields to include or exclude in the result
|
|
167
|
-
* @param {boolean} [options.include_fields] Whether specified fields are to be included (true) or excluded (false). Defaults to true.
|
|
168
|
-
* @param {Function} [cb] Callback function.
|
|
169
|
-
* @returns {Promise|undefined}
|
|
170
|
-
*/
|
|
171
|
-
getByEmail(email, options, cb) {
|
|
172
|
-
const { options: sanitizedOptions, cb: sanitizedCb } = sanitizeArguments(options, cb);
|
|
173
|
-
|
|
174
|
-
return this.usersByEmail.getAll({ email, ...sanitizedOptions }, sanitizedCb);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Get a user by its id.
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* management.users.get({ id: USER_ID }, function (err, user) {
|
|
182
|
-
* console.log(user);
|
|
183
|
-
* });
|
|
184
|
-
* @param {object} data The user data object.
|
|
185
|
-
* @param {string} data.id The user id.
|
|
186
|
-
* @param {Function} [cb] Callback function.
|
|
187
|
-
* @returns {Promise|undefined}
|
|
188
|
-
*/
|
|
189
|
-
get(...args) {
|
|
190
|
-
return this.users.get(...args);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Update a user by its id.
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* var params = { id: USER_ID };
|
|
198
|
-
*
|
|
199
|
-
* management.users.update(params, data, function (err, user) {
|
|
200
|
-
* if (err) {
|
|
201
|
-
* // Handle error.
|
|
202
|
-
* }
|
|
203
|
-
*
|
|
204
|
-
* // Updated user.
|
|
205
|
-
* console.log(user);
|
|
206
|
-
* });
|
|
207
|
-
* @param {object} params The user parameters.
|
|
208
|
-
* @param {string} params.id The user id.
|
|
209
|
-
* @param {object} data New user data.
|
|
210
|
-
* @param {Function} [cb] Callback function
|
|
211
|
-
* @returns {Promise|undefined}
|
|
212
|
-
*/
|
|
213
|
-
update(...args) {
|
|
214
|
-
return this.users.patch(...args);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Update the user metadata.
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* var params = { id: USER_ID };
|
|
222
|
-
* var metadata = {
|
|
223
|
-
* address: '123th Node.js Street'
|
|
224
|
-
* };
|
|
225
|
-
*
|
|
226
|
-
* management.users.updateUserMetadata(params, metadata, function (err, user) {
|
|
227
|
-
* if (err) {
|
|
228
|
-
* // Handle error.
|
|
229
|
-
* }
|
|
230
|
-
*
|
|
231
|
-
* // Updated user.
|
|
232
|
-
* console.log(user);
|
|
233
|
-
* });
|
|
234
|
-
* @param {object} params The user data object..
|
|
235
|
-
* @param {string} params.id The user id.
|
|
236
|
-
* @param {object} metadata New user metadata.
|
|
237
|
-
* @param {Function} [cb] Callback function
|
|
238
|
-
* @returns {Promise|undefined}
|
|
239
|
-
*/
|
|
240
|
-
updateUserMetadata(params, metadata, cb) {
|
|
241
|
-
const data = {
|
|
242
|
-
user_metadata: metadata,
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
if (cb && cb instanceof Function) {
|
|
246
|
-
return this.users.patch(params, data, cb);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return this.users.patch(params, data);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Update the app metadata.
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* var params = { id: USER_ID };
|
|
257
|
-
* var metadata = {
|
|
258
|
-
* foo: 'bar'
|
|
259
|
-
* };
|
|
260
|
-
*
|
|
261
|
-
* management.users.updateAppMetadata(params, metadata, function (err, user) {
|
|
262
|
-
* if (err) {
|
|
263
|
-
* // Handle error.
|
|
264
|
-
* }
|
|
265
|
-
*
|
|
266
|
-
* // Updated user.
|
|
267
|
-
* console.log(user);
|
|
268
|
-
* });
|
|
269
|
-
* @param {object} params The user data object..
|
|
270
|
-
* @param {string} params.id The user id.
|
|
271
|
-
* @param {object} metadata New app metadata.
|
|
272
|
-
* @param {Function} [cb] Callback function
|
|
273
|
-
* @returns {Promise|undefined}
|
|
274
|
-
*/
|
|
275
|
-
updateAppMetadata(params, metadata, cb) {
|
|
276
|
-
const data = {
|
|
277
|
-
app_metadata: metadata,
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
if (cb && cb instanceof Function) {
|
|
281
|
-
return this.users.patch(params, data, cb);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return this.users.patch(params, data);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Delete a user by its id.
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* management.users.delete({ id: USER_ID }, function (err) {
|
|
292
|
-
* if (err) {
|
|
293
|
-
* // Handle error.
|
|
294
|
-
* }
|
|
295
|
-
*
|
|
296
|
-
* // User deleted.
|
|
297
|
-
* });
|
|
298
|
-
* @param {object} params The user data object..
|
|
299
|
-
* @param {string} params.id The user id.
|
|
300
|
-
* @param {Function} [cb] Callback function
|
|
301
|
-
* @returns {Promise|undefined}
|
|
302
|
-
*/
|
|
303
|
-
delete(params, ...restOfArgs) {
|
|
304
|
-
if (typeof params !== 'object' || typeof params.id !== 'string') {
|
|
305
|
-
throw new ArgumentError('You must provide an id for the delete method');
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return this.users.delete(params, ...restOfArgs);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Delete all users.
|
|
313
|
-
*
|
|
314
|
-
* @example
|
|
315
|
-
* management.users.deleteAll(function (err) {
|
|
316
|
-
* if (err) {
|
|
317
|
-
* // Handle error.
|
|
318
|
-
* }
|
|
319
|
-
*
|
|
320
|
-
* // Users deleted
|
|
321
|
-
* });
|
|
322
|
-
* @param {Function} [cb] Callback function
|
|
323
|
-
* @returns {Promise|undefined}
|
|
324
|
-
* @deprecated This method will be removed in the next major release.
|
|
325
|
-
*/
|
|
326
|
-
deleteAll(cb, ...restOfArgs) {
|
|
327
|
-
if (typeof cb !== 'function') {
|
|
328
|
-
const errorMsg = 'The deleteAll method only accepts a callback as argument';
|
|
329
|
-
|
|
330
|
-
throw new ArgumentError(errorMsg);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
return this.users.delete(cb, ...restOfArgs);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Delete a multifactor provider.
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* var params = { id: USER_ID, provider: MULTIFACTOR_PROVIDER };
|
|
341
|
-
*
|
|
342
|
-
* management.users.deleteMultifactorProvider(params, function (err, user) {
|
|
343
|
-
* if (err) {
|
|
344
|
-
* // Handle error.
|
|
345
|
-
* }
|
|
346
|
-
*
|
|
347
|
-
* // Users accounts unlinked.
|
|
348
|
-
* });
|
|
349
|
-
* @param {object} params Data object.
|
|
350
|
-
* @param {string} params.id The user id.
|
|
351
|
-
* @param {string} params.provider Multifactor provider.
|
|
352
|
-
* @param {Function} [cb] Callback function
|
|
353
|
-
* @returns {Promise|undefined}
|
|
354
|
-
*/
|
|
355
|
-
deleteMultifactorProvider(params, cb) {
|
|
356
|
-
params = params || {};
|
|
357
|
-
|
|
358
|
-
if (!params.id || typeof params.id !== 'string') {
|
|
359
|
-
throw new ArgumentError('The id parameter must be a valid user id');
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
if (!params.provider || typeof params.provider !== 'string') {
|
|
363
|
-
throw new ArgumentError('Must specify a provider');
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (cb && cb instanceof Function) {
|
|
367
|
-
return this.multifactor.delete(params, cb);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return this.multifactor.delete(params);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Link the user with another account.
|
|
375
|
-
*
|
|
376
|
-
* @example
|
|
377
|
-
* var userId = 'USER_ID';
|
|
378
|
-
* var params = {
|
|
379
|
-
* user_id: 'OTHER_USER_ID',
|
|
380
|
-
* connection_id: 'CONNECTION_ID'
|
|
381
|
-
* };
|
|
382
|
-
*
|
|
383
|
-
* management.users.link(userId, params, function (err, user) {
|
|
384
|
-
* if (err) {
|
|
385
|
-
* // Handle error.
|
|
386
|
-
* }
|
|
387
|
-
*
|
|
388
|
-
* // Users linked.
|
|
389
|
-
* });
|
|
390
|
-
* @param {string} userId ID of the primary user.
|
|
391
|
-
* @param {object} params Secondary user data.
|
|
392
|
-
* @param {string} params.user_id ID of the user to be linked.
|
|
393
|
-
* @param {string} params.connection_id ID of the connection to be used.
|
|
394
|
-
* @param {string} params.provider Identity provider of the secondary user account being linked.
|
|
395
|
-
* @param {string} params.link_with JWT for the secondary account being linked. If sending this parameter, provider, user_id, and connection_id must not be sent.
|
|
396
|
-
* @param {Function} [cb] Callback function.
|
|
397
|
-
* @returns {Promise|undefined}
|
|
398
|
-
*/
|
|
399
|
-
link(userId, params, cb) {
|
|
400
|
-
const query = { id: userId };
|
|
401
|
-
params = params || {};
|
|
402
|
-
|
|
403
|
-
// Require a user ID.
|
|
404
|
-
if (!userId) {
|
|
405
|
-
throw new ArgumentError('The userId cannot be null or undefined');
|
|
406
|
-
}
|
|
407
|
-
if (typeof userId !== 'string') {
|
|
408
|
-
throw new ArgumentError('The userId has to be a string');
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (cb && cb instanceof Function) {
|
|
412
|
-
return this.identities.create(query, params, cb);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return this.identities.create(query, params);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Unlink the given accounts.
|
|
420
|
-
*
|
|
421
|
-
* @example
|
|
422
|
-
* var params = { id: USER_ID, provider: 'auht0', user_id: OTHER_USER_ID };
|
|
423
|
-
*
|
|
424
|
-
* management.users.unlink(params, function (err, user) {
|
|
425
|
-
* if (err) {
|
|
426
|
-
* // Handle error.
|
|
427
|
-
* }
|
|
428
|
-
*
|
|
429
|
-
* // Users accounts unlinked.
|
|
430
|
-
* });
|
|
431
|
-
* @param {object} params Linked users data.
|
|
432
|
-
* @param {string} params.id Primary user ID.
|
|
433
|
-
* @param {string} params.provider Identity provider in use.
|
|
434
|
-
* @param {string} params.user_id Secondary user ID.
|
|
435
|
-
* @param {Function} [cb] Callback function.
|
|
436
|
-
* @returns {Promise|undefined}
|
|
437
|
-
*/
|
|
438
|
-
unlink(params, cb) {
|
|
439
|
-
params = params || {};
|
|
440
|
-
|
|
441
|
-
if (!params.id || typeof params.id !== 'string') {
|
|
442
|
-
throw new ArgumentError('id field is required');
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
if (!params.user_id || typeof params.user_id !== 'string') {
|
|
446
|
-
throw new ArgumentError('user_id field is required');
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if (!params.provider || typeof params.provider !== 'string') {
|
|
450
|
-
throw new ArgumentError('provider field is required');
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
if (cb && cb instanceof Function) {
|
|
454
|
-
return this.identities.delete(params, cb);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return this.identities.delete(params);
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Get user's log events.
|
|
462
|
-
*
|
|
463
|
-
* @example
|
|
464
|
-
* var params = { id: USER_ID, page: 0, per_page: 50, sort: 'date:-1', include_totals: true };
|
|
465
|
-
*
|
|
466
|
-
* management.users.logs(params, function (err, logs) {
|
|
467
|
-
* if (err) {
|
|
468
|
-
* // Handle error.
|
|
469
|
-
* }
|
|
470
|
-
*
|
|
471
|
-
* console.log(logs);
|
|
472
|
-
* });
|
|
473
|
-
* @param {object} params Get logs data.
|
|
474
|
-
* @param {string} params.id User id.
|
|
475
|
-
* @param {number} params.per_page Number of results per page.
|
|
476
|
-
* @param {number} params.page Page number, zero indexed.
|
|
477
|
-
* @param {string} params.sort The field to use for sorting. Use field:order where order is 1 for ascending and -1 for descending. For example date:-1.
|
|
478
|
-
* @param {boolean} params.include_totals true if a query summary must be included in the result, false otherwise. Default false;
|
|
479
|
-
* @param {Function} [cb] Callback function.
|
|
480
|
-
* @returns {Promise|undefined}
|
|
481
|
-
*/
|
|
482
|
-
logs(params, cb) {
|
|
483
|
-
params = params || {};
|
|
484
|
-
|
|
485
|
-
if (!params.id || typeof params.id !== 'string') {
|
|
486
|
-
throw new ArgumentError('id field is required');
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
return this.userLogs.get(params, cb);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Get a list of Guardian enrollments.
|
|
494
|
-
*
|
|
495
|
-
* @example
|
|
496
|
-
* management.users.getGuardianEnrollments({ id: USER_ID }, function (err, enrollments) {
|
|
497
|
-
* console.log(enrollments);
|
|
498
|
-
* });
|
|
499
|
-
* @param {object} data The user data object.
|
|
500
|
-
* @param {string} data.id The user id.
|
|
501
|
-
* @param {Function} [cb] Callback function.
|
|
502
|
-
* @returns {Promise|undefined}
|
|
503
|
-
*/
|
|
504
|
-
getGuardianEnrollments(...args) {
|
|
505
|
-
return this.enrollments.get(...args);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* Generate new Guardian recovery code.
|
|
510
|
-
*
|
|
511
|
-
* @example
|
|
512
|
-
* management.users.regenerateRecoveryCode("USER_ID", function (err, result) {
|
|
513
|
-
* console.log(result.recovery_code);
|
|
514
|
-
* });
|
|
515
|
-
* @param {object} params Get logs data.
|
|
516
|
-
* @param {string} params.id User id.
|
|
517
|
-
* @param {Function} [cb] Callback function.
|
|
518
|
-
* @returns {Promise|undefined}
|
|
519
|
-
*/
|
|
520
|
-
regenerateRecoveryCode(params, cb) {
|
|
521
|
-
if (!params || !params.id) {
|
|
522
|
-
throw new ArgumentError('The userId cannot be null or undefined');
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
if (cb && cb instanceof Function) {
|
|
526
|
-
return this.recoveryCodeRegenerations.create(params, {}, cb);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return this.recoveryCodeRegenerations.create(params, {});
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Invalidate all remembered browsers for MFA.
|
|
534
|
-
*
|
|
535
|
-
* @example
|
|
536
|
-
* management.users.invalidateRememberBrowser({ id: USER_ID }, function (err, result) {
|
|
537
|
-
* if (err) {
|
|
538
|
-
* // Handle error.
|
|
539
|
-
* }
|
|
540
|
-
*
|
|
541
|
-
* // Invalidated all remembered browsers.
|
|
542
|
-
* });
|
|
543
|
-
* @param {object} params The user data object.
|
|
544
|
-
* @param {string} params.id The user id.
|
|
545
|
-
* @param {Function} [cb] Callback function.
|
|
546
|
-
* @returns {Promise|undefined}
|
|
547
|
-
*/
|
|
548
|
-
invalidateRememberBrowser(params, cb) {
|
|
549
|
-
if (!params || !params.id) {
|
|
550
|
-
throw new ArgumentError('The userId cannot be null or undefined');
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
if (cb && cb instanceof Function) {
|
|
554
|
-
return this.invalidateRememberBrowsers.create(params, {}, cb);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
return this.invalidateRememberBrowsers.create(params, {});
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* Get a list of roles for a user.
|
|
562
|
-
*
|
|
563
|
-
* @example
|
|
564
|
-
* management.users.getRoles({ id: USER_ID }, function (err, roles) {
|
|
565
|
-
* console.log(roles);
|
|
566
|
-
* });
|
|
567
|
-
* @param {object} data The user data object.
|
|
568
|
-
* @param {string} data.id The user id.
|
|
569
|
-
* @param {Function} [cb] Callback function.
|
|
570
|
-
* @returns {Promise|undefined}
|
|
571
|
-
*/
|
|
572
|
-
getRoles(...args) {
|
|
573
|
-
return this.roles.getAll(...args);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* Assign roles to a user
|
|
578
|
-
*
|
|
579
|
-
* @example
|
|
580
|
-
* var params = { id : 'USER_ID';
|
|
581
|
-
* var data = { "roles" : ["roleId1", "roleID2"]};
|
|
582
|
-
*
|
|
583
|
-
* management.users.assignRoles(params, data, function (err, user) {
|
|
584
|
-
* if (err) {
|
|
585
|
-
* // Handle error.
|
|
586
|
-
* }
|
|
587
|
-
*
|
|
588
|
-
* // roles added.
|
|
589
|
-
* });
|
|
590
|
-
* @param {object} params params object
|
|
591
|
-
* @param {string} params.id user_id
|
|
592
|
-
* @param {string} data data object containing list of role IDs
|
|
593
|
-
* @param {string} data.roles Array of role IDs
|
|
594
|
-
* @param {Function} [cb] Callback function.
|
|
595
|
-
* @returns {Promise|undefined}
|
|
596
|
-
*/
|
|
597
|
-
|
|
598
|
-
assignRoles(params, data, cb) {
|
|
599
|
-
const query = params || {};
|
|
600
|
-
data = data || {};
|
|
601
|
-
|
|
602
|
-
// Require a user ID.
|
|
603
|
-
if (!params.id) {
|
|
604
|
-
throw new ArgumentError('The user_id cannot be null or undefined');
|
|
605
|
-
}
|
|
606
|
-
if (typeof params.id !== 'string') {
|
|
607
|
-
throw new ArgumentError('The user_id has to be a string');
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
if (cb && cb instanceof Function) {
|
|
611
|
-
return this.roles.create(query, data, cb);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
return this.roles.create(query, data);
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
/**
|
|
618
|
-
* Remove roles from a user
|
|
619
|
-
*
|
|
620
|
-
* @example
|
|
621
|
-
* var params = { id : 'USER_ID';
|
|
622
|
-
* var data = { "roles" : ["roleId1", "roleID2"]};
|
|
623
|
-
*
|
|
624
|
-
* management.users.removeRoles(params, data, function (err, user) {
|
|
625
|
-
* if (err) {
|
|
626
|
-
* // Handle error.
|
|
627
|
-
* }
|
|
628
|
-
*
|
|
629
|
-
* // roles removed.
|
|
630
|
-
* });
|
|
631
|
-
* @param {object} params params object
|
|
632
|
-
* @param {string} params.id user_id
|
|
633
|
-
* @param {string} data data object containing list of role IDs
|
|
634
|
-
* @param {string} data.roles Array of role IDs
|
|
635
|
-
* @param {Function} [cb] Callback function.
|
|
636
|
-
* @returns {Promise|undefined}
|
|
637
|
-
*/
|
|
638
|
-
|
|
639
|
-
removeRoles(params, data, cb) {
|
|
640
|
-
const query = params || {};
|
|
641
|
-
data = data || {};
|
|
642
|
-
|
|
643
|
-
// Require a user ID.
|
|
644
|
-
if (!params.id) {
|
|
645
|
-
throw new ArgumentError('The user_id cannot be null or undefined');
|
|
646
|
-
}
|
|
647
|
-
if (typeof params.id !== 'string') {
|
|
648
|
-
throw new ArgumentError('The user_id has to be a string');
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
if (cb && cb instanceof Function) {
|
|
652
|
-
return this.roles.delete(query, data, cb);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
return this.roles.delete(query, data);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Get a list of permissions for a user.
|
|
660
|
-
*
|
|
661
|
-
* @example
|
|
662
|
-
* management.users.getPermissions({ id: USER_ID }, function (err, permissions) {
|
|
663
|
-
* console.log(permissions);
|
|
664
|
-
* });
|
|
665
|
-
* @param {object} data The user data object.
|
|
666
|
-
* @param {string} data.id The user id.
|
|
667
|
-
* @param {Function} [cb] Callback function.
|
|
668
|
-
* @returns {Promise|undefined}
|
|
669
|
-
*/
|
|
670
|
-
getPermissions(...args) {
|
|
671
|
-
return this.permissions.getAll(...args);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
/**
|
|
675
|
-
* Assign permissions to a user
|
|
676
|
-
*
|
|
677
|
-
* @example
|
|
678
|
-
* var params = { id : 'USER_ID';
|
|
679
|
-
* var data = { "permissions" : [{"permission_name" :"do:something" ,"resource_server_identifier" :"test123" }]};
|
|
680
|
-
*
|
|
681
|
-
* management.users.assignPermissions(params, data, function (err, user) {
|
|
682
|
-
* if (err) {
|
|
683
|
-
* // Handle error.
|
|
684
|
-
* }
|
|
685
|
-
*
|
|
686
|
-
* // permissions added.
|
|
687
|
-
* });
|
|
688
|
-
* @param {object} params params object
|
|
689
|
-
* @param {string} params.id user_id
|
|
690
|
-
* @param {string} data data object containing list of permissions
|
|
691
|
-
* @param {string} data.permissions Array of permission IDs
|
|
692
|
-
* @param {Function} [cb] Callback function.
|
|
693
|
-
* @returns {Promise|undefined}
|
|
694
|
-
*/
|
|
695
|
-
|
|
696
|
-
assignPermissions(params, data, cb) {
|
|
697
|
-
const query = params || {};
|
|
698
|
-
data = data || {};
|
|
699
|
-
|
|
700
|
-
// Require a user ID.
|
|
701
|
-
if (!params.id) {
|
|
702
|
-
throw new ArgumentError('The user_id cannot be null or undefined');
|
|
703
|
-
}
|
|
704
|
-
if (typeof params.id !== 'string') {
|
|
705
|
-
throw new ArgumentError('The user_id has to be a string');
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
if (cb && cb instanceof Function) {
|
|
709
|
-
return this.permissions.create(query, data, cb);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
return this.permissions.create(query, data);
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
/**
|
|
716
|
-
* Remove permissions from a user
|
|
717
|
-
*
|
|
718
|
-
* @example
|
|
719
|
-
* var params = { id : 'USER_ID';
|
|
720
|
-
* var data = { "permissions" : [{"permission_name" :"do:something" ,"resource_server_identifier" :"test123" }]};
|
|
721
|
-
*
|
|
722
|
-
* management.users.removePermissions(params, data, function (err, user) {
|
|
723
|
-
* if (err) {
|
|
724
|
-
* // Handle error.
|
|
725
|
-
* }
|
|
726
|
-
*
|
|
727
|
-
* // permissions removed.
|
|
728
|
-
* });
|
|
729
|
-
* @param {object} params params object
|
|
730
|
-
* @param {string} params.id user_id
|
|
731
|
-
* @param {object} data data object containing list of permission IDs
|
|
732
|
-
* @param {string} data.permissions Array of permission IDs
|
|
733
|
-
* @param {Function} [cb] Callback function.
|
|
734
|
-
* @returns {Promise|undefined}
|
|
735
|
-
*/
|
|
736
|
-
|
|
737
|
-
removePermissions(params, data, cb) {
|
|
738
|
-
const query = params || {};
|
|
739
|
-
data = data || {};
|
|
740
|
-
|
|
741
|
-
// Require a user ID.
|
|
742
|
-
if (!params.id) {
|
|
743
|
-
throw new ArgumentError('The user_id cannot be null or undefined');
|
|
744
|
-
}
|
|
745
|
-
if (typeof params.id !== 'string') {
|
|
746
|
-
throw new ArgumentError('The user_id has to be a string');
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
if (cb && cb instanceof Function) {
|
|
750
|
-
return this.permissions.delete(query, data, cb);
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
return this.permissions.delete(query, data);
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
deleteAllAuthenticators(params, cb) {
|
|
757
|
-
const query = params || {};
|
|
758
|
-
|
|
759
|
-
// Require a user ID.
|
|
760
|
-
if (!query.id) {
|
|
761
|
-
throw new ArgumentError('The user_id cannot be null or undefined');
|
|
762
|
-
}
|
|
763
|
-
if (typeof query.id !== 'string') {
|
|
764
|
-
throw new ArgumentError('The user_id has to be a string');
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
if (cb && cb instanceof Function) {
|
|
768
|
-
return this.authenticators.delete(query, cb);
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
return this.authenticators.delete(query);
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
/**
|
|
775
|
-
* Get a list of organizations for a user.
|
|
776
|
-
*
|
|
777
|
-
* @example
|
|
778
|
-
* management.users.getUserOrganizations({ id: USER_ID }, function (err, orgs) {
|
|
779
|
-
* console.log(orgs);
|
|
780
|
-
* });
|
|
781
|
-
* @param {object} data The user data object.
|
|
782
|
-
* @param {string} data.id The user id.
|
|
783
|
-
* @param {Function} [cb] Callback function.
|
|
784
|
-
* @returns {Promise|undefined}
|
|
785
|
-
*/
|
|
786
|
-
getUserOrganizations(...args) {
|
|
787
|
-
return this.organizations.getAll(...args);
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* Gets a list of authentication methods.
|
|
792
|
-
*
|
|
793
|
-
* @param {object} params The user data object.
|
|
794
|
-
* @param {string} params.id The user id.
|
|
795
|
-
* @param {Function} [cb] Callback function.
|
|
796
|
-
* @returns {Promise|undefined}
|
|
797
|
-
*/
|
|
798
|
-
getAuthenticationMethods(...args) {
|
|
799
|
-
return this.authenticationMethods.getAll(...args);
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
/**
|
|
803
|
-
* Gets an authentication method by ID.
|
|
804
|
-
*
|
|
805
|
-
* @param {object} params The user data object.
|
|
806
|
-
* @param {string} params.id The user id.
|
|
807
|
-
* @param {string} params.authentication_method_id The authentication method id.
|
|
808
|
-
* @param {Function} [cb] Callback function.
|
|
809
|
-
* @returns {Promise|undefined}
|
|
810
|
-
*/
|
|
811
|
-
getAuthenticationMethodById(...args) {
|
|
812
|
-
return this.authenticationMethods.get(...args);
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
* Creates an authentication method for a given user.
|
|
817
|
-
*
|
|
818
|
-
* @param {object} params The user data object.
|
|
819
|
-
* @param {string} params.id The user id.
|
|
820
|
-
* @param {object} data Authentication method data.
|
|
821
|
-
* @param {Function} [cb] Callback function.
|
|
822
|
-
* @returns {Promise|undefined}
|
|
823
|
-
*/
|
|
824
|
-
createAuthenticationMethod(...args) {
|
|
825
|
-
return this.authenticationMethods.create(...args);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
/**
|
|
829
|
-
* Updates all authentication methods for a user by replacing them with the given ones.
|
|
830
|
-
*
|
|
831
|
-
* @param {object} params The user data object.
|
|
832
|
-
* @param {string} params.id The user id.
|
|
833
|
-
* @param {object} data Updated authentication method data.
|
|
834
|
-
* @param {Function} [cb] Callback function.
|
|
835
|
-
* @returns {Promise|undefined}
|
|
836
|
-
*/
|
|
837
|
-
updateAuthenticationMethods(...args) {
|
|
838
|
-
return this.authenticationMethods.update(...args);
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
/**
|
|
842
|
-
* Updates an authentication method.
|
|
843
|
-
*
|
|
844
|
-
* @param {object} params The user data object.
|
|
845
|
-
* @param {string} params.id The user id.
|
|
846
|
-
* @param {string} params.authentication_method_id The authentication method id.
|
|
847
|
-
* @param {object} data Updated authentication method data.
|
|
848
|
-
* @param {Function} [cb] Callback function.
|
|
849
|
-
* @returns {Promise|undefined}
|
|
850
|
-
*/
|
|
851
|
-
updateAuthenticationMethodById(...args) {
|
|
852
|
-
return this.authenticationMethods.patch(...args);
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
/**
|
|
856
|
-
* Deletes all authentication methods for the given user.
|
|
857
|
-
*
|
|
858
|
-
* @param {object} params The user data object.
|
|
859
|
-
* @param {string} params.id The user id.
|
|
860
|
-
* @param {Function} [cb] Callback function.
|
|
861
|
-
* @returns {Promise|undefined}
|
|
862
|
-
*/
|
|
863
|
-
deleteAuthenticationMethods(...args) {
|
|
864
|
-
return this.authenticationMethods.delete(...args);
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
/**
|
|
868
|
-
* Deletes an authentication method by ID.
|
|
869
|
-
*
|
|
870
|
-
* @param {object} params The user data object.
|
|
871
|
-
* @param {string} params.id The user id.
|
|
872
|
-
* @param {string} params.authentication_method_id The authentication method id.
|
|
873
|
-
* @param {object} data Updated authentication method data.
|
|
874
|
-
* @param {Function} [cb] Callback function.
|
|
875
|
-
* @returns {Promise|undefined}
|
|
876
|
-
*/
|
|
877
|
-
deleteAuthenticationMethodById(...args) {
|
|
878
|
-
return this.authenticationMethods.delete(...args);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
module.exports = UsersManager;
|