auth0 2.37.0 → 2.40.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 (47) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +33 -11
  3. package/package.json +22 -14
  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 +238 -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 -583
  14. package/src/errors.js +23 -23
  15. package/src/index.js +3 -2
  16. package/src/management/ActionsManager.js +510 -584
  17. package/src/management/AttackProtectionManager.js +187 -0
  18. package/src/management/BlacklistedTokensManager.js +77 -84
  19. package/src/management/BrandingManager.js +141 -163
  20. package/src/management/ClientGrantsManager.js +132 -145
  21. package/src/management/ClientsManager.js +145 -161
  22. package/src/management/ConnectionsManager.js +215 -239
  23. package/src/management/CustomDomainsManager.js +140 -157
  24. package/src/management/DeviceCredentialsManager.js +95 -111
  25. package/src/management/EmailProviderManager.js +110 -128
  26. package/src/management/EmailTemplatesManager.js +96 -112
  27. package/src/management/GrantsManager.js +94 -101
  28. package/src/management/GuardianManager.js +381 -455
  29. package/src/management/HooksManager.js +283 -325
  30. package/src/management/JobsManager.js +310 -343
  31. package/src/management/LogStreamsManager.js +142 -158
  32. package/src/management/LogsManager.js +92 -99
  33. package/src/management/ManagementTokenProvider.js +112 -120
  34. package/src/management/MigrationsManager.js +81 -90
  35. package/src/management/OrganizationsManager.js +686 -784
  36. package/src/management/PromptsManager.js +160 -182
  37. package/src/management/ResourceServersManager.js +143 -160
  38. package/src/management/RolesManager.js +323 -369
  39. package/src/management/RulesConfigsManager.js +94 -110
  40. package/src/management/RulesManager.js +154 -176
  41. package/src/management/StatsManager.js +87 -103
  42. package/src/management/TenantManager.js +81 -97
  43. package/src/management/TicketsManager.js +107 -115
  44. package/src/management/UserBlocksManager.js +135 -162
  45. package/src/management/UsersManager.js +729 -852
  46. package/src/management/index.js +3102 -3625
  47. package/src/utils.js +31 -60
@@ -1,268 +1,244 @@
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
- * @class ConnectionsManager
8
6
  * Represents the relationship between Auth0 and an Identity provider.
9
- * @constructor
10
- * @memberOf module:management
11
- *
12
- * @param {Object} options The client options.
13
- * @param {String} options.baseUrl The URL of the API.
14
- * @param {Object} [options.headers] Headers to be included in all requests.
15
- * @param {Object} [options.retry] Retry Policy Config
16
7
  */
