auth0 2.36.0 → 2.38.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +554 -0
  2. package/README.md +33 -11
  3. package/package.json +22 -15
  4. package/src/Auth0RestClient.js +72 -71
  5. package/src/RetryRestClient.js +78 -81
  6. package/src/auth/DatabaseAuthenticator.js +242 -259
  7. package/src/auth/OAUthWithIDTokenValidation.js +99 -103
  8. package/src/auth/OAuthAuthenticator.js +325 -344
  9. package/src/auth/PasswordlessAuthenticator.js +237 -252
  10. package/src/auth/TokensManager.js +231 -246
  11. package/src/auth/UsersManager.js +149 -160
  12. package/src/auth/idToken.js +22 -19
  13. package/src/auth/index.js +510 -581
  14. package/src/errors.js +23 -23
  15. package/src/index.js +3 -2
  16. package/src/management/ActionsManager.js +503 -585
  17. package/src/management/BlacklistedTokensManager.js +77 -84
  18. package/src/management/BrandingManager.js +141 -163
  19. package/src/management/ClientGrantsManager.js +132 -145
  20. package/src/management/ClientsManager.js +145 -161
  21. package/src/management/ConnectionsManager.js +215 -204
  22. package/src/management/CustomDomainsManager.js +140 -157
  23. package/src/management/DeviceCredentialsManager.js +95 -111
  24. package/src/management/EmailProviderManager.js +110 -128
  25. package/src/management/EmailTemplatesManager.js +96 -112
  26. package/src/management/GrantsManager.js +94 -101
  27. package/src/management/GuardianManager.js +381 -455
  28. package/src/management/HooksManager.js +283 -325
  29. package/src/management/JobsManager.js +310 -343
  30. package/src/management/LogStreamsManager.js +142 -158
  31. package/src/management/LogsManager.js +92 -99
  32. package/src/management/ManagementTokenProvider.js +112 -120
  33. package/src/management/MigrationsManager.js +81 -90
  34. package/src/management/OrganizationsManager.js +686 -761
  35. package/src/management/PromptsManager.js +160 -178
  36. package/src/management/ResourceServersManager.js +143 -160
  37. package/src/management/RolesManager.js +323 -369
  38. package/src/management/RulesConfigsManager.js +94 -110
  39. package/src/management/RulesManager.js +154 -176
  40. package/src/management/StatsManager.js +87 -103
  41. package/src/management/TenantManager.js +81 -97
  42. package/src/management/TicketsManager.js +107 -115
  43. package/src/management/UserBlocksManager.js +135 -162
  44. package/src/management/UsersManager.js +729 -852
  45. package/src/management/index.js +3094 -3619
  46. package/src/utils.js +31 -60
@@ -1,368 +1,326 @@
1
- var ArgumentError = require('rest-facade').ArgumentError;
2
- var utils = require('../utils');
3
- var Auth0RestClient = require('../Auth0RestClient');
4
- var RetryRestClient = require('../RetryRestClient');
1
+ const { ArgumentError } = require('rest-facade');
2
+ const Auth0RestClient = require('../Auth0RestClient');
3
+ const RetryRestClient = require('../RetryRestClient');
5
4
 
6
5
  /**
7
- * Simple facade for consuming a REST API endpoint.
8
- * @external RestClient
9
- * @see https://github.com/ngonzalvez/rest-facade
10
- */
11
-
12
- /**
13
- * @class HooksManager
14
6
  * The hooks manager class provides a simple abstraction for performing CRUD operations
15
7
  * on Auth0 HooksManagers.
16
- * @constructor
17
- * @memberOf module:management
18
- *
19
- * @param {Object} options The client options.
20
- * @param {String} options.baseUrl The URL of the API.
21
- * @param {Object} [options.headers] Headers to be included in all requests.
22
- * @param {Object} [options.retry] Retry Policy Config
23
8
  */
