auth0 2.36.2 → 2.39.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 +41 -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 -581
  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/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 -182
  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,297 +1,280 @@
1
- var extend = require('util')._extend;
2
-
3
- var ArgumentError = require('rest-facade').ArgumentError;
4
- var RestClient = require('rest-facade').Client;
1
+ const { ArgumentError } = require('rest-facade');
2
+ const RestClient = require('rest-facade').Client;
5
3
 
6
4
  /**
7
- * @class
8
5
  * Abstracts the sign-in, sign-up and change-password processes for Database &
9
6
  * Active Directory authentication services.
10
- * @constructor
11
- * @memberOf module:auth
12
- *
13
- * @param {Object} options Authenticator options.
14
- * @param {String} options.baseUrl The auth0 account URL.
15
- * @param {String} [options.clientId] Default client ID.
16
- * @param {OAuthAuthenticator} oauth OAuthAuthenticator instance.
17
7
  */
18
- var DatabaseAuthenticator = function(options, oauth) {
19
- if (!options) {
20
- throw new ArgumentError('Missing authenticator options');
21
- }
8
+ class DatabaseAuthenticator {
9
+ /**
10
+ * @param {object} options Authenticator options.
11
+ * @param {string} options.baseUrl The auth0 account URL.
12
+ * @param {string} [options.clientId] Default client ID.
13
+ * @param {OAuthAuthenticator} oauth OAuthAuthenticator instance.
14
+ */
15
+ constructor(options, oauth) {
16
+ if (!options) {
17
+ throw new ArgumentError('Missing authenticator options');
18
+ }
22
19
 
23
- if (typeof options !== 'object') {
24
- throw new ArgumentError('The authenticator options must be an object');
20
+ if (typeof options !== 'object') {
21
+ throw new ArgumentError('The authenticator options must be an object');
22
+ }
23
+
24
+ /**
25
+ * Options object for the Rest Client instance.
26
+ *
27
+ * @type {object}
28
+ */
29
+ const clientOptions = {
30
+ errorFormatter: { message: 'message', name: 'error' },
31
+ headers: options.headers,
32
+ };
33
+
34
+ this.oauth = oauth;
35
+ this.dbConnections = new RestClient(`${options.baseUrl}/dbconnections/:type`, clientOptions);
36
+ this.clientId = options.clientId;
25
37
  }
26
38
 
27
39
  /**
28
- * Options object for the Rest Client instance.
40
+ * Sign in using a database or active directory service.
41
+ *
42
+ * @example <caption>
43
+ * Given the user credentials and the connection specified, it will do the
44
+ * authentication on the provider and return a JSON with the `access_token`
45
+ * and `id_token`. Find more information about the structure of the data
46
+ * object in the <a href="https://auth0.com/docs/auth-api#!#post--oauth-ro">
47
+ * API docs</a>.
48
+ * </caption>
29
49
  *
30
- * @type {Object}
50
+ * var data = {
51
+ * username: '{USERNAME}',
52
+ * password: '{PASSWORD}',
53
+ * connection: 'Username-Password-Authentication' // Optional field.
54
+ * };
55
+ *
56
+ * auth0.database.signIn(data, function (err, userData) {
57
+ * if (err) {
58
+ * // Handle error.
59
+ * }
60
+ *
61
+ * console.log(userData);
62
+ * });
63
+ * @param {object} userData User credentials object.
64
+ * @param {string} userData.username Username.
65
+ * @param {string} userData.password User password.
66
+ * @param {string} userData.connection Identity provider in use.
67
+ * @param {Function} [cb] Method callback.
68
+ * @returns {Promise|undefined}
31
69
  */
32
- var clientOptions = {
33
- errorFormatter: { message: 'message', name: 'error' },
34
- headers: options.headers
35
- };
70
+ signIn(userData, cb) {
71
+ if (!userData || typeof userData !== 'object') {
72
+ throw new ArgumentError('Missing user data object');
73
+ }
36
74
 
37
- this.oauth = oauth;
38
- this.dbConnections = new RestClient(options.baseUrl + '/dbconnections/:type', clientOptions);
39
- this.clientId = options.clientId;
40
- };
75
+ const data = {
76
+ connection: 'Username-Password-Authentication',
77
+ ...userData,
78
+ };
41
79
 
42
- /**
43
- * Sign in using a database or active directory service.
44
- * @method signIn
45
- * @memberOf module:auth.DatabaseAuthenticator.prototype
46
- *
47
- * @example <caption>
48
- * Given the user credentials and the connection specified, it will do the
49
- * authentication on the provider and return a JSON with the `access_token`
50
- * and `id_token`. Find more information about the structure of the data
51
- * object in the <a href="https://auth0.com/docs/auth-api#!#post--oauth-ro">
52
- * API docs</a>.
53
- * </caption>
54
- *
55
- * var data = {
56
- * username: '{USERNAME}',
57
- * password: '{PASSWORD}',
58
- * connection: 'Username-Password-Authentication' // Optional field.
59
- * };
60
- *
61
- * auth0.database.signIn(data, function (err, userData) {
62
- * if (err) {
63
- * // Handle error.
64
- * }
65
- *
66
- * console.log(userData);
67
- * });
68
- *
69
- * @param {Object} data User credentials object.
70
- * @param {String} data.username Username.
71
- * @param {String} data.password User password.
72
- * @param {String} data.connection Identity provider in use.
73
- * @param {Function} [cb] Method callback.
74
- *
75
- * @return {Promise|undefined}
76
- */
77
- DatabaseAuthenticator.prototype.signIn = function(userData, cb) {
78
- var defaultFields = {
79
- connection: 'Username-Password-Authentication'
80
- };
81
- var data = extend(defaultFields, userData);
82
-
83
- if (!userData || typeof userData !== 'object') {
84
- throw new ArgumentError('Missing user data object');
85
- }
80
+ if (typeof data.username !== 'string' || data.username.trim().length === 0) {
81
+ throw new ArgumentError('username field is required');
82
+ }
86
83
 
87
- if (typeof data.username !== 'string' || data.username.trim().length === 0) {
88
- throw new ArgumentError('username field is required');
89
- }
84
+ if (typeof data.password !== 'string' || data.password.trim().length === 0) {
85
+ throw new ArgumentError('password field is required');
86
+ }
90
87
 
91
- if (typeof data.password !== 'string' || data.password.trim().length === 0) {
92
- throw new ArgumentError('password field is required');
88
+ return this.oauth.signIn(data, cb);
93
89
  }
94
90
 
95
- return this.oauth.signIn(data, cb);
96
- };
91
+ /**
92
+ * Sign up using a database or active directory service.
93
+ *
94
+ * @example <caption>
95
+ * Given the user credentials, the connection specified and (optionally) the
96
+ * client ID, it will create a new user. Find more information in the
97
+ * <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-signup">
98
+ * API Docs</a>.
99
+ * </caption>
100
+ *
101
+ * var data = {
102
+ * email: '{EMAIL}',
103
+ * password: '{PASSWORD}',
104
+ * connection: 'Username-Password-Authentication' // Optional field.
105
+ * };
106
+ *
107
+ * auth0.database.signUp(data, function (err, userData) {
108
+ * if (err) {
109
+ * // Handle error.
110
+ * }
111
+ *
112
+ * console.log(userData);
113
+ * });
114
+ * @param {object} userData User credentials object.
115
+ * @param {string} userData.email User email address.
116
+ * @param {string} userData.password User password.
117
+ * @param {string} userData.connection Identity provider in use.
118
+ * @param {Function} [cb] Method callback.
119
+ * @returns {Promise|undefined}
120
+ */
121
+ signUp(userData, cb) {
122
+ if (!userData || typeof userData !== 'object') {
123
+ throw new ArgumentError('Missing user data object');
124
+ }
97
125
 
98
- /**
99
- * Sign up using a database or active directory service.
100
- * @method signUp
101
- * @memberOf module:auth.DatabaseAuthenticator.prototype
102
- *
103
- * @example <caption>
104
- * Given the user credentials, the connection specified and (optionally) the
105
- * client ID, it will create a new user. Find more information in the
106
- * <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-signup">
107
- * API Docs</a>.
108
- * </caption>
109
- *
110
- * var data = {
111
- * email: '{EMAIL}',
112
- * password: '{PASSWORD}',
113
- * connection: 'Username-Password-Authentication' // Optional field.
114
- * };
115
- *
116
- * auth0.database.signUp(data, function (err, userData) {
117
- * if (err) {
118
- * // Handle error.
119
- * }
120
- *
121
- * console.log(userData);
122
- * });
123
- *
124
- * @param {Object} data User credentials object.
125
- * @param {String} data.email User email address.
126
- * @param {String} data.password User password.
127
- * @param {String} data.connection Identity provider in use.
128
- * @param {Function} [cb] Method callback.
129
- *
130
- * @return {Promise|undefined}
131
- */
132
- DatabaseAuthenticator.prototype.signUp = function(userData, cb) {
133
- var params = {
134
- type: 'signup'
135
- };
136
- var defaultFields = {
137
- client_id: this.clientId
138
- };
139
- var data = extend(defaultFields, userData);
140
-
141
- if (!userData || typeof userData !== 'object') {
142
- throw new ArgumentError('Missing user data object');
143
- }
126
+ const data = {
127
+ client_id: this.clientId,
128
+ ...userData,
129
+ };
144
130
 
145
- if (typeof data.email !== 'string' || data.email.trim().length === 0) {
146
- throw new ArgumentError('email field is required');
147
- }
131
+ if (typeof data.email !== 'string' || data.email.trim().length === 0) {
132
+ throw new ArgumentError('email field is required');
133
+ }
148
134
 
149
- if (typeof data.password !== 'string' || data.password.trim().length === 0) {
150
- throw new ArgumentError('password field is required');
151
- }
135
+ if (typeof data.password !== 'string' || data.password.trim().length === 0) {
136
+ throw new ArgumentError('password field is required');
137
+ }
152
138
 
153
- if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
154
- throw new ArgumentError('connection field is required');
155
- }
139
+ if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
140
+ throw new ArgumentError('connection field is required');
141
+ }
156
142
 
157
- if (cb && cb instanceof Function) {
158
- return this.dbConnections.create(params, data, cb);
159
- }
143
+ const params = {
144
+ type: 'signup',
145
+ };
160
146
 
161
- return this.dbConnections.create(params, data);
162
- };
147
+ if (cb && cb instanceof Function) {
148
+ return this.dbConnections.create(params, data, cb);
149
+ }
163
150
 
164
- /**
165
- * Change password using a database or active directory service.
166
- *
167
- * @method changePassword
168
- * @memberOf module:auth.DatabaseAuthenticator.prototype
169
- *
170
- * @example <caption>
171
- * Given the user email, the connection specified and the new password to
172
- * use, Auth0 will send a forgot password email. Once the user clicks on the
173
- * confirm password change link, the new password specified in this POST will
174
- * be set to this user. Find more information in the
175
- * <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password>
176
- * API Docs</a>.
177
- * </caption>
178
- *
179
- * var data = {
180
- * email: '{EMAIL}',
181
- * password: '{PASSWORD}',
182
- * connection: 'Username-Password-Authentication'
183
- * };
184
- *
185
- * auth0.database.changePassword(data, function (err, message) {
186
- * if (err) {
187
- * // Handle error.
188
- * }
189
- *
190
- * console.log(message);
191
- * });
192
- *
193
- * @param {Object} data User credentials object.
194
- * @param {String} data.email User email address.
195
- * @param {String} data.password New password.
196
- * @param {String} data.connection Identity provider in use.
197
- * @param {Function} [cb] Method callback.
198
- *
199
- * @return {Promise|undefined}
200
- */
201
- DatabaseAuthenticator.prototype.changePassword = function(userData, cb) {
202
- var params = {
203
- type: 'change_password'
204
- };
205
- var defaultFields = {
206
- client_id: this.clientId
207
- };
208
- var data = extend(defaultFields, userData);
209
-
210
- if (!userData || typeof userData !== 'object') {
211
- throw new ArgumentError('Missing user data object');
151
+ return this.dbConnections.create(params, data);
212
152
  }
213
153
 
214
- if (typeof data.email !== 'string' || data.email.trim().length === 0) {
215
- throw new ArgumentError('email field is required');
216
- }
154
+ /**
155
+ * Change password using a database or active directory service.
156
+ *
157
+ * @example <caption>
158
+ * Given the user email, the connection specified and the new password to
159
+ * use, Auth0 will send a forgot password email. Once the user clicks on the
160
+ * confirm password change link, the new password specified in this POST will
161
+ * be set to this user. Find more information in the
162
+ * <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password>
163
+ * API Docs</a>.
164
+ * </caption>
165
+ *
166
+ * var data = {
167
+ * email: '{EMAIL}',
168
+ * password: '{PASSWORD}',
169
+ * connection: 'Username-Password-Authentication'
170
+ * };
171
+ *
172
+ * auth0.database.changePassword(data, function (err, message) {
173
+ * if (err) {
174
+ * // Handle error.
175
+ * }
176
+ *
177
+ * console.log(message);
178
+ * });
179
+ * @param {object} userData User credentials object.
180
+ * @param {string} userData.email User email address.
181
+ * @param {string} userData.password New password.
182
+ * @param {string} userData.connection Identity provider in use.
183
+ * @param {Function} [cb] Method callback.
184
+ * @returns {Promise|undefined}
185
+ */
186
+ changePassword(userData, cb) {
187
+ if (!userData || typeof userData !== 'object') {
188
+ throw new ArgumentError('Missing user data object');
189
+ }
217
190
 
218
- if (typeof data.password !== 'string' || data.password.trim().length === 0) {
219
- throw new ArgumentError('password field is required');
220
- }
191
+ const data = {
192
+ client_id: this.clientId,
193
+ ...userData,
194
+ };
221
195
 
222
- if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
223
- throw new ArgumentError('connection field is required');
224
- }
196
+ if (typeof data.email !== 'string' || data.email.trim().length === 0) {
197
+ throw new ArgumentError('email field is required');
198
+ }
225
199
 
226
- if (cb && cb instanceof Function) {
227
- return this.dbConnections.create(params, data, cb);
228
- }
200
+ if (typeof data.password !== 'string' || data.password.trim().length === 0) {
201
+ throw new ArgumentError('password field is required');
202
+ }
229
203
 
230
- return this.dbConnections.create(params, data);
231
- };
204
+ if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
205
+ throw new ArgumentError('connection field is required');
206
+ }
232
207
 
233
- /**
234
- * Request a change password email using a database or active directory service.
235
- *
236
- * @method requestChangePasswordEmail
237
- * @memberOf module:auth.DatabaseAuthenticator.prototype
238
- *
239
- * @example <caption>
240
- * Given the user email, the connection specified, Auth0 will send a change
241
- * password email. once the user clicks on the confirm password change link,
242
- * the new password specified in this POST will be set to this user. Find more
243
- * information in the <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password>
244
- * API Docs</a>.
245
- * </caption>
246
- *
247
- * var data = {
248
- * email: '{EMAIL}',
249
- * connection: 'Username-Password-Authentication',
250
- * client_id: 'OS1VzKTVjizL0VCc9Hx2ae2aTPXWy6BD'
251
- * };
252
- *
253
- * auth0.database.requestChangePasswordEmail(data, function (err, message) {
254
- * if (err) {
255
- * // Handle error.
256
- * }
257
- *
258
- * console.log(message);
259
- * });
260
- *
261
- * @param {Object} data User credentials object.
262
- * @param {String} data.email User email address.
263
- * @param {String} data.connection Identity provider in use.
264
- * @param {String} data.client_id Client ID of the Application requesting the password change, to be included in the email template.
265
- * @param {Function} [cb] Method callback.
266
- *
267
- * @return {Promise|undefined}
268
- */
269
- DatabaseAuthenticator.prototype.requestChangePasswordEmail = function(userData, cb) {
270
- var params = {
271
- type: 'change_password'
272
- };
273
- var defaultFields = {
274
- client_id: this.clientId
275
- };
276
- var data = extend(defaultFields, userData);
277
-
278
- if (!userData || typeof userData !== 'object') {
279
- throw new ArgumentError('Missing user data object');
280
- }
208
+ const params = {
209
+ type: 'change_password',
210
+ };
281
211
 
282
- if (typeof data.email !== 'string' || data.email.trim().length === 0) {
283
- throw new ArgumentError('email field is required');
284
- }
212
+ if (cb && cb instanceof Function) {
213
+ return this.dbConnections.create(params, data, cb);
214
+ }
285
215
 
286
- if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
287
- throw new ArgumentError('connection field is required');
216
+ return this.dbConnections.create(params, data);
288
217
  }
289
218
 
290
- if (cb && cb instanceof Function) {
291
- return this.dbConnections.create(params, data, cb);
292
- }
219
+ /**
220
+ * Request a change password email using a database or active directory service.
221
+ *
222
+ * @example <caption>
223
+ * Given the user email, the connection specified, Auth0 will send a change
224
+ * password email. once the user clicks on the confirm password change link,
225
+ * the new password specified in this POST will be set to this user. Find more
226
+ * information in the <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password>
227
+ * API Docs</a>.
228
+ * </caption>
229
+ *
230
+ * var data = {
231
+ * email: '{EMAIL}',
232
+ * connection: 'Username-Password-Authentication',
233
+ * client_id: 'OS1VzKTVjizL0VCc9Hx2ae2aTPXWy6BD'
234
+ * };
235
+ *
236
+ * auth0.database.requestChangePasswordEmail(data, function (err, message) {
237
+ * if (err) {
238
+ * // Handle error.
239
+ * }
240
+ *
241
+ * console.log(message);
242
+ * });
243
+ * @param {object} userData User credentials object.
244
+ * @param {string} userData.email User email address.
245
+ * @param {string} userData.connection Identity provider in use.
246
+ * @param {string} userData.client_id Client ID of the Application requesting the password change, to be included in the email template.
247
+ * @param {Function} [cb] Method callback.
248
+ * @returns {Promise|undefined}
249
+ */
250
+ requestChangePasswordEmail(userData, cb) {
251
+ if (!userData || typeof userData !== 'object') {
252
+ throw new ArgumentError('Missing user data object');
253
+ }
293
254
 
294
- return this.dbConnections.create(params, data);
295
- };
255
+ const data = {
256
+ client_id: this.clientId,
257
+ ...userData,
258
+ };
259
+
260
+ if (typeof data.email !== 'string' || data.email.trim().length === 0) {
261
+ throw new ArgumentError('email field is required');
262
+ }
263
+
264
+ if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
265
+ throw new ArgumentError('connection field is required');
266
+ }
267
+
268
+ const params = {
269
+ type: 'change_password',
270
+ };
271
+
272
+ if (cb && cb instanceof Function) {
273
+ return this.dbConnections.create(params, data, cb);
274
+ }
275
+
276
+ return this.dbConnections.create(params, data);
277
+ }
278
+ }
296
279
 
297
280
  module.exports = DatabaseAuthenticator;