auth0 2.36.0 → 2.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +554 -0
  2. package/README.md +33 -11
  3. package/package.json +22 -15
  4. package/src/Auth0RestClient.js +72 -71
  5. package/src/RetryRestClient.js +78 -81
  6. package/src/auth/DatabaseAuthenticator.js +242 -259
  7. package/src/auth/OAUthWithIDTokenValidation.js +99 -103
  8. package/src/auth/OAuthAuthenticator.js +325 -344
  9. package/src/auth/PasswordlessAuthenticator.js +237 -252
  10. package/src/auth/TokensManager.js +231 -246
  11. package/src/auth/UsersManager.js +149 -160
  12. package/src/auth/idToken.js +22 -19
  13. package/src/auth/index.js +510 -581
  14. package/src/errors.js +23 -23
  15. package/src/index.js +3 -2
  16. package/src/management/ActionsManager.js +503 -585
  17. package/src/management/BlacklistedTokensManager.js +77 -84
  18. package/src/management/BrandingManager.js +141 -163
  19. package/src/management/ClientGrantsManager.js +132 -145
  20. package/src/management/ClientsManager.js +145 -161
  21. package/src/management/ConnectionsManager.js +215 -204
  22. package/src/management/CustomDomainsManager.js +140 -157
  23. package/src/management/DeviceCredentialsManager.js +95 -111
  24. package/src/management/EmailProviderManager.js +110 -128
  25. package/src/management/EmailTemplatesManager.js +96 -112
  26. package/src/management/GrantsManager.js +94 -101
  27. package/src/management/GuardianManager.js +381 -455
  28. package/src/management/HooksManager.js +283 -325
  29. package/src/management/JobsManager.js +310 -343
  30. package/src/management/LogStreamsManager.js +142 -158
  31. package/src/management/LogsManager.js +92 -99
  32. package/src/management/ManagementTokenProvider.js +112 -120
  33. package/src/management/MigrationsManager.js +81 -90
  34. package/src/management/OrganizationsManager.js +686 -761
  35. package/src/management/PromptsManager.js +160 -178
  36. package/src/management/ResourceServersManager.js +143 -160
  37. package/src/management/RolesManager.js +323 -369
  38. package/src/management/RulesConfigsManager.js +94 -110
  39. package/src/management/RulesManager.js +154 -176
  40. package/src/management/StatsManager.js +87 -103
  41. package/src/management/TenantManager.js +81 -97
  42. package/src/management/TicketsManager.js +107 -115
  43. package/src/management/UserBlocksManager.js +135 -162
  44. package/src/management/UsersManager.js +729 -852
  45. package/src/management/index.js +3094 -3619
  46. package/src/utils.js +31 -60
@@ -1,143 +1,135 @@
1
- var ArgumentError = require('rest-facade').ArgumentError;
2
- var AuthenticationClient = require('../auth');
3
- var memoizer = require('lru-memoizer');
4
- var es6Promisify = require('es6-promisify');
5
-
6
- var DEFAULT_OPTIONS = { enableCache: true };
1
+ const { ArgumentError } = require('rest-facade');
2
+ const AuthenticationClient = require('../auth');
3
+ const memoizer = require('lru-memoizer');
4
+ const util = require('util');
7
5
 
8
6
  /**
9
- * @class ManagementTokenProvider
10
7
  * Auth0 Management API Token Provider.
11
- * @constructor
12
- * @memberOf module:management
13
- *
14
- * @param {Object} options Options for the ManagementTokenProvider.
15
- * @param {String} options.domain ManagementClient server domain.
16
- * @param {String} options.clientId Non Interactive Client Id.
17
- * @param {String} options.clientSecret Non Interactive Client Secret.
18
- * @param {String} options.scope Non Interactive Client Scope.
19
- * @param {String} options.audience Audience of the Management API.
20
- * @param {Boolean} [options.enableCache=true] Enabled or Disable Cache
21
- * @param {Number} [options.cacheTTLInSeconds] By default the `expires_in` value will be used to determine the cached time of the token, this can be overridden.
22
- * @param {Object} [options.headers] Additional headers that will be added to the outgoing requests.
23
- *
24
8
  */
