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
package/src/auth/index.js CHANGED
@@ -1,29 +1,23 @@
1
- /** @module auth **/
2
-
3
- var util = require('util');
4
- var utils = require('../utils');
5
- var jsonToBase64 = utils.jsonToBase64;
6
- var ArgumentError = require('rest-facade').ArgumentError;
1
+ const util = require('util');
2
+ const utils = require('../utils');
3
+ const { jsonToBase64 } = utils;
4
+ const { ArgumentError } = require('rest-facade');
7
5
 
8
6
  // Authenticators.
9
- var OAuthAuthenticator = require('./OAuthAuthenticator');
10
- var DatabaseAuthenticator = require('./DatabaseAuthenticator');
11
- var PasswordlessAuthenticator = require('./PasswordlessAuthenticator');
7
+ const OAuthAuthenticator = require('./OAuthAuthenticator');
8
+ const DatabaseAuthenticator = require('./DatabaseAuthenticator');
9
+ const PasswordlessAuthenticator = require('./PasswordlessAuthenticator');
12
10
 
13
11
  // Managers
14
- var UsersManager = require('./UsersManager');
15
- var TokensManager = require('./TokensManager');
12
+ const UsersManager = require('./UsersManager');
13
+ const TokensManager = require('./TokensManager');
16
14
 
17
- var BASE_URL_FORMAT = 'https://%s';
15
+ const BASE_URL_FORMAT = 'https://%s';
18
16
 
19
17
  /**
20
- * @class
21
18
  * Authentication API SDK.
22
19
  *
23
- * This client must used to access Auth0's
24
- * <a href="https://auth0.com/docs/auth-api">Authentication API</a>.
25
- * @constructor
26
- * @memberOf module:auth
20
+ * This client must used to access Auth0's {@link https://auth0.com/docs/auth-api Authentication API}.
27
21
  *
28
22
  * @example <caption>
29
23
  * The <b>AuthenticationClient</b> constructor takes an <i>optional</i> client
@@ -36,603 +30,538 @@ var BASE_URL_FORMAT = 'https://%s';
36
30
  * domain: '{YOUR_ACCOUNT}.auth0.com',
37
31
  * clientId: '{OPTIONAL_CLIENT_ID}'
38
32
  * });
39
- *
40
- * @param {Object} options Options for the Authentication Client SDK.
41
- * @param {String} options.domain AuthenticationClient server domain.
42
- * @param {String} [options.clientId] Default client ID.
43
- * @param {String} [options.clientSecret] Default client Secret.
44
- * @param {String} [options.supportedAlgorithms] Algorithms that your application expects to receive
45
- * @param {Boolean} [options.__bypassIdTokenValidation] Whether the id_token should be validated or not
46
- * @param {Object} [options.headers] Additional headers that will be added to the outgoing requests.
47
33
  */
