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