25
- var ManagementTokenProvider = function(options) {
26
- if (!options || typeof options !== 'object') {
27
- throw new ArgumentError('Options must be an object');
28
- }
9
+ class ManagementTokenProvider {
10
+ /**
11
+ * @param {object} options Options for the ManagementTokenProvider.
12
+ * @param {string} options.domain ManagementClient server domain.
13
+ * @param {string} options.clientId Non Interactive Client Id.
14
+ * @param {string} options.clientSecret Non Interactive Client Secret.
15
+ * @param {string} options.scope Non Interactive Client Scope.
16
+ * @param {string} options.audience Audience of the Management API.
17
+ * @param {boolean} [options.enableCache=true] Enabled or Disable Cache
18
+ * @param {number} [options.cacheTTLInSeconds] By default the `expires_in` value will be used to determine the cached time of the token, this can be overridden.
19
+ * @param {object} [options.headers] Additional headers that will be added to the outgoing requests.
20
+ */
21
+ constructor(options) {
22
+ if (!options || typeof options !== 'object') {
23
+ throw new ArgumentError('Options must be an object');
24
+ }
29
25
 
30
- var params = Object.assign({}, DEFAULT_OPTIONS, options);
26
+ const params = { enableCache: true, ...options };
31
27
 
32
- if (!params.domain || params.domain.length === 0) {
33
- throw new ArgumentError('Must provide a domain');
34
- }
28
+ if (!params.domain || params.domain.length === 0) {
29
+ throw new ArgumentError('Must provide a domain');
30
+ }
35
31
 
36
- if (!params.clientId || params.clientId.length === 0) {
37
- throw new ArgumentError('Must provide a clientId');
38
- }
32
+ if (!params.clientId || params.clientId.length === 0) {
33
+ throw new ArgumentError('Must provide a clientId');
34
+ }
39
35
 
40
- if (!params.clientSecret || params.clientSecret.length === 0) {
41
- throw new ArgumentError('Must provide a clientSecret');
42
- }
36
+ if (!params.clientSecret || params.clientSecret.length === 0) {
37
+ throw new ArgumentError('Must provide a clientSecret');
38
+ }
43
39
 
44
- if (!params.audience || params.audience.length === 0) {
45
- throw new ArgumentError('Must provide a audience');
46
- }
40
+ if (!params.audience || params.audience.length === 0) {
41
+ throw new ArgumentError('Must provide a audience');
42
+ }
47
43
 
48
- if (typeof params.enableCache !== 'boolean') {
49
- throw new ArgumentError('enableCache must be a boolean');
50
- }
44
+ if (typeof params.enableCache !== 'boolean') {
45
+ throw new ArgumentError('enableCache must be a boolean');
46
+ }
47
+
48
+ if (params.enableCache && params.cacheTTLInSeconds) {
49
+ if (typeof params.cacheTTLInSeconds !== 'number') {
50
+ throw new ArgumentError('cacheTTLInSeconds must be a number');
51
+ }
51
52
 
52
- if (params.enableCache && params.cacheTTLInSeconds) {
53
- if (typeof params.cacheTTLInSeconds !== 'number') {
54
- throw new ArgumentError('cacheTTLInSeconds must be a number');
53
+ if (params.cacheTTLInSeconds <= 0) {
54
+ throw new ArgumentError('cacheTTLInSeconds must be a greater than 0');
55
+ }
55
56
  }
56
57
 
57
- if (params.cacheTTLInSeconds <= 0) {
58
- throw new ArgumentError('cacheTTLInSeconds must be a greater than 0');
58
+ if (params.scope && typeof params.scope !== 'string') {
59
+ throw new ArgumentError('scope must be a string');
59
60
  }
60
- }
61
61
 
62
- if (params.scope && typeof params.scope !== 'string') {
63
- throw new ArgumentError('scope must be a string');
62
+ this.options = params;
63
+ const authenticationClientOptions = {
64
+ domain: this.options.domain,
65
+ clientId: this.options.clientId,
66
+ clientSecret: this.options.clientSecret,
67
+ telemetry: this.options.telemetry,
68
+ clientInfo: this.options.clientInfo,
69
+ headers: this.options.headers,
70
+ };
71
+ this.authenticationClient = new AuthenticationClient(authenticationClientOptions);
72
+
73
+ const self = this;
74
+ this.getCachedAccessToken = util.promisify(
75
+ memoizer({
76
+ load(options, callback) {
77
+ self
78
+ .clientCredentialsGrant(options.domain, options.scope, options.audience)
79
+ .then((data) => {
80
+ callback(null, data);
81
+ })
82
+ .catch((err) => {
83
+ callback(err);
84
+ });
85
+ },
86
+ hash(options) {
87
+ return `${options.domain}-${options.clientId}-${options.scope}`;
88
+ },
89
+ itemMaxAge(options, data) {
90
+ if (options.cacheTTLInSeconds) {
91
+ return options.cacheTTLInSeconds * 1000;
92
+ }
93
+
94
+ // if the expires_in is lower or equal to than 10 seconds, do not subtract 10 additional seconds.
95
+ if (data.expires_in && data.expires_in <= 10 /* seconds */) {
96
+ return data.expires_in * 1000;
97
+ } else if (data.expires_in) {
98
+ // Subtract 10 seconds from expires_in to fetch a new one, before it expires.
99
+ return data.expires_in * 1000 - 10000 /* milliseconds */;
100
+ }
101
+ return 60 * 60 * 1000; //1h
102
+ },
103
+ max: 100,
104
+ })
105
+ );
64
106
  }
65
107
 
66
- this.options = params;
67
- var authenticationClientOptions = {
68
- domain: this.options.domain,
69
- clientId: this.options.clientId,
70
- clientSecret: this.options.clientSecret,
71
- telemetry: this.options.telemetry,
72
- clientInfo: this.options.clientInfo,
73
- headers: this.options.headers
74
- };
75
- this.authenticationClient = new AuthenticationClient(authenticationClientOptions);
76
-
77
- var self = this;
78
- this.getCachedAccessToken = es6Promisify.promisify(
79
- memoizer({
80
- load: function(options, callback) {
81
- self
82
- .clientCredentialsGrant(options.domain, options.scope, options.audience)
83
- .then(function(data) {
84
- callback(null, data);
85
- })
86
- .catch(function(err) {
87
- callback(err);
88
- });
89
- },
90
- hash: function(options) {
91
- return options.domain + '-' + options.clientId + '-' + options.scope;
92
- },
93
- itemMaxAge: function(options, data) {
94
- if (options.cacheTTLInSeconds) {
95
- return options.cacheTTLInSeconds * 1000;
96
- }
97
-
98
- // if the expires_in is lower or equal to than 10 seconds, do not subtract 10 additional seconds.
99
- if (data.expires_in && data.expires_in <= 10 /* seconds */) {
100
- return data.expires_in * 1000;
101
- } else if (data.expires_in) {
102
- // Subtract 10 seconds from expires_in to fetch a new one, before it expires.
103
- return data.expires_in * 1000 - 10000 /* milliseconds */;
104
- }
105
- return 60 * 60 * 1000; //1h
106
- },
107
- max: 100
108
- })
109
- );
110
- };
111
-
112
- /**
113
- * Returns the access_token.
114
- *
115
- * @method getAccessToken
116
- * @memberOf module:management.ManagementTokenProvider.prototype
117
- *
118
- * @return {Promise} Promise returning an access_token.
119
- */
120
- ManagementTokenProvider.prototype.getAccessToken = function() {
121
- if (this.options.enableCache) {
122
- return this.getCachedAccessToken(this.options).then(function(data) {
108
+ /**
109
+ * Returns the access_token.
110
+ *
111
+ * @returns {Promise} Promise returning an access_token.
112
+ */
113
+ async getAccessToken() {
114
+ if (this.options.enableCache) {
115
+ const data = await this.getCachedAccessToken(this.options);
123
116
  return data.access_token;
124
- });
125
- } else {
126
- return this.clientCredentialsGrant(
127
- this.options.domain,
128
- this.options.scope,
129
- this.options.audience
130
- ).then(function(data) {
117
+ } else {
118
+ const data = await this.clientCredentialsGrant(
119
+ this.options.domain,
120
+ this.options.scope,
121
+ this.options.audience
122
+ );
131
123
  return data.access_token;
124
+ }
125
+ }
126
+
127
+ clientCredentialsGrant(domain, scope, audience) {
128
+ return this.authenticationClient.clientCredentialsGrant({
129
+ audience,
130
+ scope,
132
131
  });
133
132
  }
134
- };
135
-
136
- ManagementTokenProvider.prototype.clientCredentialsGrant = function(domain, scope, audience) {
137
- return this.authenticationClient.clientCredentialsGrant({
138
- audience: audience,
139
- scope: scope
140
- });
141
- };
133
+ }
142
134
 
143
135
  module.exports = ManagementTokenProvider;
@@ -1,108 +1,99 @@
1
- var ArgumentError = require('rest-facade').ArgumentError;
2
- var Auth0RestClient = require('../Auth0RestClient');
3
- var RetryRestClient = require('../RetryRestClient');
1
+ const { ArgumentError } = require('rest-facade');
2
+ const Auth0RestClient = require('../Auth0RestClient');
3
+ const RetryRestClient = require('../RetryRestClient');
4
4
 
5
5
  /**
6
- * @class
7
6
  * Abstracts interaction with the migrations endpoint.
8
- * @constructor
9
- * @memberOf module:management
10
- *
11
- * @param {Object} options The client options.
12
- * @param {String} options.baseUrl The URL of the API.
13
- * @param {Object} [options.headers] Headers to be included in all requests.
14
- * @param {Object} [options.retry] Retry Policy Config
15
7
  */
16
- var MigrationsManager = function(options) {
17
- if (options === null || typeof options !== 'object') {
18
- throw new ArgumentError('Must provide manager options');
19
- }
8
+ class MigrationsManager {
9
+ /**
10
+ * @param {object} options The client options.
11
+ * @param {string} options.baseUrl The URL of the API.
12
+ * @param {object} [options.headers] Headers to be included in all requests.
13
+ * @param {object} [options.retry] Retry Policy Config
14
+ */
15
+ constructor(options) {
16
+ if (options === null || typeof options !== 'object') {
17
+ throw new ArgumentError('Must provide manager options');
18
+ }
20
19
 
21
- if (options.baseUrl === null || options.baseUrl === undefined) {
22
- throw new ArgumentError('Must provide a base URL for the API');
23
- }
20
+ if (options.baseUrl === null || options.baseUrl === undefined) {
21
+ throw new ArgumentError('Must provide a base URL for the API');
22
+ }
24
23
 
25
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
26
- throw new ArgumentError('The provided base URL is invalid');
27
- }
24
+ if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
25
+ throw new ArgumentError('The provided base URL is invalid');
26
+ }
28
27
 
29
- var clientOptions = {
30
- errorFormatter: { message: 'message', name: 'error' },
31
- headers: options.headers,
32
- query: { repeatParams: false }
33
- };
28
+ const clientOptions = {
29
+ errorFormatter: { message: 'message', name: 'error' },
30
+ headers: options.headers,
31
+ query: { repeatParams: false },
32
+ };
33
+
34
+ /**
35
+ * Provides an abstraction layer for consuming the migrations endpoint
36
+ *
37
+ * @type {external:RestClient}
38
+ */
39
+ const auth0RestClient = new Auth0RestClient(
40
+ `${options.baseUrl}/migrations`,
41
+ clientOptions,
42
+ options.tokenProvider
43
+ );
44
+ this.resource = new RetryRestClient(auth0RestClient, options.retry);
45
+ }
34
46
 
35
47
  /**
36
- * Provides an abstraction layer for consuming the migrations endpoint
48
+ * Update the tenant migrations.
37
49
  *
38
- * @type {external:RestClient}
50
+ * @example
51
+ * management.migrations.updateMigrations(data, function (err) {
52
+ * if (err) {
53
+ * // Handle error.
54
+ * }
55
+ * });
56
+ * @param {object} data The tenant migrations to be updated
57
+ * @param {object} data.flags The tenant migrations flags to be updated
58
+ * @param {Function} [cb] Callback function.
59
+ * @returns {Promise|undefined}
39
60
  */
40
- var auth0RestClient = new Auth0RestClient(
41
- options.baseUrl + '/migrations',
42
- clientOptions,
43
- options.tokenProvider
44
- );
45
- this.resource = new RetryRestClient(auth0RestClient, options.retry);
46
- };
61
+ updateMigrations(data, cb) {
62
+ if (cb && cb instanceof Function) {
63
+ return this.resource.patch({}, data, cb);
64
+ }
47
65
 
48
- /**
49
- * Update the tenant migrations.
50
- *
51
- * @method updateMigrations
52
- * @memberOf module:management.MigrationsManager.prototype
53
- *
54
- * @example
55
- * management.migrations.updateMigrations(data, function (err) {
56
- * if (err) {
57
- * // Handle error.
58
- * }
59
- * });
60
- *
61
- * @param {Object} data The tenant migrations to be updated
62
- * @param {Object} data.flags The tenant migrations flags to be updated
63
- * @param {Function} [cb] Callback function.
64
- *
65
- * @return {Promise|undefined}
66
- */
67
- MigrationsManager.prototype.updateMigrations = function(data, cb) {
68
- if (cb && cb instanceof Function) {
69
- return this.resource.patch({}, data, cb);
66
+ // Return a promise.
67
+ return this.resource.patch({}, data);
70
68
  }
71
69
 
72
- // Return a promise.
73
- return this.resource.patch({}, data);
74
- };
70
+ /**
71
+ * Get the tenant migrations.
72
+ *
73
+ * @example
74
+ * management.migrations.getMigrations(function (err, migrations) {
75
+ * if (err) {
76
+ * // Handle error.
77
+ * }
78
+ *
79
+ * console.log(migrations.flags);
80
+ * });
81
+ * @param data
82
+ * @param {Function} [cb] Callback function.
83
+ * @returns {Promise|undefined}
84
+ */
85
+ getMigrations(data, cb) {
86
+ if (data instanceof Function && !cb) {
87
+ cb = data;
88
+ data = {};
89
+ }
90
+ if (cb && cb instanceof Function) {
91
+ return this.resource.get(data, cb);
92
+ }
75
93
 
76
- /**
77
- * Get the tenant migrations.
78
- *
79
- * @method getMigrations
80
- * @memberOf module:management.MigrationsManager.prototype
81
- *
82
- * @example
83
- * management.migrations.getMigrations(function (err, migrations) {
84
- * if (err) {
85
- * // Handle error.
86
- * }
87
- *
88
- * console.log(migrations.flags);
89
- * });
90
- *
91
- * @param {Function} [cb] Callback function.
92
- *
93
- * @return {Promise|undefined}
94
- */
95
- MigrationsManager.prototype.getMigrations = function(data, cb) {
96
- if (data instanceof Function && !cb) {
97
- cb = data;
98
- data = {};
94
+ // Return a promise.
95
+ return this.resource.get(data);
99
96
  }
100
- if (cb && cb instanceof Function) {
101
- return this.resource.get(data, cb);
102
- }
103
-
104
- // Return a promise.
105
- return this.resource.get(data);
106
- };
97
+ }
107
98
 
108
99
  module.exports = MigrationsManager;