24
- var HooksManager = function(options) {
25
- if (options === null || typeof options !== 'object') {
26
- throw new ArgumentError('Must provide manager options');
9
+ class HooksManager {
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
+ if (options === null || typeof options !== 'object') {
18
+ throw new ArgumentError('Must provide manager options');
19
+ }
20
+
21
+ if (options.baseUrl === null || options.baseUrl === undefined) {
22
+ throw new ArgumentError('Must provide a base URL for the API');
23
+ }
24
+
25
+ if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
26
+ throw new ArgumentError('The provided base URL is invalid');
27
+ }
28
+
29
+ /**
30
+ * Options object for the Rest Client instance.
31
+ *
32
+ * @type {object}
33
+ */
34
+ const clientOptions = {
35
+ headers: options.headers,
36
+ query: { repeatParams: false },
37
+ };
38
+
39
+ /**
40
+ * Provides an abstraction layer for performing CRUD operations on
41
+ * {@link https://auth0.com/docs/api/v2#!/HooksManagers Auth0 HooksManagers}.
42
+ *
43
+ * @type {external:RestClient}
44
+ */
45
+ const auth0RestClient = new Auth0RestClient(
46
+ `${options.baseUrl}/hooks/:id`,
47
+ clientOptions,
48
+ options.tokenProvider
49
+ );
50
+ this.resource = new RetryRestClient(auth0RestClient, options.retry);
51
+
52
+ const hookSecretsClient = new Auth0RestClient(
53
+ `${options.baseUrl}/hooks/:id/secrets`,
54
+ clientOptions,
55
+ options.tokenProvider
56
+ );
57
+ this.secrets = new RetryRestClient(hookSecretsClient, options.retry);
27
58
  }
28
59
 
29
- if (options.baseUrl === null || options.baseUrl === undefined) {
30
- throw new ArgumentError('Must provide a base URL for the API');
60
+ /**
61
+ * Create a new hook.
62
+ *
63
+ * @example
64
+ * management.hooks.create(data, function (err) {
65
+ * if (err) {
66
+ * // Handle error.
67
+ * }
68
+ *
69
+ * // Hook created.
70
+ * });
71
+ * @param {object} data Hook data object.
72
+ * @param {Function} [cb] Callback function.
73
+ * @returns {Promise|undefined}
74
+ */
75
+ create(...args) {
76
+ return this.resource.create(...args);
31
77
  }
32
78
 
33
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
34
- throw new ArgumentError('The provided base URL is invalid');
79
+ /**
80
+ * Get all hooks.
81
+ *
82
+ * @example <caption>
83
+ * This method takes an optional object as first argument that may be used to
84
+ * specify pagination settings. If pagination options are not present,
85
+ * the first page of a limited number of results will be returned.
86
+ * </caption>
87
+ *
88
+ * // Pagination settings.
89
+ * var params = {
90
+ * per_page: 10,
91
+ * page: 0
92
+ * };
93
+ *
94
+ * management.hooks.getAll(params, function (err, hooks) {
95
+ * console.log(hooks.length);
96
+ * });
97
+ * @param {object} [params] Hooks parameters.
98
+ * @param {number} [params.per_page] Number of results per page.
99
+ * @param {number} [params.page] Page number, zero indexed.
100
+ * @param {Function} [cb] Callback function.
101
+ * @returns {Promise|undefined}
102
+ */
103
+ getAll(...args) {
104
+ return this.resource.getAll(...args);
35
105
  }
36
106
 
37
107
  /**
38
- * Options object for the Rest Client instance.
108
+ * Get an Auth0 hook.
109
+ *
110
+ * @example
111
+ * management.hooks.get({ id: HOOK_ID }, function (err, hook) {
112
+ * if (err) {
113
+ * // Handle error.
114
+ * }
39
115
  *
40
- * @type {Object}
116
+ * console.log(hook);
117
+ * });
118
+ * @param {object} params Hook parameters.
119
+ * @param {string} params.id Hook ID.
120
+ * @param {Function} [cb] Callback function.
121
+ * @returns {Promise|undefined}
41
122
  */
42
- var clientOptions = {
43
- headers: options.headers,
44
- query: { repeatParams: false }
45
- };
123
+ get(...args) {
124
+ return this.resource.get(...args);
125
+ }
46
126
 
47
127
  /**
48
- * Provides an abstraction layer for performing CRUD operations on
49
- * {@link https://auth0.com/docs/api/v2#!/HooksManagers Auth0 HooksManagers}.
128
+ * Update an existing hook.
129
+ *
130
+ * @example
131
+ * var data = { name: 'New name' };
132
+ * var params = { id: HOOK_ID };
133
+ *
134
+ * // Using auth0 instance.
135
+ * management.updateHook(params, data, function (err, hook) {
136
+ * if (err) {
137
+ * // Handle error.
138
+ * }
139
+ *
140
+ * console.log(hook.name); // 'New name'
141
+ * });
50
142
  *
51
- * @type {external:RestClient}
143
+ * // Using the hooks manager directly.
144
+ * management.hooks.update(params, data, function (err, hook) {
145
+ * if (err) {
146
+ * // Handle error.
147
+ * }
148
+ *
149
+ * console.log(hook.name); // 'New name'
150
+ * });
151
+ * @param {object} params Hook parameters.
152
+ * @param {string} params.id Hook ID.
153
+ * @param {object} data Updated hook data.
154
+ * @param {Function} [cb] Callback function.
155
+ * @returns {Promise|undefined}
52
156
  */
53
- var auth0RestClient = new Auth0RestClient(
54
- options.baseUrl + '/hooks/:id',
55
- clientOptions,
56
- options.tokenProvider
57
- );
58
- this.resource = new RetryRestClient(auth0RestClient, options.retry);
59
-
60
- var hookSecretsClient = new Auth0RestClient(
61
- options.baseUrl + '/hooks/:id/secrets',
62
- clientOptions,
63
- options.tokenProvider
64
- );
65
- this.secrets = new RetryRestClient(hookSecretsClient, options.retry);
66
- };
67
-
68
- /**
69
- * Create a new hook.
70
- *
71
- * @method create
72
- * @memberOf module:management.HooksManager.prototype
73
- *
74
- * @example
75
- * management.hooks.create(data, function (err) {
76
- * if (err) {
77
- * // Handle error.
78
- * }
79
- *
80
- * // Hook created.
81
- * });
82
- *
83
- * @param {Object} data Hook data object.
84
- * @param {Function} [cb] Callback function.
85
- *
86
- * @return {Promise|undefined}
87
- */
88
- utils.wrapPropertyMethod(HooksManager, 'create', 'resource.create');
89
-
90
- /**
91
- * Get all hooks.
92
- *
93
- * @method getAll
94
- * @memberOf module:management.HooksManager.prototype
95
- *
96
- * @example <caption>
97
- * This method takes an optional object as first argument that may be used to
98
- * specify pagination settings. If pagination options are not present,
99
- * the first page of a limited number of results will be returned.
100
- * </caption>
101
- *
102
- * // Pagination settings.
103
- * var params = {
104
- * per_page: 10,
105
- * page: 0
106
- * };
107
- *
108
- * management.hooks.getAll(params, function (err, hooks) {
109
- * console.log(hooks.length);
110
- * });
111
- *
112
- * @param {Object} [params] Hooks parameters.
113
- * @param {Number} [params.per_page] Number of results per page.
114
- * @param {Number} [params.page] Page number, zero indexed.
115
- * @param {Function} [cb] Callback function.
116
- *
117
- * @return {Promise|undefined}
118
- */
119
- utils.wrapPropertyMethod(HooksManager, 'getAll', 'resource.getAll');
120
-
121
- /**
122
- * Get an Auth0 hook.
123
- *
124
- * @method get
125
- * @memberOf module:management.HooksManager.prototype
126
- *
127
- * @example
128
- * management.hooks.get({ id: HOOK_ID }, function (err, hook) {
129
- * if (err) {
130
- * // Handle error.
131
- * }
132
- *
133
- * console.log(hook);
134
- * });
135
- *
136
- * @param {Object} params Hook parameters.
137
- * @param {String} params.id Hook ID.
138
- * @param {Function} [cb] Callback function.
139
- *
140
- * @return {Promise|undefined}
141
- */
142
- utils.wrapPropertyMethod(HooksManager, 'get', 'resource.get');
157
+ update(...args) {
158
+ return this.resource.patch(...args);
159
+ }
143
160
 
144
- /**
145
- * Update an existing hook.
146
- *
147
- * @method update
148
- * @memberOf module:management.HooksManager.prototype
149
- *
150
- * @example
151
- * var data = { name: 'New name' };
152
- * var params = { id: HOOK_ID };
153
- *
154
- * // Using auth0 instance.
155
- * management.updateHook(params, data, function (err, hook) {
156
- * if (err) {
157
- * // Handle error.
158
- * }
159
- *
160
- * console.log(hook.name); // 'New name'
161
- * });
162
- *
163
- * // Using the hooks manager directly.
164
- * management.hooks.update(params, data, function (err, hook) {
165
- * if (err) {
166
- * // Handle error.
167
- * }
168
- *
169
- * console.log(hook.name); // 'New name'
170
- * });
171
- *
172
- * @param {Object} params Hook parameters.
173
- * @param {String} params.id Hook ID.
174
- * @param {Object} data Updated hook data.
175
- * @param {Function} [cb] Callback function.
176
- *
177
- * @return {Promise|undefined}
178
- */
179
- utils.wrapPropertyMethod(HooksManager, 'update', 'resource.patch');
161
+ /**
162
+ * Delete an existing hook.
163
+ *
164
+ * @example
165
+ * management.hooks.delete({ id: HOOK_ID }, function (err) {
166
+ * if (err) {
167
+ * // Handle error.
168
+ * }
169
+ *
170
+ * // Hook deleted.
171
+ * });
172
+ * @param {object} params Hook parameters.
173
+ * @param {string} params.id Hook ID.
174
+ * @param {Function} [cb] Callback function.
175
+ * @returns {Promise|undefined}
176
+ */
177
+ delete(...args) {
178
+ return this.resource.delete(...args);
179
+ }
180
180
 
181
- /**
182
- * Delete an existing hook.
183
- *
184
- * @method delete
185
- * @memberOf module:management.HooksManager.prototype
186
- *
187
- * @example
188
- * management.hooks.delete({ id: HOOK_ID }, function (err) {
189
- * if (err) {
190
- * // Handle error.
191
- * }
192
- *
193
- * // Hook deleted.
194
- * });
195
- *
196
- * @param {Object} params Hook parameters.
197
- * @param {String} params.id Hook ID.
198
- * @param {Function} [cb] Callback function.
199
- *
200
- * @return {Promise|undefined}
201
- */
202
- utils.wrapPropertyMethod(HooksManager, 'delete', 'resource.delete');
181
+ /**
182
+ * Get Hook secrets
183
+ *
184
+ * @example <caption>
185
+ * This method takes a first argument as the hookId and returns the secrets for the hook. The secret values will be hidden.
186
+ * </caption>
187
+ *
188
+ * var params = {id : 'HOOK_ID'}
189
+ *
190
+ * management.hooks.getSecrets( {id : 'HOOK_ID'}, function (err, secrets) {
191
+ * console.log(secrets);
192
+ * });
193
+ * @param {object} params Hook parameters.
194
+ * @param {string} params.id ID of the Hook.
195
+ * @param {Function} [cb] Callback function.
196
+ * @returns {Promise|undefined}
197
+ */
198
+ getSecrets(params, callback) {
199
+ return this.secrets.getAll(params, callback);
200
+ }
203
201
 
204
- /**
205
- * Get Hook secrets
206
- *
207
- * @method getSecrets
208
- * @memberOf module:management.HooksManager.prototype
209
- *
210
- * @example
211
- * var params = {id : 'HOOK_ID'}
212
- * @example <caption>
213
- * This method takes a first argument as the hookId and returns the secrets for the hook. The secret values will be hidden.
214
- * </caption>
215
- *
216
- * management.hooks.getSecrets( {id : 'HOOK_ID'}, function (err, secrets) {
217
- * console.log(secrets);
218
- * });
219
- *
220
- * @param {Object} params Hook parameters.
221
- * @param {String} params.id ID of the Hook.
222
- * @param {Function} [cb] Callback function.
223
- *
224
- * @return {Promise|undefined}
225
- */
226
- HooksManager.prototype.getSecrets = function(params, callback) {
227
- return this.secrets.getAll(params, callback);
228
- };
202
+ /**
203
+ * Add secrets in a hook
204
+ *
205
+ * @example
206
+ * var params = { id :'HOOK_ID'};
207
+ * var data = { "DB_USER" : "jdoe", "DB_PASS": "password123!"};
208
+ *
209
+ * management.hooks.addSecrets(params, data, function (err, secrets) {
210
+ * if (err) {
211
+ * // Handle error.
212
+ * }
213
+ *
214
+ * // secrets added.
215
+ * });
216
+ * @param {object} params Hook parameters.
217
+ * @param {string} params.id ID of the Hook.
218
+ * @param {object} data object containing secrets as key/value pairs
219
+ * @param {Function} [cb] Callback function.
220
+ * @returns {Promise|undefined}
221
+ */
229
222
 
230
- /**
231
- * Add secrets in a hook
232
- *
233
- * @method addSecrets
234
- * @memberOf module:management.HooksManager.prototype
235
- *
236
- * @example
237
- * var params = { id :'HOOK_ID'};
238
- * var data = { "DB_USER" : "jdoe", "DB_PASS": "password123!"};
239
- *
240
- * management.hooks.addSecrets(params, data, function (err, secrets) {
241
- * if (err) {
242
- * // Handle error.
243
- * }
244
- *
245
- * // secrets added.
246
- * });
247
- *
248
- * @param {Object} params Hook parameters.
249
- * @param {String} params.id ID of the Hook.
250
- * @param {Object} data object containing secrets as key/value pairs
251
- * @param {Function} [cb] Callback function.
252
- *
253
- * @return {Promise|undefined}
254
- */
223
+ addSecrets(params, data, cb) {
224
+ params = params || {};
225
+ data = data || {};
255
226
 
256
- HooksManager.prototype.addSecrets = function(params, data, cb) {
257
- params = params || {};
258
- data = data || {};
227
+ // Require an ID.
228
+ if (!params.id) {
229
+ throw new ArgumentError('The id passed in params cannot be null or undefined');
230
+ }
259
231
 
260
- // Require an ID.
261
- if (!params.id) {
262
- throw new ArgumentError('The id passed in params cannot be null or undefined');
263
- }
232
+ if (typeof params.id !== 'string') {
233
+ throw new ArgumentError('The hook Id has to be a string');
234
+ }
264
235
 
265
- if (typeof params.id !== 'string') {
266
- throw new ArgumentError('The hook Id has to be a string');
267
- }
236
+ if (cb && cb instanceof Function) {
237
+ return this.secrets.create(params, data, cb);
238
+ }
268
239
 
269
- if (cb && cb instanceof Function) {
270
- return this.secrets.create(params, data, cb);
240
+ return this.secrets.create(params, data);
271
241
  }
272
242
 
273
- return this.secrets.create(params, data);
274
- };
243
+ /**
244
+ * Update secrets in a hook
245
+ *
246
+ * @example
247
+ * var params = { id :'HOOK_ID'};
248
+ * var data = { "DB_USER" : "jdoe", "DB_PASS": "password123!"};
249
+ *
250
+ * management.hooks.updateSecrets(params, data, function (err, secrets) {
251
+ * if (err) {
252
+ * // Handle error.
253
+ * }
254
+ *
255
+ * // secrets updated.
256
+ * });
257
+ * @param {object} params Hook parameters.
258
+ * @param {string} params.id ID of the Hook.
259
+ * @param {object} data object containing secrets as key/value pairs
260
+ * @param {Function} [cb] Callback function.
261
+ * @returns {Promise|undefined}
262
+ */
275
263
 
276
- /**
277
- * Update secrets in a hook
278
- *
279
- * @method updateSecrets
280
- * @memberOf module:management.HooksManager.prototype
281
- *
282
- * @example
283
- * var params = { id :'HOOK_ID'};
284
- * var data = { "DB_USER" : "jdoe", "DB_PASS": "password123!"};
285
- *
286
- * management.hooks.updateSecrets(params, data, function (err, secrets) {
287
- * if (err) {
288
- * // Handle error.
289
- * }
290
- *
291
- * // secrets updated.
292
- * });
293
- *
294
- * @param {Object} params Hook parameters.
295
- * @param {String} params.id ID of the Hook.
296
- * @param {Object} data object containing secrets as key/value pairs
297
- * @param {Function} [cb] Callback function.
298
- *
299
- * @return {Promise|undefined}
300
- */
264
+ updateSecrets(params, data, cb) {
265
+ params = params || {};
266
+ data = data || {};
301
267
 
302
- HooksManager.prototype.updateSecrets = function(params, data, cb) {
303
- params = params || {};
304
- data = data || {};
268
+ // Require an ID.
269
+ if (!params.id) {
270
+ throw new ArgumentError('The id passed in params cannot be null or undefined');
271
+ }
305
272
 
306
- // Require an ID.
307
- if (!params.id) {
308
- throw new ArgumentError('The id passed in params cannot be null or undefined');
309
- }
273
+ if (typeof params.id !== 'string') {
274
+ throw new ArgumentError('The hook Id has to be a string');
275
+ }
310
276
 
311
- if (typeof params.id !== 'string') {
312
- throw new ArgumentError('The hook Id has to be a string');
313
- }
277
+ if (cb && cb instanceof Function) {
278
+ return this.secrets.patch(params, data, cb);
279
+ }
314
280
 
315
- if (cb && cb instanceof Function) {
316
- return this.secrets.patch(params, data, cb);
281
+ return this.secrets.patch(params, data);
317
282
  }
318
283
 
319
- return this.secrets.patch(params, data);
320
- };
284
+ /**
285
+ * Remove secrets from a hook
286
+ *
287
+ * @example
288
+ * var params = { id :'HOOK_ID'};
289
+ * var data =["DB_PASS"];
290
+ *
291
+ * management.hooks.removeSecrets(params, data, function (err, hook) {
292
+ * if (err) {
293
+ * // Handle error.
294
+ * }
295
+ *
296
+ * // secrets added.
297
+ * });
298
+ * @param {object} params Hook parameters.
299
+ * @param {string} params.id ID of the Hook.
300
+ * @param {object} data Array of secret names
301
+ * @param {Function} [cb] Callback function.
302
+ * @returns {Promise|undefined}
303
+ */
321
304
 
322
- /**
323
- * Remove secrets from a hook
324
- *
325
- * @method removeSecrets
326
- * @memberOf module:management.HooksManager.prototype
327
- *
328
- * @example
329
- * var params = { id :'HOOK_ID'};
330
- * var data =["DB_PASS"];
331
- *
332
- * management.hooks.removeSecrets(params, data, function (err, hook) {
333
- * if (err) {
334
- * // Handle error.
335
- * }
336
- *
337
- * // secrets added.
338
- * });
339
- *
340
- * @param {Object} params Hook parameters.
341
- * @param {String} params.id ID of the Hook.
342
- * @param {Object} data Array of secret names
343
- * @param {Function} [cb] Callback function.
344
- *
345
- * @return {Promise|undefined}
346
- */
305
+ removeSecrets(params, data, cb) {
306
+ params = params || {};
307
+ data = data || {};
347
308
 
348
- HooksManager.prototype.removeSecrets = function(params, data, cb) {
349
- params = params || {};
350
- data = data || {};
309
+ // Require an ID.
310
+ if (!params.id) {
311
+ throw new ArgumentError('The id passed in params cannot be null or undefined');
312
+ }
351
313
 
352
- // Require an ID.
353
- if (!params.id) {
354
- throw new ArgumentError('The id passed in params cannot be null or undefined');
355
- }
314
+ if (typeof params.id !== 'string') {
315
+ throw new ArgumentError('The hook Id has to be a string');
316
+ }
356
317
 
357
- if (typeof params.id !== 'string') {
358
- throw new ArgumentError('The hook Id has to be a string');
359
- }
318
+ if (cb && cb instanceof Function) {
319
+ return this.secrets.delete(params, data, cb);
320
+ }
360
321
 
361
- if (cb && cb instanceof Function) {
362
- return this.secrets.delete(params, data, cb);
322
+ return this.secrets.delete(params, data);
363
323
  }
364
-
365
- return this.secrets.delete(params, data);
366
- };
324
+ }
367
325
 
368
326
  module.exports = HooksManager;