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.
Files changed (51) hide show
  1. package/README.md +19 -15
  2. package/package.json +47 -33
  3. package/CHANGELOG.md +0 -673
  4. package/src/Auth0RestClient.js +0 -123
  5. package/src/RetryRestClient.js +0 -105
  6. package/src/auth/DatabaseAuthenticator.js +0 -282
  7. package/src/auth/OAUthWithIDTokenValidation.js +0 -124
  8. package/src/auth/OAuthAuthenticator.js +0 -405
  9. package/src/auth/PasswordlessAuthenticator.js +0 -303
  10. package/src/auth/TokensManager.js +0 -254
  11. package/src/auth/UsersManager.js +0 -161
  12. package/src/auth/clientAuthentication.js +0 -86
  13. package/src/auth/idToken.js +0 -167
  14. package/src/auth/index.js +0 -573
  15. package/src/errors.js +0 -60
  16. package/src/index.js +0 -11
  17. package/src/index.mjs +0 -11
  18. package/src/management/ActionsManager.js +0 -526
  19. package/src/management/AttackProtectionManager.js +0 -158
  20. package/src/management/BaseManager.js +0 -41
  21. package/src/management/BlacklistedTokensManager.js +0 -67
  22. package/src/management/BrandingManager.js +0 -250
  23. package/src/management/ClientCredentialsManager.js +0 -112
  24. package/src/management/ClientGrantsManager.js +0 -124
  25. package/src/management/ClientsManager.js +0 -184
  26. package/src/management/ConnectionsManager.js +0 -213
  27. package/src/management/CustomDomainsManager.js +0 -141
  28. package/src/management/DeviceCredentialsManager.js +0 -91
  29. package/src/management/EmailProviderManager.js +0 -101
  30. package/src/management/EmailTemplatesManager.js +0 -90
  31. package/src/management/GrantsManager.js +0 -84
  32. package/src/management/GuardianManager.js +0 -361
  33. package/src/management/HooksManager.js +0 -295
  34. package/src/management/JobsManager.js +0 -324
  35. package/src/management/LogStreamsManager.js +0 -136
  36. package/src/management/LogsManager.js +0 -82
  37. package/src/management/ManagementTokenProvider.js +0 -144
  38. package/src/management/MigrationsManager.js +0 -76
  39. package/src/management/OrganizationsManager.js +0 -721
  40. package/src/management/PromptsManager.js +0 -162
  41. package/src/management/ResourceServersManager.js +0 -143
  42. package/src/management/RolesManager.js +0 -329
  43. package/src/management/RulesConfigsManager.js +0 -86
  44. package/src/management/RulesManager.js +0 -148
  45. package/src/management/StatsManager.js +0 -84
  46. package/src/management/TenantManager.js +0 -76
  47. package/src/management/TicketsManager.js +0 -104
  48. package/src/management/UserBlocksManager.js +0 -121
  49. package/src/management/UsersManager.js +0 -882
  50. package/src/management/index.js +0 -3405
  51. package/src/utils.js +0 -60
