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,233 +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.
143
+ *
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
+ * }
44
152
  *
45
- * @type {external:RestClient}
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);
161
+ update(...args) {
162
+ return this.resource.patch(...args);
163
+ }
53
164
 
54
165
  /**
55
- * Provides an abstraction layer for consuming the
56
- * {@link https://auth0.com/docs/api/management/v2#!/Connections/delete_users_by_email
57
- * 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
+ * }
58
173
  *
59
- * @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}
60
180
  */
61
- var userAuth0RestClient = new Auth0RestClient(
62
- options.baseUrl + '/connections/:id/users',
63
- clientOptions,
64
- options.tokenProvider
65
- );
66
- this.user = new RetryRestClient(userAuth0RestClient, options.retry);
67
- };
68
-
69
- /**
70
- * Create a new connection.
71
- *
72
- * @method create
73
- * @memberOf module:management.ConnectionsManager.prototype
74
- *
75
- * @example
76
- * management.connections.create(data, function (err) {
77
- * if (err) {
78
- * // Handle error.
79
- * }
80
- *
81
- * // Connection created.
82
- * });
83
- *
84
- * @param {Object} data Connection data object.
85
- * @param {Function} [cb] Callback function.
86
- *
87
- * @return {Promise|undefined}
88
- */
89
- utils.wrapPropertyMethod(ConnectionsManager, 'create', 'resource.create');
90
-
91
- /**
92
- * Get all connections.
93
- *
94
- * @method getAll
95
- * @memberOf module:management.ConnectionsManager.prototype
96
- *
97
- * @example <caption>
98
- * This method takes an optional object as first argument that may be used to
99
- * specify pagination settings. If pagination options are not present,
100
- * the first page of a limited number of results will be returned.
101
- * </caption>
102
- *
103
- * // Pagination settings.
104
- * var params = {
105
- * per_page: 10,
106
- * page: 0
107
- * };
108
- *
109
- * management.connections.getAll(params, function (err, connections) {
110
- * console.log(connections.length);
111
- * });
112
- *
113
- * @param {Object} [params] Connections params.
114
- * @param {Number} [params.per_page] Number of results per page.
115
- * @param {Number} [params.page] Page number, zero indexed.
116
- * @param {Function} [cb] Callback function.
117
- *
118
- * @return {Promise|undefined}
119
- */
120
- utils.wrapPropertyMethod(ConnectionsManager, 'getAll', 'resource.getAll');
121
-
122
- /**
123
- * Get an Auth0 connection.
124
- *
125
- * @method get
126
- * @memberOf module:management.ConnectionsManager.prototype
127
- *
128
- * @example
129
- * management.connections.get({ id: CONNECTION_ID }, function (err, connection) {
130
- * if (err) {
131
- * // Handle error.
132
- * }
133
- *
134
- * console.log(connection);
135
- * });
136
- *
137
- * @param {Object} params Connection parameters.
138
- * @param {String} params.id Connection ID.
139
- * @param {Function} [cb] Callback function.
140
- *
141
- * @return {Promise|undefined}
142
- */
143
- utils.wrapPropertyMethod(ConnectionsManager, 'get', 'resource.get');
181
+ delete(...args) {
182
+ return this.resource.delete(...args);
183
+ }
144
184
 
145
- /**
146
- * Update an existing connection.
147
- *
148
- * @method update
149
- * @memberOf module:management.ConnectionsManager.prototype
150
- *
151
- * @example
152
- * var data = { name: 'newConnectionName' };
153
- * var params = { id: CONNECTION_ID };
154
- *
155
- * management.connections.update(params, data, function (err, connection) {
156
- * if (err) {
157
- * // Handle error.
158
- * }
159
- *
160
- * console.log(connection.name); // 'newConnectionName'
161
- * });
162
- *
163
- * @param {Object} params Connection parameters.
164
- * @param {String} params.id Connection ID.
165
- * @param {Object} data Updated connection data.
166
- * @param {Function} [cb] Callback function.
167
- *
168
- * @return {Promise|undefined}
169
- */
170
- utils.wrapPropertyMethod(ConnectionsManager, 'update', 'resource.patch');
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
+ }
171
209
 
172
- /**
173
- * Delete an existing connection.
174
- *
175
- * @method delete
176
- * @memberOf module:management.ConnectionsManager.prototype
177
- *
178
- * @example
179
- * management.connections.delete({ id: CONNECTION_ID }, function (err) {
180
- * if (err) {
181
- * // Handle error.
182
- * }
183
- *
184
- * // Connection deleted.
185
- * });
186
- *
187
- * @param {Object} params Connection parameters.
188
- * @param {String} params.id Connection ID.
189
- * @param {Function} [cb] Callback function.
190
- *
191
- * @return {Promise|undefined}
192
- */
193
- utils.wrapPropertyMethod(ConnectionsManager, 'delete', 'resource.delete');
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
+ }
194
231
 
195
- /**
196
- * Delete a connection user by email.
197
- *
198
- * @method delete
199
- * @memberOf module:management.ConnectionsManager.prototype
200
- *
201
- * @example
202
- * management.connections.deleteUserByEmail({ id: CONNECTION_ID, email:USER_EMAIL }, function (err) {
203
- * if (err) {
204
- * // Handle error.
205
- * }
206
- *
207
- * // User deleted.
208
- * });
209
- *
210
- * @param {Object} params Connection parameters.
211
- * @param {String} params.id Connection ID.
212
- * @param {String} params.email User Email.
213
- * @param {Function} [cb] Callback function.
214
- *
215
- * @return {Promise|undefined}
216
- */
217
- ConnectionsManager.prototype.deleteUserByEmail = function(params, cb) {
218
- if (typeof params !== 'object' || typeof params.email !== 'string' || params.email.length < 1) {
219
- throw new ArgumentError('You must provide an email for the deleteUserByEmail method');
220
- }
232
+ if (!params.id) {
233
+ throw new ArgumentError('The connection id cannot be null or undefined');
234
+ }
221
235
 
222
- if (!params.id) {
223
- throw new ArgumentError('The connection id cannot be null or undefined');
224
- }
236
+ if (cb && cb instanceof Function) {
237
+ return this.user.delete(params, {}, cb);
238
+ }
225
239
 
226
- if (cb && cb instanceof Function) {
227
- return this.user.delete(params, {}, cb);
240
+ return this.user.delete(params, {});
228
241
  }
229
-
230
- return this.user.delete(params, {});
231
- };
242
+ }
232
243
 
233
244
  module.exports = ConnectionsManager;