17
- var ConnectionsManager = function(options) {
18
- if (options === null || typeof options !== 'object') {
19
- throw new ArgumentError('Must provide client options');
8
+ class ConnectionsManager {
9
+ /**
10
+ * @param {object} options The client options.
11
+ * @param {string} options.baseUrl The URL of the API.
12
+ * @param {object} [options.headers] Headers to be included in all requests.
13
+ * @param {object} [options.retry] Retry Policy Config
14
+ */
15
+ constructor(options) {
16
+ if (options === null || typeof options !== 'object') {
17
+ throw new ArgumentError('Must provide client options');
18
+ }
19
+
20
+ if (options.baseUrl === null || options.baseUrl === undefined) {
21
+ throw new ArgumentError('Must provide a base URL for the API');
22
+ }
23
+
24
+ if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
25
+ throw new ArgumentError('The provided base URL is invalid');
26
+ }
27
+
28
+ /**
29
+ * Options object for the Rest Client instance.
30
+ *
31
+ * @type {object}
32
+ */
33
+ const clientOptions = {
34
+ headers: options.headers,
35
+ query: { repeatParams: false },
36
+ };
37
+
38
+ /**
39
+ * Provides an abstraction layer for performing CRUD operations on
40
+ * {@link https://auth0.com/docs/api/v2#!/ConnectionsManagers Auth0
41
+ * Connections}.
42
+ *
43
+ * @type {external:RestClient}
44
+ */
45
+ const auth0RestClient = new Auth0RestClient(
46
+ `${options.baseUrl}/connections/:id`,
47
+ clientOptions,
48
+ options.tokenProvider
49
+ );
50
+ this.resource = new RetryRestClient(auth0RestClient, options.retry);
51
+
52
+ const statusClient = new Auth0RestClient(
53
+ `${options.baseUrl}/connections/:id/status`,
54
+ clientOptions,
55
+ options.tokenProvider
56
+ );
57
+ this.status = new RetryRestClient(statusClient, options.retry);
58
+
59
+ /**
60
+ * Provides an abstraction layer for consuming the
61
+ * {@link https://auth0.com/docs/api/management/v2#!/Connections/delete_users_by_email
62
+ * endpoint}.
63
+ *
64
+ * @type {external:RestClient}
65
+ */
66
+ const userAuth0RestClient = new Auth0RestClient(
67
+ `${options.baseUrl}/connections/:id/users`,
68
+ clientOptions,
69
+ options.tokenProvider
70
+ );
71
+ this.user = new RetryRestClient(userAuth0RestClient, options.retry);
20
72
  }
21
73
 
22
- if (options.baseUrl === null || options.baseUrl === undefined) {
23
- throw new ArgumentError('Must provide a base URL for the API');
74
+ /**
75
+ * Create a new connection.
76
+ *
77
+ * @example
78
+ * management.connections.create(data, function (err) {
79
+ * if (err) {
80
+ * // Handle error.
81
+ * }
82
+ *
83
+ * // Connection created.
84
+ * });
85
+ * @param {object} data Connection data object.
86
+ * @param {Function} [cb] Callback function.
87
+ * @returns {Promise|undefined}
88
+ */
89
+ create(...args) {
90
+ return this.resource.create(...args);
24
91
  }
25
92
 
26
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
27
- throw new ArgumentError('The provided base URL is invalid');
93
+ /**
94
+ * Get all connections.
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.connections.getAll(params, function (err, connections) {
109
+ * console.log(connections.length);
110
+ * });
111
+ * @param {object} [params] Connections params.
112
+ * @param {number} [params.per_page] Number of results per page.
113
+ * @param {number} [params.page] Page number, zero indexed.
114
+ * @param {Function} [cb] Callback function.
115
+ * @returns {Promise|undefined}
116
+ */
117
+ getAll(...args) {
118
+ return this.resource.getAll(...args);
28
119
  }
29
120
 
30
121
  /**
31
- * Options object for the Rest Client instance.
122
+ * Get an Auth0 connection.
123
+ *
124
+ * @example
125
+ * management.connections.get({ id: CONNECTION_ID }, function (err, connection) {
126
+ * if (err) {
127
+ * // Handle error.
128
+ * }
32
129
  *
33
- * @type {Object}
130
+ * console.log(connection);
131
+ * });
132
+ * @param {object} params Connection parameters.
133
+ * @param {string} params.id Connection ID.
134
+ * @param {Function} [cb] Callback function.
135
+ * @returns {Promise|undefined}
34
136
  */
35
- var clientOptions = {
36
- headers: options.headers,
37
- query: { repeatParams: false }
38
- };
137
+ get(...args) {
138
+ return this.resource.get(...args);
139
+ }
39
140
 
40
141
  /**
41
- * Provides an abstraction layer for performing CRUD operations on
42
- * {@link https://auth0.com/docs/api/v2#!/ConnectionsManagers Auth0
43
- * Connections}.
142
+ * Update an existing connection.
44
143
  *
45
- * @type {external:RestClient}
144
+ * @example
145
+ * var data = { name: 'newConnectionName' };
146
+ * var params = { id: CONNECTION_ID };
147
+ *
148
+ * management.connections.update(params, data, function (err, connection) {
149
+ * if (err) {
150
+ * // Handle error.
151
+ * }
152
+ *
153
+ * console.log(connection.name); // 'newConnectionName'
154
+ * });
155
+ * @param {object} params Connection parameters.
156
+ * @param {string} params.id Connection ID.
157
+ * @param {object} data Updated connection data.
158
+ * @param {Function} [cb] Callback function.
159
+ * @returns {Promise|undefined}
46
160
  */
47
- var auth0RestClient = new Auth0RestClient(
48
- options.baseUrl + '/connections/:id ',
49
- clientOptions,
50
- options.tokenProvider
51
- );
52
- this.resource = new RetryRestClient(auth0RestClient, options.retry);
53
-
54
- var statusClient = new Auth0RestClient(
55
- options.baseUrl + '/connections/:id/status',
56
- clientOptions,
57
- options.tokenProvider
58
- );
59
- this.status = new RetryRestClient(statusClient, options.retry);
161
+ update(...args) {
162
+ return this.resource.patch(...args);
163
+ }
60
164
 
61
165
  /**
62
- * Provides an abstraction layer for consuming the
63
- * {@link https://auth0.com/docs/api/management/v2#!/Connections/delete_users_by_email
64
- * endpoint}.
166
+ * Delete an existing connection.
167
+ *
168
+ * @example
169
+ * management.connections.delete({ id: CONNECTION_ID }, function (err) {
170
+ * if (err) {
171
+ * // Handle error.
172
+ * }
65
173
  *
66
- * @type {external:RestClient}
174
+ * // Connection deleted.
175
+ * });
176
+ * @param {object} params Connection parameters.
177
+ * @param {string} params.id Connection ID.
178
+ * @param {Function} [cb] Callback function.
179
+ * @returns {Promise|undefined}
67
180
  */
68
- var userAuth0RestClient = new Auth0RestClient(
69
- options.baseUrl + '/connections/:id/users',
70
- clientOptions,
71
- options.tokenProvider
72
- );
73
- this.user = new RetryRestClient(userAuth0RestClient, options.retry);
74
- };
75
-
76
- /**
77
- * Create a new connection.
78
- *
79
- * @method create
80
- * @memberOf module:management.ConnectionsManager.prototype
81
- *
82
- * @example
83
- * management.connections.create(data, function (err) {
84
- * if (err) {
85
- * // Handle error.
86
- * }
87
- *
88
- * // Connection created.
89
- * });
90
- *
91
- * @param {Object} data Connection data object.
92
- * @param {Function} [cb] Callback function.
93
- *
94
- * @return {Promise|undefined}
95
- */
96
- utils.wrapPropertyMethod(ConnectionsManager, 'create', 'resource.create');
97
-
98
- /**
99
- * Get all connections.
100
- *
101
- * @method getAll
102
- * @memberOf module:management.ConnectionsManager.prototype
103
- *
104
- * @example <caption>
105
- * This method takes an optional object as first argument that may be used to
106
- * specify pagination settings. If pagination options are not present,
107
- * the first page of a limited number of results will be returned.
108
- * </caption>
109
- *
110
- * // Pagination settings.
111
- * var params = {
112
- * per_page: 10,
113
- * page: 0
114
- * };
115
- *
116
- * management.connections.getAll(params, function (err, connections) {
117
- * console.log(connections.length);
118
- * });
119
- *
120
- * @param {Object} [params] Connections params.
121
- * @param {Number} [params.per_page] Number of results per page.
122
- * @param {Number} [params.page] Page number, zero indexed.
123
- * @param {Function} [cb] Callback function.
124
- *
125
- * @return {Promise|undefined}
126
- */
127
- utils.wrapPropertyMethod(ConnectionsManager, 'getAll', 'resource.getAll');
128
-
129
- /**
130
- * Get an Auth0 connection.
131
- *
132
- * @method get
133
- * @memberOf module:management.ConnectionsManager.prototype
134
- *
135
- * @example
136
- * management.connections.get({ id: CONNECTION_ID }, function (err, connection) {
137
- * if (err) {
138
- * // Handle error.
139
- * }
140
- *
141
- * console.log(connection);
142
- * });
143
- *
144
- * @param {Object} params Connection parameters.
145
- * @param {String} params.id Connection ID.
146
- * @param {Function} [cb] Callback function.
147
- *
148
- * @return {Promise|undefined}
149
- */
150
- utils.wrapPropertyMethod(ConnectionsManager, 'get', 'resource.get');
151
-
152
- /**
153
- * Update an existing connection.
154
- *
155
- * @method update
156
- * @memberOf module:management.ConnectionsManager.prototype
157
- *
158
- * @example
159
- * var data = { name: 'newConnectionName' };
160
- * var params = { id: CONNECTION_ID };
161
- *
162
- * management.connections.update(params, data, function (err, connection) {
163
- * if (err) {
164
- * // Handle error.
165
- * }
166
- *
167
- * console.log(connection.name); // 'newConnectionName'
168
- * });
169
- *
170
- * @param {Object} params Connection parameters.
171
- * @param {String} params.id Connection ID.
172
- * @param {Object} data Updated connection data.
173
- * @param {Function} [cb] Callback function.
174
- *
175
- * @return {Promise|undefined}
176
- */
177
- utils.wrapPropertyMethod(ConnectionsManager, 'update', 'resource.patch');
181
+ delete(...args) {
182
+ return this.resource.delete(...args);
183
+ }
178
184
 
179
- /**
180
- * Delete an existing connection.
181
- *
182
- * @method delete
183
- * @memberOf module:management.ConnectionsManager.prototype
184
- *
185
- * @example
186
- * management.connections.delete({ id: CONNECTION_ID }, function (err) {
187
- * if (err) {
188
- * // Handle error.
189
- * }
190
- *
191
- * // Connection deleted.
192
- * });
193
- *
194
- * @param {Object} params Connection parameters.
195
- * @param {String} params.id Connection ID.
196
- * @param {Function} [cb] Callback function.
197
- *
198
- * @return {Promise|undefined}
199
- */
200
- utils.wrapPropertyMethod(ConnectionsManager, 'delete', 'resource.delete');
185
+ /**
186
+ * Checks the status of an ad/ldap connection referenced by its ID.
187
+ *
188
+ * @example
189
+ * var params = {id : 'CONNECTION_ID'}
190
+ * @example <caption>
191
+ * This methods takes the connection ID and returns the status when online, or an error when offline.
192
+ * </caption>
193
+ *
194
+ * management.connections.checkStatus( {id : 'CONNECTION_ID'}, function (err, status) {
195
+ * if (err) {
196
+ * console.log('OFFLINE', err);
197
+ * } else {
198
+ * console.log('ONLINE', status);
199
+ * }
200
+ * });
201
+ * @param {object} params Connection parameters
202
+ * @param {string} params.id ID of the Connection.
203
+ * @param {Function} [cb] Callback function.
204
+ * @returns {Promise|undefined}
205
+ */
206
+ checkStatus(...args) {
207
+ return this.status.get(...args);
208
+ }
201
209
 
202
- /**
203
- * Checks the status of an ad/ldap connection referenced by its ID.
204
- *
205
- * @method checkStatus
206
- * @memberOf module:management.OrganizationsManager.prototype
207
- *
208
- * @example
209
- * var params = {id : 'CONNECTION_ID'}
210
- * @example <caption>
211
- * This methods takes the connection ID and returns the status when online, or an error when offline.
212
- * </caption>
213
- *
214
- * management.connections.checkStatus( {id : 'CONNECTION_ID'}, function (err, status) {
215
- * if (err) {
216
- * console.log('OFFLINE', err);
217
- * } else {
218
- * console.log('ONLINE', status);
219
- * }
220
- * });
221
- *
222
- * @param {Object} params Connection parameters
223
- * @param {String} params.id ID of the Connection.
224
- * @param {Function} [cb] Callback function.
225
- *
226
- * @return {Promise|undefined}
227
- */
228
- utils.wrapPropertyMethod(ConnectionsManager, 'checkStatus', 'status.get');
210
+ /**
211
+ * Delete a connection user by email.
212
+ *
213
+ * @example
214
+ * management.connections.deleteUserByEmail({ id: CONNECTION_ID, email:USER_EMAIL }, function (err) {
215
+ * if (err) {
216
+ * // Handle error.
217
+ * }
218
+ *
219
+ * // User deleted.
220
+ * });
221
+ * @param {object} params Connection parameters.
222
+ * @param {string} params.id Connection ID.
223
+ * @param {string} params.email User Email.
224
+ * @param {Function} [cb] Callback function.
225
+ * @returns {Promise|undefined}
226
+ */
227
+ deleteUserByEmail(params, cb) {
228
+ if (typeof params !== 'object' || typeof params.email !== 'string' || params.email.length < 1) {
229
+ throw new ArgumentError('You must provide an email for the deleteUserByEmail method');
230
+ }
229
231
 
230
- /**
231
- * Delete a connection user by email.
232
- *
233
- * @method delete
234
- * @memberOf module:management.ConnectionsManager.prototype
235
- *
236
- * @example
237
- * management.connections.deleteUserByEmail({ id: CONNECTION_ID, email:USER_EMAIL }, function (err) {
238
- * if (err) {
239
- * // Handle error.
240
- * }
241
- *
242
- * // User deleted.
243
- * });
244
- *
245
- * @param {Object} params Connection parameters.
246
- * @param {String} params.id Connection ID.
247
- * @param {String} params.email User Email.
248
- * @param {Function} [cb] Callback function.
249
- *
250
- * @return {Promise|undefined}
251
- */
252
- ConnectionsManager.prototype.deleteUserByEmail = function(params, cb) {
253
- if (typeof params !== 'object' || typeof params.email !== 'string' || params.email.length < 1) {
254
- throw new ArgumentError('You must provide an email for the deleteUserByEmail method');
255
- }
232
+ if (!params.id) {
233
+ throw new ArgumentError('The connection id cannot be null or undefined');
234
+ }
256
235
 
257
- if (!params.id) {
258
- throw new ArgumentError('The connection id cannot be null or undefined');
259
- }
236
+ if (cb && cb instanceof Function) {
237
+ return this.user.delete(params, {}, cb);
238
+ }
260
239
 
261
- if (cb && cb instanceof Function) {
262
- return this.user.delete(params, {}, cb);
240
+ return this.user.delete(params, {});
263
241
  }
264
-
265
- return this.user.delete(params, {});
266
- };
242
+ }
267
243
 
268
244
  module.exports = ConnectionsManager;