@@ -1,123 +0,0 @@
1
- const RestClient = require('rest-facade').Client;
2
- const { ArgumentError } = require('rest-facade');
3
-
4
- const utils = require('./utils');
5
- const { SanitizedError } = require('./errors');
6
-
7
- class Auth0RestClient {
8
- constructor(resourceUrl, options, provider) {
9
- if (resourceUrl === null || resourceUrl === undefined) {
10
- throw new ArgumentError('Must provide a Resource Url');
11
- }
12
-
13
- if ('string' !== typeof resourceUrl || resourceUrl.length === 0) {
14
- throw new ArgumentError('The provided Resource Url is invalid');
15
- }
16
-
17
- if (options === null || typeof options !== 'object') {
18
- throw new ArgumentError('Must provide options');
19
- }
20
-
21
- options.errorCustomizer = options.errorCustomizer || SanitizedError;
22
- options.errorFormatter = options.errorFormatter || { message: 'message', name: 'error' };
23
-
24
- this.options = options;
25
- this.provider = provider;
26
- this.restClient = new RestClient(resourceUrl, options);
27
-
28
- this.wrappedProvider = function (method, args) {
29
- if (!this.provider) {
30
- return this._request(method, args);
31
- }
32
-
33
- let callback;
34
- if (args && args[args.length - 1] instanceof Function) {
35
- callback = args[args.length - 1];
36
- }
37
-
38
- return this.provider
39
- .getAccessToken()
40
- .then((access_token) => {
41
- this.restClient.options.headers['Authorization'] = `Bearer ${access_token}`;
42
- return this._request(method, args);
43
- })
44
- .catch((err) => {
45
- if (callback) {
46
- return callback(err);
47
- }
48
- throw err;
49
- });
50
- };
51
- }
52
-
53
- _request(method, args) {
54
- if (!this.options.includeResponseHeaders) {
55
- return this.restClient[method](...args);
56
- }
57
-
58
- let callback;
59
- // Handle the case where the promise variant is called without any args
60
- // client.get() -> client.get({}, callback)
61
- if (!args || !args.length) {
62
- args = [{}];
63
- }
64
- // Handle the case where an undefined placeholder is defined for callback
65
- // client.get(params, undefined) -> client.get(params, callback)
66
- if (typeof args[args.length - 1] === 'undefined') {
67
- args.pop();
68
- }
69
- if (typeof args[args.length - 1] === 'function') {
70
- callback = args.pop();
71
- }
72
- return new Promise((resolve, reject) => {
73
- this.restClient[method](...args, (err, data, headers) => {
74
- const payload = { data, headers };
75
- if (err) {
76
- if (callback) callback(err);
77
- else reject(err);
78
- return;
79
- }
80
- if (callback) callback(null, payload);
81
- else resolve(payload);
82
- });
83
- });
84
- }
85
-
86
- getAll(...args) {
87
- return this.wrappedProvider('getAll', args);
88
- }
89
-
90
- get(params, callback) {
91
- if (typeof params === 'object' && params.id) {
92
- params.id = utils.maybeDecode(`${params.id}`);
93
- }
94
- return this.wrappedProvider('get', [...[params, callback].filter(Boolean)]);
95
- }
96
-
97
- create(...args) {
98
- return this.wrappedProvider('create', args);
99
- }
100
-
101
- patch(params, ...restOfArgs) {
102
- if (typeof params === 'object' && params.id) {
103
- params.id = utils.maybeDecode(`${params.id}`);
104
- }
105
- return this.wrappedProvider('patch', [params, ...restOfArgs]);
106
- }
107
-
108
- update(params, ...restOfArgs) {
109
- if (typeof params === 'object' && params.id) {
110
- params.id = utils.maybeDecode(`${params.id}`);
111
- }
112
- return this.wrappedProvider('update', [params, ...restOfArgs]);
113
- }
114
-
115
- delete(params, ...restOfArgs) {
116
- if (typeof params === 'object' && params.id) {
117
- params.id = utils.maybeDecode(`${params.id}`);
118
- }
119
- return this.wrappedProvider('delete', [params, ...restOfArgs]);
120
- }
121
- }
122
-
123
- module.exports = Auth0RestClient;
@@ -1,105 +0,0 @@
1
- const retry = require('retry');
2
- const { ArgumentError } = require('rest-facade');
3
-
4
- const DEFAULT_OPTIONS = {
5
- maxRetries: 3,
6
- enabled: true,
7
- randomize: true,
8
- };
9
-
10
- /**
11
- * Wrapper Rest Client that adds Retry functionality when requests are failing due to rate limiting (status code 429).
12
- */
13
- class RetryRestClient {
14
- /**
15
- * @param {object} restClient RestClient.
16
- * @param {object} [options] Options for the RetryRestClient. It includes all properties from https://github.com/tim-kos/node-retry#retryoperationoptions
17
- * @param {object} [options.enabled=true] Enabled or Disable Retry Policy functionality.
18
- * @param {number} [options.maxRetries=3] The maximum amount of times to retry the operation.
19
- */
20
- constructor(restClient, options) {
21
- if (restClient === null || typeof restClient !== 'object') {
22
- throw new ArgumentError('Must provide RestClient');
23
- }
24
-
25
- const params = Object.assign({}, DEFAULT_OPTIONS, options);
26
-
27
- if (typeof params.enabled !== 'boolean') {
28
- throw new ArgumentError('Must provide enabled boolean value');
29
- }
30
-
31
- if (typeof params.maxRetries !== 'number' || params.maxRetries <= 0) {
32
- throw new ArgumentError('Must provide maxRetries as a positive number');
33
- }
34
-
35
- this.restClient = restClient;
36
- this.enabled = params.enabled;
37
- this.retryOptions = Object.assign({ retries: params.maxRetries }, params);
38
- }
39
-
40
- getAll(...args) {
41
- return this.invoke('getAll', args);
42
- }
43
-
44
- get(...args) {
45
- return this.invoke('get', args);
46
- }
47
-
48
- create(...args) {
49
- return this.invoke('create', args);
50
- }
51
-
52
- patch(...args) {
53
- return this.invoke('patch', args);
54
- }
55
-
56
- update(...args) {
57
- return this.invoke('update', args);
58
- }
59
-
60
- delete(...args) {
61
- return this.invoke('delete', args);
62
- }
63
-
64
- invoke(method, args) {
65
- let cb;
66
- if (args && args[args.length - 1] instanceof Function) {
67
- cb = args[args.length - 1];
68
- args.pop(); // Remove the callback
69
- }
70
-
71
- const promise = this.handleRetry(method, args);
72
-
73
- if (cb instanceof Function) {
74
- promise.then(cb.bind(null, null)).catch(cb);
75
- return;
76
- }
77
-
78
- return promise;
79
- }
80
-
81
- handleRetry(method, args) {
82
- if (!this.enabled) {
83
- return this.restClient[method](...args);
84
- }
85
-
86
- return new Promise((resolve, reject) => {
87
- const operation = retry.operation(this.retryOptions);
88
-
89
- operation.attempt(() => {
90
- this.restClient[method](...args)
91
- .then((body) => {
92
- resolve(body);
93
- })
94
- .catch((err) => {
95
- if (err && err.statusCode === 429 && operation.retry(err)) {
96
- return;
97
- }
98
- reject(err);
99
- });
100
- });
101
- });
102
- }
103
- }
104
-
105
- module.exports = RetryRestClient;
@@ -1,282 +0,0 @@
1
- const { ArgumentError } = require('rest-facade');
2
- const RestClient = require('rest-facade').Client;
3
-
4
- /**
5
- * Abstracts the sign-in, sign-up and change-password processes for Database &
6
- * Active Directory authentication services.
7
- */
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 {string} [options.proxy] Add the `superagent-proxy` dependency and specify a proxy url eg 'https://myproxy.com:1234'
14
- * @param {OAuthAuthenticator} oauth OAuthAuthenticator instance.
15
- */
16
- constructor(options, oauth) {
17
- if (!options) {
18
- throw new ArgumentError('Missing authenticator options');
19
- }
20
-
21
- if (typeof options !== 'object') {
22
- throw new ArgumentError('The authenticator options must be an object');
23
- }
24
-
25
- /**
26
- * Options object for the Rest Client instance.
27
- *
28
- * @type {object}
29
- */
30
- const clientOptions = {
31
- errorFormatter: { message: 'message', name: 'error' },
32
- headers: options.headers,
33
- proxy: options.proxy,
34
- };
35
-
36
- this.oauth = oauth;
37
- this.dbConnections = new RestClient(`${options.baseUrl}/dbconnections/:type`, clientOptions);
38
- this.clientId = options.clientId;
39
- }
40
-
41
- /**
42
- * Sign in using a database or active directory service.
43
- *
44
- * @example <caption>
45
- * Given the user credentials and the connection specified, it will do the
46
- * authentication on the provider and return a JSON with the `access_token`
47
- * and `id_token`. Find more information about the structure of the data
48
- * object in the <a href="https://auth0.com/docs/auth-api#!#post--oauth-ro">
49
- * API docs</a>.
50
- * </caption>
51
- *
52
- * var data = {
53
- * username: '{USERNAME}',
54
- * password: '{PASSWORD}',
55
- * connection: 'Username-Password-Authentication' // Optional field.
56
- * };
57
- *
58
- * auth0.database.signIn(data, function (err, userData) {
59
- * if (err) {
60
- * // Handle error.
61
- * }
62
- *
63
- * console.log(userData);
64
- * });
65
- * @param {object} userData User credentials object.
66
- * @param {string} userData.username Username.
67
- * @param {string} userData.password User password.
68
- * @param {string} userData.connection Identity provider in use.
69
- * @param {Function} [cb] Method callback.
70
- * @returns {Promise|undefined}
71
- */
72
- signIn(userData, cb) {
73
- if (!userData || typeof userData !== 'object') {
74
- throw new ArgumentError('Missing user data object');
75
- }
76
-
77
- const data = {
78
- connection: 'Username-Password-Authentication',
79
- ...userData,
80
- };
81
-
82
- if (typeof data.username !== 'string' || data.username.trim().length === 0) {
83
- throw new ArgumentError('username field is required');
84
- }
85
-
86
- if (typeof data.password !== 'string' || data.password.trim().length === 0) {
87
- throw new ArgumentError('password field is required');
88
- }
89
-
90
- return this.oauth.signIn(data, cb);
91
- }
92
-
93
- /**
94
- * Sign up using a database or active directory service.
95
- *
96
- * @example <caption>
97
- * Given the user credentials, the connection specified and (optionally) the
98
- * client ID, it will create a new user. Find more information in the
99
- * <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-signup">
100
- * API Docs</a>.
101
- * </caption>
102
- *
103
- * var data = {
104
- * email: '{EMAIL}',
105
- * password: '{PASSWORD}',
106
- * connection: 'Username-Password-Authentication' // Optional field.
107
- * };
108
- *
109
- * auth0.database.signUp(data, function (err, userData) {
110
- * if (err) {
111
- * // Handle error.
112
- * }
113
- *
114
- * console.log(userData);
115
- * });
116
- * @param {object} userData User credentials object.
117
- * @param {string} userData.email User email address.
118
- * @param {string} userData.password User password.
119
- * @param {string} userData.connection Identity provider in use.
120
- * @param {Function} [cb] Method callback.
121
- * @returns {Promise|undefined}
122
- */
123
- signUp(userData, cb) {
124
- if (!userData || typeof userData !== 'object') {
125
- throw new ArgumentError('Missing user data object');
126
- }
127
-
128
- const data = {
129
- client_id: this.clientId,
130
- ...userData,
131
- };
132
-
133
- if (typeof data.email !== 'string' || data.email.trim().length === 0) {
134
- throw new ArgumentError('email field is required');
135
- }
136
-
137
- if (typeof data.password !== 'string' || data.password.trim().length === 0) {
138
- throw new ArgumentError('password field is required');
139
- }
140
-
141
- if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
142
- throw new ArgumentError('connection field is required');
143
- }
144
-
145
- const params = {
146
- type: 'signup',
147
- };
148
-
149
- if (cb && cb instanceof Function) {
150
- return this.dbConnections.create(params, data, cb);
151
- }
152
-
153
- return this.dbConnections.create(params, data);
154
- }
155
-
156
- /**
157
- * Change password using a database or active directory service.
158
- *
159
- * @example <caption>
160
- * Given the user email, the connection specified and the new password to
161
- * use, Auth0 will send a forgot password email. Once the user clicks on the
162
- * confirm password change link, the new password specified in this POST will
163
- * be set to this user. Find more information in the
164
- * <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password>
165
- * API Docs</a>.
166
- * </caption>
167
- *
168
- * var data = {
169
- * email: '{EMAIL}',
170
- * password: '{PASSWORD}',
171
- * connection: 'Username-Password-Authentication'
172
- * };
173
- *
174
- * auth0.database.changePassword(data, function (err, message) {
175
- * if (err) {
176
- * // Handle error.
177
- * }
178
- *
179
- * console.log(message);
180
- * });
181
- * @param {object} userData User credentials object.
182
- * @param {string} userData.email User email address.
183
- * @param {string} userData.password New password.
184
- * @param {string} userData.connection Identity provider in use.
185
- * @param {Function} [cb] Method callback.
186
- * @returns {Promise|undefined}
187
- */
188
- changePassword(userData, cb) {
189
- if (!userData || typeof userData !== 'object') {
190
- throw new ArgumentError('Missing user data object');
191
- }
192
-
193
- const data = {
194
- client_id: this.clientId,
195
- ...userData,
196
- };
197
-
198
- if (typeof data.email !== 'string' || data.email.trim().length === 0) {
199
- throw new ArgumentError('email field is required');
200
- }
201
-
202
- if (typeof data.password !== 'string' || data.password.trim().length === 0) {
203
- throw new ArgumentError('password field is required');
204
- }
205
-
206
- if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
207
- throw new ArgumentError('connection field is required');
208
- }
209
-
210
- const params = {
211
- type: 'change_password',
212
- };
213
-
214
- if (cb && cb instanceof Function) {
215
- return this.dbConnections.create(params, data, cb);
216
- }
217
-
218
- return this.dbConnections.create(params, data);
219
- }
220
-
221
- /**
222
- * Request a change password email using a database or active directory service.
223
- *
224
- * @example <caption>
225
- * Given the user email, the connection specified, Auth0 will send a change
226
- * password email. once the user clicks on the confirm password change link,
227
- * the new password specified in this POST will be set to this user. Find more
228
- * information in the <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-change_password>
229
- * API Docs</a>.
230
- * </caption>
231
- *
232
- * var data = {
233
- * email: '{EMAIL}',
234
- * connection: 'Username-Password-Authentication',
235
- * client_id: 'OS1VzKTVjizL0VCc9Hx2ae2aTPXWy6BD'
236
- * };
237
- *
238
- * auth0.database.requestChangePasswordEmail(data, function (err, message) {
239
- * if (err) {
240
- * // Handle error.
241
- * }
242
- *
243
- * console.log(message);
244
- * });
245
- * @param {object} userData User credentials object.
246
- * @param {string} userData.email User email address.
247
- * @param {string} userData.connection Identity provider in use.
248
- * @param {string} userData.client_id Client ID of the Application requesting the password change, to be included in the email template.
249
- * @param {Function} [cb] Method callback.
250
- * @returns {Promise|undefined}
251
- */
252
- requestChangePasswordEmail(userData, cb) {
253
- if (!userData || typeof userData !== 'object') {
254
- throw new ArgumentError('Missing user data object');
255
- }
256
-
257
- const data = {
258
- client_id: this.clientId,
259
- ...userData,
260
- };
261
-
262
- if (typeof data.email !== 'string' || data.email.trim().length === 0) {
263
- throw new ArgumentError('email field is required');
264
- }
265
-
266
- if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
267
- throw new ArgumentError('connection field is required');
268
- }
269
-
270
- const params = {
271
- type: 'change_password',
272
- };
273
-
274
- if (cb && cb instanceof Function) {
275
- return this.dbConnections.create(params, data, cb);
276
- }
277
-
278
- return this.dbConnections.create(params, data);
279
- }
280
- }
281
-
282
- module.exports = DatabaseAuthenticator;
@@ -1,124 +0,0 @@
1
- const jwt = require('jsonwebtoken');
2
- const jwksClient = require('jwks-rsa');
3
- const { ArgumentError } = require('rest-facade');
4
- const validateIdToken = require('./idToken').validate;
5
-
6
- const HS256_IGNORE_VALIDATION_MESSAGE =
7
- 'Validation of `id_token` requires a `clientSecret` when using the HS256 algorithm. To ensure tokens are validated, please switch the signing algorithm to RS256 or provide a `clientSecret` in the constructor.';
8
-
9
- /**
10
- * Abstracts the `oauth.create` method with additional id_token validation
11
- */
12
- class OAUthWithIDTokenValidation {
13
- /**
14
- * @param {object} oauth An instance of @type {OAuthAuthenticator}
15
- * @param {object} options Authenticator options.
16
- * @param {string} options.domain AuthenticationClient server domain
17
- * @param {string} [options.clientId] Default client ID.
18
- * @param {string} [options.clientSecret] Default client Secret.
19
- * @param {string} [options.supportedAlgorithms] Algorithms that your application expects to receive
20
- * @param {boolean} [options.__bypassIdTokenValidation] Whether the id_token should be validated or not
21
- */
22
- constructor(oauth, options) {
23
- if (!oauth) {
24
- throw new ArgumentError('Missing OAuthAuthenticator param');
25
- }
26
-
27
- if (!options) {
28
- throw new ArgumentError('Missing authenticator options');
29
- }
30
-
31
- if (typeof options !== 'object') {
32
- throw new ArgumentError('The authenticator options must be an object');
33
- }
34
-
35
- this.oauth = oauth;
36
- this.__bypassIdTokenValidation = options.__bypassIdTokenValidation;
37
- this.clientId = options.clientId;
38
- this.clientSecret = options.clientSecret;
39
- this.domain = options.domain;
40
- this.supportedAlgorithms = options.supportedAlgorithms || ['HS256', 'RS256'];
41
- this._jwksClient = jwksClient({
42
- jwksUri: `https://${options.domain}/.well-known/jwks.json`,
43
- });
44
- }
45
-
46
- /**
47
- * Creates an oauth request and validates the id_token (if any)
48
- *
49
- * @param {object} params OAuth parameters that are passed through
50
- * @param {object} data Custom parameters sent to the OAuth endpoint
51
- * @param {Function} [cb] Callback function
52
- * @returns {Promise|undefined}
53
- */
54
- create(params, data, cb) {
55
- const _this = this;
56
- function getKey(header, callback) {
57
- if (header.alg === 'HS256') {
58
- if (!_this.clientSecret) {
59
- return callback({ message: HS256_IGNORE_VALIDATION_MESSAGE });
60
- }
61
- return callback(null, Buffer.from(_this.clientSecret, 'base64'));
62
- }
63
- _this._jwksClient.getSigningKey(header.kid, (err, key) => {
64
- if (err) {
65
- return callback(err);
66
- }
67
- const signingKey = key.publicKey || key.rsaPublicKey;
68
- return callback(null, signingKey);
69
- });
70
- }
71
- const createAndValidate = this.oauth.create(params, data).then((r) => {
72
- if (_this.__bypassIdTokenValidation) {
73
- return r;
74
- }
75
-
76
- if (r.id_token) {
77
- return new Promise((resolve, reject) => {
78
- const options = {
79
- algorithms: this.supportedAlgorithms,
80
- audience: this.clientId,
81
- issuer: `https://${this.domain}/`,
82
- };
83
-
84
- if (data.organization) {
85
- options.organization = data.organization;
86
- }
87
-
88
- if (data.nonce) {
89
- options.nonce = data.nonce;
90
- }
91
-
92
- if (data.maxAge) {
93
- options.maxAge = data.maxAge;
94
- }
95
-
96
- jwt.verify(r.id_token, getKey, options, (err) => {
97
- if (err) {
98
- if (err.message && err.message.includes(HS256_IGNORE_VALIDATION_MESSAGE)) {
99
- console.warn(HS256_IGNORE_VALIDATION_MESSAGE);
100
- } else {
101
- return reject(err);
102
- }
103
- }
104
-
105
- try {
106
- validateIdToken(r.id_token, options);
107
- } catch (idTokenError) {
108
- return reject(idTokenError);
109
- }
110
-
111
- return resolve(r);
112
- });
113
- });
114
- }
115
- return r;
116
- });
117
- if (!cb) {
118
- return createAndValidate;
119
- }
120
- createAndValidate.then((r) => cb(null, r)).catch((e) => cb(e));
121
- }
122
- }
123
-
124
- module.exports = OAUthWithIDTokenValidation;