48
- var AuthenticationClient = function(options) {
49
- if (!options || typeof options !== 'object') {
50
- throw new ArgumentError('Authentication Client SDK options must be an object');
51
- }
34
+ class AuthenticationClient {
35
+ /**
36
+ * @param {object} options Options for the Authentication Client SDK.
37
+ * @param {string} options.domain AuthenticationClient server domain.
38
+ * @param {string} [options.clientId] Default client ID.
39
+ * @param {string} [options.clientSecret] Default client Secret.
40
+ * @param {string} [options.supportedAlgorithms] Algorithms that your application expects to receive
41
+ * @param {boolean} [options.__bypassIdTokenValidation] Whether the id_token should be validated or not
42
+ * @param {object} [options.headers] Additional headers that will be added to the outgoing requests.
43
+ */
44
+ constructor(options) {
45
+ if (!options || typeof options !== 'object') {
46
+ throw new ArgumentError('Authentication Client SDK options must be an object');
47
+ }
52
48
 
53
- if (!options.domain || options.domain.length === 0) {
54
- throw new ArgumentError('Must provide a domain');
55
- }
49
+ if (!options.domain || options.domain.length === 0) {
50
+ throw new ArgumentError('Must provide a domain');
51
+ }
56
52
 
57
- var defaultHeaders = {
58
- 'User-Agent': 'node.js/' + process.version.replace('v', ''),
59
- 'Content-Type': 'application/json'
60
- };
61
-
62
- var managerOptions = {
63
- clientId: options.clientId,
64
- domain: options.domain,
65
- clientSecret: options.clientSecret,
66
- headers: Object.assign(defaultHeaders, options.headers || {}),
67
- baseUrl: util.format(BASE_URL_FORMAT, options.domain),
68
- supportedAlgorithms: options.supportedAlgorithms,
69
- __bypassIdTokenValidation: options.__bypassIdTokenValidation
70
- };
71
-
72
- if (options.telemetry !== false) {
73
- var clientInfo = options.clientInfo || utils.generateClientInfo();
74
- if ('string' === typeof clientInfo.name && clientInfo.name) {
75
- var telemetry = jsonToBase64(clientInfo);
76
- managerOptions.headers['Auth0-Client'] = telemetry;
53
+ const defaultHeaders = {
54
+ 'User-Agent': `node.js/${process.version.replace('v', '')}`,
55
+ 'Content-Type': 'application/json',
56
+ };
57
+
58
+ const managerOptions = {
59
+ clientId: options.clientId,
60
+ domain: options.domain,
61
+ clientSecret: options.clientSecret,
62
+ headers: Object.assign(defaultHeaders, options.headers || {}),
63
+ baseUrl: util.format(BASE_URL_FORMAT, options.domain),
64
+ supportedAlgorithms: options.supportedAlgorithms,
65
+ __bypassIdTokenValidation: options.__bypassIdTokenValidation,
66
+ };
67
+
68
+ if (options.telemetry !== false) {
69
+ const clientInfo = options.clientInfo || utils.generateClientInfo();
70
+ if ('string' === typeof clientInfo.name && clientInfo.name) {
71
+ const telemetry = jsonToBase64(clientInfo);
72
+ managerOptions.headers['Auth0-Client'] = telemetry;
73
+ }
77
74
  }
75
+
76
+ /**
77
+ * OAuth authenticator.
78
+ *
79
+ * @type {OAuthAuthenticator}
80
+ */
81
+ this.oauth = new OAuthAuthenticator(managerOptions);
82
+
83
+ /**
84
+ * Database authenticator.
85
+ *
86
+ * @type {DatabaseAuthenticator}
87
+ */
88
+ this.database = new DatabaseAuthenticator(managerOptions, this.oauth);
89
+
90
+ /**
91
+ * Passwordless authenticator.
92
+ *
93
+ * @type {PasswordlessAuthenticator}
94
+ */
95
+ this.passwordless = new PasswordlessAuthenticator(managerOptions, this.oauth);
96
+
97
+ /**
98
+ * Users manager.
99
+ *
100
+ * @type {UsersManager}
101
+ */
102
+ this.users = new UsersManager(managerOptions);
103
+
104
+ /**
105
+ * Tokens manager.
106
+ *
107
+ * @type {TokensManager}
108
+ */
109
+ this.tokens = new TokensManager(managerOptions);
78
110
  }
79
111
 
80
112
  /**
81
- * OAuth authenticator.
113
+ * Start passwordless flow sending an email.
114
+ *
115
+ * @example <caption>
116
+ * Given the user `email` address, it will send an email with a link. You can
117
+ * then authenticate with this user opening the link and he will be
118
+ * automatically logged in to the application. Optionally, you can
119
+ * append/override parameters to the link (like `scope`, `redirect_uri`,
120
+ * `protocol`, `response_type`, etc.) using `authParams` object.
121
+ *
122
+ * Find more information in the
123
+ * <a href="https://auth0.com/docs/auth-api#!#post--with_email">API Docs</a>
124
+ * </caption>
125
+ *
126
+ * var data = {
127
+ * email: '{EMAIL}',
128
+ * authParams: {} // Optional auth params.
129
+ * };
82
130
  *
83
- * @type {OAuthAuthenticator}
131
+ * auth0.requestMagicLink(data, function (err) {
132
+ * if (err) {
133
+ * // Handle error.
134
+ * }
135
+ * };
136
+ * @param {object} data User data object.
137
+ * @param {string} data.email User email address.
138
+ * @param {object} [data.authParams] Authentication parameters.
139
+ * @param {Function} [cb] Method callback.
140
+ * @returns {Promise|undefined}
84
141
  */
85
- this.oauth = new OAuthAuthenticator(managerOptions);
142
+ requestMagicLink(data, cb) {
143
+ data.send = 'link';
144
+
145
+ return this.passwordless.sendEmail(data, cb);
146
+ }
86
147
 
87
148
  /**
88
- * Database authenticator.
149
+ * Start passwordless flow sending an email.
150
+ *
151
+ * @example <caption>
152
+ * Given the user `email` address, it will send an email with a verification
153
+ * code. You can then authenticate with this user using the `/oauth/ro`
154
+ * endpoint using the email as username and the code as password.
155
+ *
156
+ * Find more information in the
157
+ * <a href="https://auth0.com/docs/auth-api#!#post--with_email">API Docs</a>
158
+ * </caption>
89
159
  *
90
- * @type {DatabaseAuthenticator}
160
+ * var data = {
161
+ * email: '{EMAIL}',
162
+ * authParams: {} // Optional auth params.
163
+ * };
164
+ *
165
+ * auth0.requestEmailCode(data, function (err) {
166
+ * if (err) {
167
+ * // Handle error.
168
+ * }
169
+ * };
170
+ * @param {object} data User data object.
171
+ * @param {string} data.email User email address.
172
+ * @param {object} [data.authParams] Authentication parameters.
173
+ * @param {Function} [cb] Method callback.
174
+ * @returns {Promise|undefined}
91
175
  */
92
- this.database = new DatabaseAuthenticator(managerOptions, this.oauth);
176
+ requestEmailCode(data, cb) {
177
+ data.send = 'code';
178
+
179
+ return this.passwordless.sendEmail(data, cb);
180
+ }
93
181
 
94
182
  /**
95
- * Passwordless authenticator.
183
+ * Verify the given OTP which was sent on the given email.
184
+ *
185
+ * @example <caption>
186
+ * Given the user credentials (`email` and `otp`), authenticates
187
+ * with the provider using the `/oauth/token` endpoint. Upon successful
188
+ * authentication, returns a JSON object containing the `access_token` and
189
+ * `id_token`.
190
+ * </caption>
96
191
  *
97
- * @type {PasswordlessAuthenticator}
192
+ * var data = {
193
+ * email: '{EMAIL}',
194
+ * otp: '{VERIFICATION_CODE}'
195
+ * };
196
+ *
197
+ * auth0.verifyEmailCode(data, function (err) {
198
+ * if (err) {
199
+ * // Handle error.
200
+ * }
201
+ * });
202
+ * @example <caption>
203
+ * The user data object has the following structure.
204
+ * </caption>
205
+ *
206
+ * {
207
+ * id_token: String,
208
+ * access_token: String,
209
+ * token_type: String
210
+ * }
211
+ * @param {object} data Credentials object.
212
+ * @param {string} data.email Email.
213
+ * @param {string} data.otp Verification code.
214
+ * @param {Function} [cb] Method callback.
215
+ * @returns {Promise|undefined}
98
216
  */
99
- this.passwordless = new PasswordlessAuthenticator(managerOptions, this.oauth);
217
+ verifyEmailCode(data, cb) {
218
+ const translatedData = {
219
+ username: data.email,
220
+ realm: 'email',
221
+ otp: data.otp,
222
+ };
223
+
224
+ return this.passwordless.signIn(translatedData, cb);
225
+ }
100
226
 
101
227
  /**
102
- * Users manager.
228
+ * Start passwordless flow sending an SMS.
229
+ *
230
+ * @example <caption>
231
+ * Given the user `phone_number`, it will send a SMS message with a
232
+ * verification code. You can then authenticate with this user using the
233
+ * `/oauth/ro` endpoint specifying `phone_number` as `username` and `code` as
234
+ * `password`:
235
+ * </caption>
103
236
  *
104
- * @type {UsersManager}
237
+ * var data = {
238
+ * phone_number: '{PHONE}'
239
+ * };
240
+ *
241
+ * auth0.requestSMSCode(data, function (err) {
242
+ * if (err) {
243
+ * // Handle error.
244
+ * }
245
+ *
246
+ * });
247
+ * @param {object} data User data object.
248
+ * @param {string} data.phone_number The user phone number.
249
+ * @param {Function} [cb] Method callback.
250
+ * @returns {Promise|undefined}
105
251
  */
106
- this.users = new UsersManager(managerOptions);
252
+ requestSMSCode(data, cb) {
253
+ const translatedData = {
254
+ phone_number: data.phoneNumber || data.phone_number,
255
+ };
256
+
257
+ return this.passwordless.sendSMS(translatedData, cb);
258
+ }
107
259
 
108
260
  /**
109
- * Tokens manager.
261
+ * Sign in with the given user credentials.
262
+ *
263
+ * @example <caption>
264
+ * Given the user credentials (`phone_number` and `otp`), authenticates
265
+ * with the provider using the `/oauth/token` endpoint. Upon successful
266
+ * authentication, returns a JSON object containing the `access_token` and
267
+ * `id_token`.
268
+ * </caption>
269
+ *
270
+ * var data = {
271
+ * username: '{PHONE_NUMBER}'
272
+ * otp: '{VERIFICATION_CODE}'
273
+ * };
274
+ *
275
+ * auth0.verifySMSCode(data, function (err) {
276
+ * if (err) {
277
+ * // Handle error.
278
+ * }
279
+ * });
280
+ * @example <caption>
281
+ * Given the user credentials (`phone_number` and `password`), authenticates
282
+ * with the provider using the deprecated `/oauth/ro` endpoint. Upon successful
283
+ * authentication, returns a JSON object containing the `access_token` and
284
+ * `id_token`.
285
+ * </caption>
110
286
  *
111
- * @type {TokensManager}
287
+ * var data = {
288
+ * username: '{PHONE_NUMBER}',
289
+ * password: '{VERIFICATION_CODE}'
290
+ * };
291
+ *
292
+ * auth0.verifySMSCode(data, function (err) {
293
+ * if (err) {
294
+ * // Handle error.
295
+ * }
296
+ * });
297
+ * @example <caption>
298
+ * The user data object has the following structure.
299
+ * </caption>
300
+ *
301
+ * {
302
+ * id_token: String,
303
+ * access_token: String,
304
+ * token_type: String
305
+ * }
306
+ * @param {object} data Credentials object.
307
+ * @param {string} data.username Phone number.
308
+ * @param {string} data.otp Verification code. Use this instead of `password` to use the `/oauth/token` endpoint.
309
+ * @param {string} data.password Verification code. Use this instead of `otp` to use the `/oauth/ro` endpoint.
310
+ * @param {Function} [cb] Method callback.
311
+ * @returns {Promise|undefined}
112
312
  */
113
- this.tokens = new TokensManager(managerOptions);
114
- };
115
-
116
- /**
117
- * Start passwordless flow sending an email.
118
- *
119
- * @method requestMagicLink
120
- * @memberOf module:auth.AuthenticationClient.prototype
121
- *
122
- * @example <caption>
123
- * Given the user `email` address, it will send an email with a link. You can
124
- * then authenticate with this user opening the link and he will be
125
- * automatically logged in to the application. Optionally, you can
126
- * append/override parameters to the link (like `scope`, `redirect_uri`,
127
- * `protocol`, `response_type`, etc.) using `authParams` object.
128
- *
129
- * Find more information in the
130
- * <a href="https://auth0.com/docs/auth-api#!#post--with_email">API Docs</a>
131
- * </caption>
132
- *
133
- * var data = {
134
- * email: '{EMAIL}',
135
- * authParams: {} // Optional auth params.
136
- * };
137
- *
138
- * auth0.requestMagicLink(data, function (err) {
139
- * if (err) {
140
- * // Handle error.
141
- * }
142
- * };
143
- *
144
- * @param {Object} data User data object.
145
- * @param {String} data.email User email address.
146
- * @param {Object} [data.authParams] Authentication parameters.
147
- * @param {Function} [cb] Method callback.
148
- *
149
- * @return {Promise|undefined}
150
- */
151
- AuthenticationClient.prototype.requestMagicLink = function(data, cb) {
152
- data.send = 'link';
153
-
154
- return this.passwordless.sendEmail(data, cb);
155
- };
156
-
157
- /**
158
- * Start passwordless flow sending an email.
159
- *
160
- * @method requestEmailCode
161
- * @memberOf module:auth.AuthenticationClient.prototype
162
- *
163
- * @example <caption>
164
- * Given the user `email` address, it will send an email with a verification
165
- * code. You can then authenticate with this user using the `/oauth/ro`
166
- * endpoint using the email as username and the code as password.
167
- *
168
- * Find more information in the
169
- * <a href="https://auth0.com/docs/auth-api#!#post--with_email">API Docs</a>
170
- * </caption>
171
- *
172
- * var data = {
173
- * email: '{EMAIL}',
174
- * authParams: {} // Optional auth params.
175
- * };
176
- *
177
- * auth0.requestEmailCode(data, function (err) {
178
- * if (err) {
179
- * // Handle error.
180
- * }
181
- * };
182
- *
183
- * @param {Object} data User data object.
184
- * @param {String} data.email User email address.
185
- * @param {Object} [data.authParams] Authentication parameters.
186
- * @param {Function} [cb] Method callback.
187
- *
188
- * @return {Promise|undefined}
189
- */
190
- AuthenticationClient.prototype.requestEmailCode = function(data, cb) {
191
- data.send = 'code';
192
-
193
- return this.passwordless.sendEmail(data, cb);
194
- };
195
-
196
- /**
197
- * Verify the given OTP which was sent on the given email.
198
- *
199
- * @method verifyEmailCode
200
- * @memberOf module:auth.AuthenticationClient.prototype
201
- *
202
- * @example <caption>
203
- * Given the user credentials (`email` and `otp`), authenticates
204
- * with the provider using the `/oauth/token` endpoint. Upon successful
205
- * authentication, returns a JSON object containing the `access_token` and
206
- * `id_token`.
207
- * </caption>
208
- *
209
- * var data = {
210
- * email: '{EMAIL}',
211
- * otp: '{VERIFICATION_CODE}'
212
- * };
213
- *
214
- * auth0.verifyEmailCode(data, function (err) {
215
- * if (err) {
216
- * // Handle error.
217
- * }
218
- * });
219
- *
220
- * @example <caption>
221
- * The user data object has the following structure.
222
- * </caption>
223
- *
224
- * {
225
- * id_token: String,
226
- * access_token: String,
227
- * token_type: String
228
- * }
229
- *
230
- * @param {Object} data Credentials object.
231
- * @param {String} data.email Email.
232
- * @param {String} data.otp Verification code.
233
- * @param {Function} [cb] Method callback.
234
- *
235
- * @return {Promise|undefined}
236
- */
237
- AuthenticationClient.prototype.verifyEmailCode = function(data, cb) {
238
- var translatedData = {
239
- username: data.email,
240
- realm: 'email',
241
- otp: data.otp
242
- };
243
-
244
- return this.passwordless.signIn(translatedData, cb);
245
- };
246
-
247
- /**
248
- * Start passwordless flow sending an SMS.
249
- *
250
- * @method requestSMSCode
251
- * @memberOf module:auth.AuthenticationClient.prototype
252
- *
253
- * @example <caption>
254
- * Given the user `phone_number`, it will send a SMS message with a
255
- * verification code. You can then authenticate with this user using the
256
- * `/oauth/ro` endpoint specifying `phone_number` as `username` and `code` as
257
- * `password`:
258
- * </caption>
259
- *
260
- * var data = {
261
- * phone_number: '{PHONE}'
262
- * };
263
- *
264
- * auth0.requestSMSCode(data, function (err) {
265
- * if (err) {
266
- * // Handle error.
267
- * }
268
- *
269
- * });
270
- *
271
- * @param {Object} data User data object.
272
- * @param {String} data.phone_number The user phone number.
273
- * @param {Function} [cb] Method callback.
274
- *
275
- * @return {Promise|undefined}
276
- */
277
- AuthenticationClient.prototype.requestSMSCode = function(data, cb) {
278
- var translatedData = {
279
- phone_number: data.phoneNumber || data.phone_number
280
- };
281
-
282
- return this.passwordless.sendSMS(translatedData, cb);
283
- };
313
+ verifySMSCode(data, cb) {
314
+ const translatedData = {
315
+ username: data.phoneNumber || data.phone_number || data.username,
316
+ };
317
+
318
+ if (data.otp) {
319
+ translatedData.otp = data.otp;
320
+ } else {
321
+ translatedData.password = data.code || data.password;
322
+ }
284
323
 
285
- /**
286
- * Sign in with the given user credentials.
287
- *
288
- * @method verifySMSCode
289
- * @memberOf module:auth.AuthenticationClient.prototype
290
- *
291
- * @example <caption>
292
- * Given the user credentials (`phone_number` and `otp`), authenticates
293
- * with the provider using the `/oauth/token` endpoint. Upon successful
294
- * authentication, returns a JSON object containing the `access_token` and
295
- * `id_token`.
296
- * </caption>
297
- *
298
- * var data = {
299
- * username: '{PHONE_NUMBER}'
300
- * otp: '{VERIFICATION_CODE}'
301
- * };
302
- *
303
- * auth0.verifySMSCode(data, function (err) {
304
- * if (err) {
305
- * // Handle error.
306
- * }
307
- * });
308
- *
309
- * @example <caption>
310
- * Given the user credentials (`phone_number` and `password`), authenticates
311
- * with the provider using the deprecated `/oauth/ro` endpoint. Upon successful
312
- * authentication, returns a JSON object containing the `access_token` and
313
- * `id_token`.
314
- * </caption>
315
- *
316
- * var data = {
317
- * username: '{PHONE_NUMBER}',
318
- * password: '{VERIFICATION_CODE}'
319
- * };
320
- *
321
- * auth0.verifySMSCode(data, function (err) {
322
- * if (err) {
323
- * // Handle error.
324
- * }
325
- * });
326
- *
327
- * @example <caption>
328
- * The user data object has the following structure.
329
- * </caption>
330
- *
331
- * {
332
- * id_token: String,
333
- * access_token: String,
334
- * token_type: String
335
- * }
336
- *
337
- * @param {Object} data Credentials object.
338
- * @param {String} data.username Phone number.
339
- * @param {String} data.otp Verification code. Use this instead of `password` to use the `/oauth/token` endpoint.
340
- * @param {String} data.password Verification code. Use this instead of `otp` to use the `/oauth/ro` endpoint.
341
- * @param {Function} [cb] Method callback.
342
- *
343
- * @return {Promise|undefined}
344
- */
345
- AuthenticationClient.prototype.verifySMSCode = function(data, cb) {
346
- var translatedData = {
347
- username: data.phoneNumber || data.phone_number || data.username
348
- };
349
-
350
- if (data.otp) {
351
- translatedData.otp = data.otp;
352
- } else {
353
- translatedData.password = data.code || data.password;
324
+ return this.passwordless.signIn(translatedData, cb);
354
325
  }
355
326
 
356
- return this.passwordless.signIn(translatedData, cb);
357
- };
358
-
359
- /**
360
- * Exchange the token of the logged in user with a token that is valid to call
361
- * the API (signed with the API secret).
362
- *
363
- * @method getDelegationToken
364
- * @memberOf module:auth.AuthenticationClient.prototype
365
- *
366
- * @example <caption>
367
- * Given an existing token, this endpoint will generate a new token signed
368
- * with the target client secret. This is used to flow the identity of the
369
- * user from the application to an API or across different APIs that are
370
- * protected with different secrets. Find more information in the
371
- * <a href="https://auth0.com/docs/auth-api#!#post--delegation">API Docs</a>.
372
- * </caption>
373
- *
374
- * var data = {
375
- * id_token: '{ID_TOKEN}',
376
- * api_type: 'app',
377
- * target: '{TARGET}',
378
- * grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer'
379
- * };
380
- *
381
- * auth0.getDelegationToken(data, function (err, token) {
382
- * if (err) {
383
- * // Handle error.
384
- * }
385
- *
386
- * console.log(token);
387
- * });
388
- *
389
- * @param {Object} data Token data object.
390
- * @param {String} data.id_token The user ID token.
391
- * @param {String} data.api_type The API type (aws, firebase, etc).
392
- * @param {String} data.target The target client ID.
393
- * @param {String} data.grant_type The grant type.
394
- * @param {Function} [cb] Method callback.
395
- *
396
- * @return {Promise|undefined}
397
- */
398
- AuthenticationClient.prototype.getDelegationToken = function(data, cb) {
399
- var translatedData = {
400
- id_token: data.id_token,
401
- api_type: data.api || data.api_type,
402
- scope: data.scope,
403
- target: data.targetClientId || data.target,
404
- grant_type: data.grant_type
405
- };
406
-
407
- return this.tokens.getDelegationToken(translatedData, cb);
408
- };
409
-
410
- /**
411
- * Change password using a database or active directory service.
412
- *
413
- * @method changePassword
414
- * @memberOf module:auth.AuthenticationClient.prototype
415
- *
416
- * @example <caption>
417
- * Given the user email, the connection specified and the new password to
418
- * use, Auth0 will send a forgot password email. Once the user clicks on the
419
- * confirm password change link, the new password specified in this POST will
420
- * be set to this user. Find more information in the
421
- * <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password">
422
- * API Docs</a>.
423
- * </caption>
424
- *
425
- * var data = {
426
- * email: '{EMAIL}',
427
- * password: '{PASSWORD}',
428
- * connection: 'Username-Password-Authentication'
429
- * };
430
- *
431
- * auth0.changePassword(data, function (err, message) {
432
- * if (err) {
433
- * // Handle error.
434
- * }
435
- *
436
- * console.log(message);
437
- * });
438
- *
439
- * @param {Object} data User data object.
440
- * @param {String} data.email User email.
441
- * @param {String} data.password User password.
442
- * @param {String} data.connection Identity provider for the user.
443
- * @param {Function} [cb] Method callback.
444
- *
445
- * @return {Promise|undefined}
446
- */
447
- AuthenticationClient.prototype.changePassword = function(data, cb) {
448
- var translatedData = {
449
- connection: data.connection,
450
- email: data.email || data.username,
451
- password: data.password
452
- };
453
-
454
- return this.database.changePassword(data, cb);
455
- };
327
+ /**
328
+ * Exchange the token of the logged in user with a token that is valid to call
329
+ * the API (signed with the API secret).
330
+ *
331
+ * @example <caption>
332
+ * Given an existing token, this endpoint will generate a new token signed
333
+ * with the target client secret. This is used to flow the identity of the
334
+ * user from the application to an API or across different APIs that are
335
+ * protected with different secrets. Find more information in the
336
+ * <a href="https://auth0.com/docs/auth-api#!#post--delegation">API Docs</a>.
337
+ * </caption>
338
+ *
339
+ * var data = {
340
+ * id_token: '{ID_TOKEN}',
341
+ * api_type: 'app',
342
+ * target: '{TARGET}',
343
+ * grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer'
344
+ * };
345
+ *
346
+ * auth0.getDelegationToken(data, function (err, token) {
347
+ * if (err) {
348
+ * // Handle error.
349
+ * }
350
+ *
351
+ * console.log(token);
352
+ * });
353
+ * @param {object} data Token data object.
354
+ * @param {string} data.id_token The user ID token.
355
+ * @param {string} data.api_type The API type (aws, firebase, etc).
356
+ * @param {string} data.target The target client ID.
357
+ * @param {string} data.grant_type The grant type.
358
+ * @param {Function} [cb] Method callback.
359
+ * @returns {Promise|undefined}
360
+ */
361
+ getDelegationToken(data, cb) {
362
+ const translatedData = {
363
+ id_token: data.id_token,
364
+ api_type: data.api || data.api_type,
365
+ scope: data.scope,
366
+ target: data.targetClientId || data.target,
367
+ grant_type: data.grant_type,
368
+ };
369
+
370
+ return this.tokens.getDelegationToken(translatedData, cb);
371
+ }
456
372
 
457
- /**
458
- * Request a change password email using a database or active directory service.
459
- *
460
- * @method requestChangePasswordEmail
461
- * @memberOf module:auth.AuthenticationClient.prototype
462
- *
463
- * @example <caption>
464
- * Given the user email, the connection specified, Auth0 will send a change
465
- * password email. once the user clicks on the confirm password change link,
466
- * the new password specified in this POST will be set to this user. Find more
467
- * information in the <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password>
468
- * API Docs</a>.
469
- * </caption>
470
- *
471
- * var data = {
472
- * email: '{EMAIL}',
473
- * connection: 'Username-Password-Authentication',
474
- * client_id: 'OS1VzKTVjizL0VCc9Hx2ae2aTPXWy6BD'
475
- * };
476
- *
477
- * auth0.requestChangePasswordEmail(data, function (err, message) {
478
- * if (err) {
479
- * // Handle error.
480
- * }
481
- *
482
- * console.log(message);
483
- * });
484
- *
485
- * @param {Object} data User data object.
486
- * @param {String} data.email User email.
487
- * @param {String} data.connection Identity provider for the user.
488
- * @param {String} data.client_id Client ID of the Application requesting the password change, to be included in the email template.
489
- * @param {Function} [cb] Method callback.
490
- *
491
- * @return {Promise|undefined}
492
- */
493
- AuthenticationClient.prototype.requestChangePasswordEmail = function(data, cb) {
494
- var translatedData = {
495
- connection: data.connection,
496
- email: data.email || data.username
497
- };
373
+ /**
374
+ * Change password using a database or active directory service.
375
+ *
376
+ * @example <caption>
377
+ * Given the user email, the connection specified and the new password to
378
+ * use, Auth0 will send a forgot password email. Once the user clicks on the
379
+ * confirm password change link, the new password specified in this POST will
380
+ * be set to this user. Find more information in the
381
+ * <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password">
382
+ * API Docs</a>.
383
+ * </caption>
384
+ *
385
+ * var data = {
386
+ * email: '{EMAIL}',
387
+ * password: '{PASSWORD}',
388
+ * connection: 'Username-Password-Authentication'
389
+ * };
390
+ *
391
+ * auth0.changePassword(data, function (err, message) {
392
+ * if (err) {
393
+ * // Handle error.
394
+ * }
395
+ *
396
+ * console.log(message);
397
+ * });
398
+ * @param {object} data User data object.
399
+ * @param {string} data.email User email.
400
+ * @param {string} data.password User password.
401
+ * @param {string} data.connection Identity provider for the user.
402
+ * @param {Function} [cb] Method callback.
403
+ * @returns {Promise|undefined}
404
+ */
405
+ changePassword(data, cb) {
406
+ return this.database.changePassword(data, cb);
407
+ }
498
408
 
499
- return this.database.requestChangePasswordEmail(data, cb);
500
- };
409
+ /**
410
+ * Request a change password email using a database or active directory service.
411
+ *
412
+ * @example <caption>
413
+ * Given the user email, the connection specified, Auth0 will send a change
414
+ * password email. once the user clicks on the confirm password change link,
415
+ * the new password specified in this POST will be set to this user. Find more
416
+ * information in the <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password>
417
+ * API Docs</a>.
418
+ * </caption>
419
+ *
420
+ * var data = {
421
+ * email: '{EMAIL}',
422
+ * connection: 'Username-Password-Authentication',
423
+ * client_id: 'OS1VzKTVjizL0VCc9Hx2ae2aTPXWy6BD'
424
+ * };
425
+ *
426
+ * auth0.requestChangePasswordEmail(data, function (err, message) {
427
+ * if (err) {
428
+ * // Handle error.
429
+ * }
430
+ *
431
+ * console.log(message);
432
+ * });
433
+ * @param {object} data User data object.
434
+ * @param {string} data.email User email.
435
+ * @param {string} data.connection Identity provider for the user.
436
+ * @param {string} data.client_id Client ID of the Application requesting the password change, to be included in the email template.
437
+ * @param {Function} [cb] Method callback.
438
+ * @returns {Promise|undefined}
439
+ */
440
+ requestChangePasswordEmail(data, cb) {
441
+ return this.database.requestChangePasswordEmail(data, cb);
442
+ }
501
443
 
502
- /**
503
- * Given an access token get the user profile linked to it.
504
- *
505
- * @method getProfile
506
- * @memberOf module:auth.AuthenticationClient.prototype
507
- *
508
- * @example <caption>
509
- * Get the user information based on the Auth0 access token (obtained during
510
- * login). Find more information in the
511
- * <a href="https://auth0.com/docs/auth-api#!#get--userinfo">API Docs</a>.
512
- * </caption>
513
- *
514
- * auth0.getProfile(data, function (err, userInfo) {
515
- * if (err) {
516
- * // Handle error.
517
- * }
518
- *
519
- * console.log(userInfo);
520
- * });
521
- *
522
- * @param {String} accessToken The user access token.
523
- *
524
- * @return {Promise|undefined}
525
- */
526
- utils.wrapPropertyMethod(AuthenticationClient, 'getProfile', 'users.getInfo');
444
+ /**
445
+ * Given an access token get the user profile linked to it.
446
+ *
447
+ * @example <caption>
448
+ * Get the user information based on the Auth0 access token (obtained during
449
+ * login). Find more information in the
450
+ * <a href="https://auth0.com/docs/auth-api#!#get--userinfo">API Docs</a>.
451
+ * </caption>
452
+ *
453
+ * auth0.getProfile(data, function (err, userInfo) {
454
+ * if (err) {
455
+ * // Handle error.
456
+ * }
457
+ *
458
+ * console.log(userInfo);
459
+ * });
460
+ * @param {string} accessToken The user access token.
461
+ * @returns {Promise|undefined}
462
+ */
463
+ getProfile(...args) {
464
+ return this.users.getInfo(...args);
465
+ }
527
466
 
528
- /**
529
- * Gets an access token using the client credentials grant flow.
530
- *
531
- * @method clientCredentialsGrant
532
- * @memberOf module:auth.AuthenticationClient.prototype
533
- *
534
- * @example <caption>
535
- * Gets an access token using the client credentials grant flow. Find more information in the
536
- * <a href="https://auth0.com/docs/api-auth/config/asking-for-access-tokens">API Docs</a>.
537
- * </caption>
538
- *
539
- * auth0.clientCredentialsGrant({
540
- * audience: 'https://tenant.auth0.com/api/v2/',
541
- * scope: 'read:users update:users'
542
- * }, function (err, response) {
543
- * if (err) {
544
- * // Handle error.
545
- * }
546
- *
547
- * console.log(response);
548
- * });
549
- *
550
- * @param {Object} options
551
- * @param {String} [options.scope] scopes to request to be added to the returned access token
552
- * @param {String} [options.audience] audience or identifier of the API where the access token will be used, e.g. Auth0 Management API
553
- *
554
- * @return {Promise|undefined}
555
- */
556
- utils.wrapPropertyMethod(
557
- AuthenticationClient,
558
- 'clientCredentialsGrant',
559
- 'oauth.clientCredentialsGrant'
560
- );
467
+ /**
468
+ * Gets an access token using the client credentials grant flow.
469
+ *
470
+ * @example <caption>
471
+ * Gets an access token using the client credentials grant flow. Find more information in the
472
+ * <a href="https://auth0.com/docs/api-auth/config/asking-for-access-tokens">API Docs</a>.
473
+ * </caption>
474
+ *
475
+ * auth0.clientCredentialsGrant({
476
+ * audience: 'https://tenant.auth0.com/api/v2/',
477
+ * scope: 'read:users update:users'
478
+ * }, function (err, response) {
479
+ * if (err) {
480
+ * // Handle error.
481
+ * }
482
+ *
483
+ * console.log(response);
484
+ * });
485
+ * @param {object} options
486
+ * @param {string} [options.scope] scopes to request to be added to the returned access token
487
+ * @param {string} [options.audience] audience or identifier of the API where the access token will be used, e.g. Auth0 Management API
488
+ * @returns {Promise|undefined}
489
+ */
490
+ clientCredentialsGrant(...args) {
491
+ return this.oauth.clientCredentialsGrant(...args);
492
+ }
561
493
 
562
- /**
563
- * Sign in using a username and password
564
- *
565
- * @method passwordGrant
566
- * @memberOf module:auth.AuthenticationClient.prototype
567
- *
568
- * @example <caption>
569
- * Given the user's credentials perform the OAuth password grant
570
- * or Password Realm grant if a realm is provided,
571
- * it will return a JSON with the access_token and id_token.
572
- * More information in the
573
- * <a href="https://auth0.com/docs/api/authentication#resource-owner-password">
574
- * API Docs
575
- * </a>.
576
- * </caption>
577
- *
578
- * var data = {
579
- * client_id: '{CLIENT_ID}', // Optional field.
580
- * username: '{USERNAME}',
581
- * password: '{PASSWORD}'
582
- * realm: '{CONNECTION_NAME}', // Optional field.
583
- * scope: 'openid' // Optional field.
584
- * };
585
- *
586
- * auth0.passwordGrant(data, function (err, userData) {
587
- * if (err) {
588
- * // Handle error.
589
- * }
590
- *
591
- * console.log(userData);
592
- * });
593
- *
594
- * @param {Object} userData User credentials object.
595
- * @param {String} userData.username Username.
596
- * @param {String} userData.password User password.
597
- * @param {String} [userData.realm] Name of the realm to use to authenticate or the connection name
598
- *
599
- * @return {Promise|undefined}
600
- */
601
- utils.wrapPropertyMethod(AuthenticationClient, 'passwordGrant', 'oauth.passwordGrant');
494
+ /**
495
+ * Sign in using a username and password
496
+ *
497
+ * @example <caption>
498
+ * Given the user's credentials perform the OAuth password grant
499
+ * or Password Realm grant if a realm is provided,
500
+ * it will return a JSON with the access_token and id_token.
501
+ * More information in the
502
+ * <a href="https://auth0.com/docs/api/authentication#resource-owner-password">
503
+ * API Docs
504
+ * </a>.
505
+ * </caption>
506
+ *
507
+ * var data = {
508
+ * client_id: '{CLIENT_ID}', // Optional field.
509
+ * username: '{USERNAME}',
510
+ * password: '{PASSWORD}'
511
+ * realm: '{CONNECTION_NAME}', // Optional field.
512
+ * scope: 'openid' // Optional field.
513
+ * };
514
+ *
515
+ * auth0.passwordGrant(data, function (err, userData) {
516
+ * if (err) {
517
+ * // Handle error.
518
+ * }
519
+ *
520
+ * console.log(userData);
521
+ * });
522
+ * @param {object} userData User credentials object.
523
+ * @param {string} userData.username Username.
524
+ * @param {string} userData.password User password.
525
+ * @param {string} [userData.realm] Name of the realm to use to authenticate or the connection name
526
+ * @param {object} [options] Additional options.
527
+ * @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header
528
+ * @returns {Promise|undefined}
529
+ */
530
+ passwordGrant(...args) {
531
+ return this.oauth.passwordGrant(...args);
532
+ }
602
533
 
603
- /**
604
- * Sign in using a refresh token
605
- *
606
- * @method refreshToken
607
- * @memberOf module:auth.AuthenticationClient.prototype
608
- *
609
- * @example <caption>
610
- * Given a refresh token from a previous authentication request,
611
- * it will return a JSON with the access_token and id_token.
612
- * More information in the
613
- * <a href="https://auth0.com/docs/api/authentication#refresh-token">
614
- * API Docs
615
- * </a>.
616
- * </caption>
617
- *
618
- * var data = {
619
- * client_id: '{CLIENT_ID}', // Optional field.
620
- * refresh_token: '{REFRESH_TOKEN}',
621
- * };
622
- *
623
- * auth0.refreshToken(data, function (err, userData) {
624
- * if (err) {
625
- * // Handle error.
626
- * }
627
- *
628
- * console.log(userData);
629
- * });
630
- *
631
- * @param {Object} userData User credentials object.
632
- * @param {String} userData.refresh_token Refresh token.
633
- *
634
- * @return {Promise|undefined}
635
- */
636
- utils.wrapPropertyMethod(AuthenticationClient, 'refreshToken', 'oauth.refreshToken');
534
+ /**
535
+ * Sign in using a refresh token
536
+ *
537
+ * @example <caption>
538
+ * Given a refresh token from a previous authentication request,
539
+ * it will return a JSON with the access_token and id_token.
540
+ * More information in the
541
+ * <a href="https://auth0.com/docs/api/authentication#refresh-token">
542
+ * API Docs
543
+ * </a>.
544
+ * </caption>
545
+ *
546
+ * var data = {
547
+ * client_id: '{CLIENT_ID}', // Optional field.
548
+ * refresh_token: '{REFRESH_TOKEN}',
549
+ * };
550
+ *
551
+ * auth0.refreshToken(data, function (err, userData) {
552
+ * if (err) {
553
+ * // Handle error.
554
+ * }
555
+ *
556
+ * console.log(userData);
557
+ * });
558
+ * @param {object} userData User credentials object.
559
+ * @param {string} userData.refresh_token Refresh token.
560
+ * @returns {Promise|undefined}
561
+ */
562
+ refreshToken(...args) {
563
+ return this.oauth.refreshToken(...args);
564
+ }
565
+ }
637
566
 
638
567
  module.exports = AuthenticationClient;