auth0 2.37.0 → 2.40.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 (47) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +33 -11
  3. package/package.json +22 -14
  4. package/src/Auth0RestClient.js +72 -71
  5. package/src/RetryRestClient.js +78 -81
  6. package/src/auth/DatabaseAuthenticator.js +242 -259
  7. package/src/auth/OAUthWithIDTokenValidation.js +99 -103
  8. package/src/auth/OAuthAuthenticator.js +325 -344
  9. package/src/auth/PasswordlessAuthenticator.js +238 -252
  10. package/src/auth/TokensManager.js +231 -246
  11. package/src/auth/UsersManager.js +149 -160
  12. package/src/auth/idToken.js +22 -19
  13. package/src/auth/index.js +510 -583
  14. package/src/errors.js +23 -23
  15. package/src/index.js +3 -2
  16. package/src/management/ActionsManager.js +510 -584
  17. package/src/management/AttackProtectionManager.js +187 -0
  18. package/src/management/BlacklistedTokensManager.js +77 -84
  19. package/src/management/BrandingManager.js +141 -163
  20. package/src/management/ClientGrantsManager.js +132 -145
  21. package/src/management/ClientsManager.js +145 -161
  22. package/src/management/ConnectionsManager.js +215 -239
  23. package/src/management/CustomDomainsManager.js +140 -157
  24. package/src/management/DeviceCredentialsManager.js +95 -111
  25. package/src/management/EmailProviderManager.js +110 -128
  26. package/src/management/EmailTemplatesManager.js +96 -112
  27. package/src/management/GrantsManager.js +94 -101
  28. package/src/management/GuardianManager.js +381 -455
  29. package/src/management/HooksManager.js +283 -325
  30. package/src/management/JobsManager.js +310 -343
  31. package/src/management/LogStreamsManager.js +142 -158
  32. package/src/management/LogsManager.js +92 -99
  33. package/src/management/ManagementTokenProvider.js +112 -120
  34. package/src/management/MigrationsManager.js +81 -90
  35. package/src/management/OrganizationsManager.js +686 -784
  36. package/src/management/PromptsManager.js +160 -182
  37. package/src/management/ResourceServersManager.js +143 -160
  38. package/src/management/RolesManager.js +323 -369
  39. package/src/management/RulesConfigsManager.js +94 -110
  40. package/src/management/RulesManager.js +154 -176
  41. package/src/management/StatsManager.js +87 -103
  42. package/src/management/TenantManager.js +81 -97
  43. package/src/management/TicketsManager.js +107 -115
  44. package/src/management/UserBlocksManager.js +135 -162
  45. package/src/management/UsersManager.js +729 -852
  46. package/src/management/index.js +3102 -3625
  47. package/src/utils.js +31 -60
@@ -1,183 +1,161 @@
1
- var ArgumentError = require('rest-facade').ArgumentError;
2
- var utils = require('../utils');
3
- var Auth0RestClient = require('../Auth0RestClient');
4
- var RetryRestClient = require('../RetryRestClient');
1
+ const { ArgumentError } = require('rest-facade');
2
+ const Auth0RestClient = require('../Auth0RestClient');
3
+ const RetryRestClient = require('../RetryRestClient');
5
4
 
6
5
  /**
7
- * Simple facade for consuming a REST API endpoint.
8
- * @external RestClient
9
- * @see https://github.com/ngonzalvez/rest-facade
10
- */
11
-
12
- /**
13
- * @class BrandingManager
14
6
  * Manages settings related to branding.
15
- * @constructor
16
- * @memberOf module:management
17
- *
18
- * @param {Object} options The client options.
19
- * @param {String} options.baseUrl The URL of the API.
20
- * @param {Object} [options.headers] Headers to be included in all requests.
21
- * @param {Object} [options.retry] Retry Policy Config
22
7
  */
23
- var BrandingManager = function(options) {
24
- if (options === null || typeof options !== 'object') {
25
- throw new ArgumentError('Must provide manager options');
26
- }
8
+ class BrandingManager {
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
+ }
27
19
 
28
- if (options.baseUrl === null || options.baseUrl === undefined) {
29
- throw new ArgumentError('Must provide a base URL for the API');
30
- }
20
+ if (options.baseUrl === null || options.baseUrl === undefined) {
21
+ throw new ArgumentError('Must provide a base URL for the API');
22
+ }
31
23
 
32
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
33
- throw new ArgumentError('The provided base URL is invalid');
34
- }
24
+ if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
25
+ throw new ArgumentError('The provided base URL is invalid');
26
+ }
27
+
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
36
+ * {@link https://auth0.com/docs/api/management/v2#!/Branding Branding endpoint}.
37
+ *
38
+ * @type {external:RestClient}
39
+ */
40
+ const auth0RestClient = new Auth0RestClient(
41
+ `${options.baseUrl}/branding`,
42
+ clientOptions,
43
+ options.tokenProvider
44
+ );
45
+ this.resource = new RetryRestClient(auth0RestClient, options.retry);
35
46
 
36
- var clientOptions = {
37
- errorFormatter: { message: 'message', name: 'error' },
38
- headers: options.headers,
39
- query: { repeatParams: false }
40
- };
47
+ /**
48
+ * Provides an abstraction layer for consuming the
49
+ * {@link https://auth0.com/docs/api/management/v2#!/Branding/get_universal_login Branding new universal login template endpoint}.
50
+ *
51
+ * @type {external:RestClient}
52
+ */
53
+ const brandingTemplateAuth0RestClient = new Auth0RestClient(
54
+ `${options.baseUrl}/branding/templates/universal-login`,
55
+ clientOptions,
56
+ options.tokenProvider
57
+ );
58
+ this.brandingTemplates = new RetryRestClient(brandingTemplateAuth0RestClient, options.retry);
59
+ }
41
60
 
42
61
  /**
43
- * Provides an abstraction layer for consuming the
44
- * {@link https://auth0.com/docs/api/management/v2#!/Branding Branding endpoint}.
62
+ * Update the branding settings.
63
+ *
64
+ * @example
65
+ * management.branding.updateSettings(params, data, function (err, branding) {
66
+ * if (err) {
67
+ * // Handle error.
68
+ * }
45
69
  *
46
- * @type {external:RestClient}
70
+ * // Updated branding
71
+ * console.log(branding);
72
+ * });
73
+ * @param {object} params Branding parameters (leavy empty).
74
+ * @param {object} data Updated branding data.
75
+ * @param {Function} [cb] Callback function.
76
+ * @returns {Promise|undefined}
47
77
  */
48
- var auth0RestClient = new Auth0RestClient(
49
- options.baseUrl + '/branding',
50
- clientOptions,
51
- options.tokenProvider
52
- );
53
- this.resource = new RetryRestClient(auth0RestClient, options.retry);
78
+ updateSettings(...args) {
79
+ return this.resource.patch(...args);
80
+ }
54
81
 
55
82
  /**
56
- * Provides an abstraction layer for consuming the
57
- * {@link https://auth0.com/docs/api/management/v2#!/Branding/get_universal_login Branding new universal login template endpoint}.
83
+ * Get the branding settings..
58
84
  *
59
- * @type {external:RestClient}
85
+ * @example
86
+ * management.branding.getSettings(data, function (err, branding) {
87
+ * if (err) {
88
+ * // Handle error.
89
+ * }
90
+ *
91
+ * // Branding
92
+ * console.log(branding);
93
+ * });
94
+ * @param {object} params Branding parameters.
95
+ * @param {object} data Branding data.
96
+ * @param {Function} [cb] Callback function.
97
+ * @returns {Promise|undefined}
60
98
  */
61
- var brandingTemplateAuth0RestClient = new Auth0RestClient(
62
- options.baseUrl + '/branding/templates/universal-login',
63
- clientOptions,
64
- options.tokenProvider
65
- );
66
- this.brandingTemplates = new RetryRestClient(brandingTemplateAuth0RestClient, options.retry);
67
- };
68
-
69
- /**
70
- * Update the branding settings.
71
- *
72
- * @method updateSettings
73
- * @memberOf module:management.BrandingManager.prototype
74
- *
75
- * @example
76
- * management.branding.updateSettings(params, data, function (err, branding) {
77
- * if (err) {
78
- * // Handle error.
79
- * }
80
- *
81
- * // Updated branding
82
- * console.log(branding);
83
- * });
84
- *
85
- * @param {Object} params Branding parameters (leavy empty).
86
- * @param {Object} data Updated branding data.
87
- * @param {Function} [cb] Callback function.
88
- *
89
- * @return {Promise|undefined}
90
- */
91
- utils.wrapPropertyMethod(BrandingManager, 'updateSettings', 'resource.patch');
92
-
93
- /**
94
- * Get the branding settings..
95
- *
96
- * @method getSettings
97
- * @memberOf module:management.BrandingManager.prototype
98
- *
99
- * @example
100
- * management.branding.getSettings(data, function (err, branding) {
101
- * if (err) {
102
- * // Handle error.
103
- * }
104
- *
105
- * // Branding
106
- * console.log(branding);
107
- * });
108
- *
109
- * @param {Object} params Branding parameters.
110
- * @param {Object} data Branding data.
111
- * @param {Function} [cb] Callback function.
112
- *
113
- * @return {Promise|undefined}
114
- */
115
- utils.wrapPropertyMethod(BrandingManager, 'getSettings', 'resource.get');
99
+ getSettings(...args) {
100
+ return this.resource.get(...args);
101
+ }
116
102
 
117
- /**
118
- * Get the new universal login template.
119
- *
120
- * @method getUniversalLoginTemplate
121
- * @memberOf module:management.BrandingManager.prototype
122
- *
123
- * @example
124
- * management.branding.getUniversalLoginTemplate(data, function (err, template) {
125
- * if (err) {
126
- * // Handle error.
127
- * }
128
- *
129
- * // Branding
130
- * console.log(template);
131
- * });
132
- *
133
- * @param {Object} params Branding parameters (leave empty).
134
- * @param {Object} data Branding data (leave empty).
135
- * @param {Function} [cb] Callback function.
136
- *
137
- * @return {Promise|undefined}
138
- */
139
- utils.wrapPropertyMethod(BrandingManager, 'getUniversalLoginTemplate', 'brandingTemplates.get');
103
+ /**
104
+ * Get the new universal login template.
105
+ *
106
+ * @example
107
+ * management.branding.getUniversalLoginTemplate(data, function (err, template) {
108
+ * if (err) {
109
+ * // Handle error.
110
+ * }
111
+ *
112
+ * // Branding
113
+ * console.log(template);
114
+ * });
115
+ * @param {object} params Branding parameters (leave empty).
116
+ * @param {object} data Branding data (leave empty).
117
+ * @param {Function} [cb] Callback function.
118
+ * @returns {Promise|undefined}
119
+ */
120
+ getUniversalLoginTemplate(...args) {
121
+ return this.brandingTemplates.get(...args);
122
+ }
140
123
 
141
- /**
142
- * Set the new universal login template.
143
- *
144
- * @method setUniversalLoginTemplate
145
- * @memberOf module:management.BrandingManager.prototype
146
- *
147
- * @example
148
- * management.branding.setUniversalLoginTemplate(params, data, function (err) {
149
- * if (err) {
150
- * // Handle error.
151
- * }
152
- * });
153
- *
154
- * @param {Object} params Branding parameters (leavy empty).
155
- * @param {Object} data Branding data (object with template field).
156
- * @param {Function} [cb] Callback function.
157
- *
158
- * @return {Promise|undefined}
159
- */
160
- utils.wrapPropertyMethod(BrandingManager, 'setUniversalLoginTemplate', 'brandingTemplates.update');
124
+ /**
125
+ * Set the new universal login template.
126
+ *
127
+ * @example
128
+ * management.branding.setUniversalLoginTemplate(params, data, function (err) {
129
+ * if (err) {
130
+ * // Handle error.
131
+ * }
132
+ * });
133
+ * @param {object} params Branding parameters (leavy empty).
134
+ * @param {object} data Branding data (object with template field).
135
+ * @param {Function} [cb] Callback function.
136
+ * @returns {Promise|undefined}
137
+ */
138
+ setUniversalLoginTemplate(...args) {
139
+ return this.brandingTemplates.update(...args);
140
+ }
161
141
 
162
- /**
163
- * Delete the new universal login template (revert to default).
164
- *
165
- * @method deleteUniversalLoginTemplate
166
- * @memberOf module:management.BrandingManager.prototype
167
- *
168
- * @example
169
- * management.branding.deleteUniversalLoginTemplate(data, function (err) {
170
- * if (err) {
171
- * // Handle error.
172
- * }
173
- * });
174
- *
175
- * @param {Object} params Branding parameters (leavy empty).
176
- * @param {Object} data Branding data (leave empty).
177
- * @param {Function} [cb] Callback function.
178
- *
179
- * @return {Promise|undefined}
180
- */
181
- utils.wrapPropertyMethod(BrandingManager, 'deleteUniversalLoginTemplate', 'brandingTemplates.delete');
142
+ /**
143
+ * Delete the new universal login template (revert to default).
144
+ *
145
+ * @example
146
+ * management.branding.deleteUniversalLoginTemplate(data, function (err) {
147
+ * if (err) {
148
+ * // Handle error.
149
+ * }
150
+ * });
151
+ * @param {object} params Branding parameters (leavy empty).
152
+ * @param {object} data Branding data (leave empty).
153
+ * @param {Function} [cb] Callback function.
154
+ * @returns {Promise|undefined}
155
+ */
156
+ deleteUniversalLoginTemplate(...args) {
157
+ return this.brandingTemplates.delete(...args);
158
+ }
159
+ }
182
160
 
183
161
  module.exports = BrandingManager;
@@ -1,165 +1,152 @@
1
- var ArgumentError = require('rest-facade').ArgumentError;
2
- var utils = require('../utils');
3
- var Auth0RestClient = require('../Auth0RestClient');
4
- var RetryRestClient = require('../RetryRestClient');
1
+ const { ArgumentError } = require('rest-facade');
2
+ const Auth0RestClient = require('../Auth0RestClient');
3
+ const RetryRestClient = require('../RetryRestClient');
4
+
5
5
  /**
6
- * @class ClientGrantsManager
7
6
  * Auth0 Client Grants Manager.
8
7
  *
9
8
  * See {@link https://auth0.com/docs/api/v2#!/Client_Grants Client Grants}
10
- *
11
- * @constructor
12
- * @memberOf module:management
13
- *
14
- * @param {Object} options The client options.
15
- * @param {String} options.baseUrl The URL of the API.
16
- * @param {Object} [options.headers] Headers to be included in all requests.
17
- * @param {Object} [options.retry] Retry Policy Config
18
9
  */
19
- var ClientGrantsManager = function(options) {
20
- if (options === null || typeof options !== 'object') {
21
- throw new ArgumentError('Must provide client options');
22
- }
10
+ class ClientGrantsManager {
11
+ /**
12
+ * @param {object} options The client options.
13
+ * @param {string} options.baseUrl The URL of the API.
14
+ * @param {object} [options.headers] Headers to be included in all requests.
15
+ * @param {object} [options.retry] Retry Policy Config
16
+ */
17
+ constructor(options) {
18
+ if (options === null || typeof options !== 'object') {
19
+ throw new ArgumentError('Must provide client options');
20
+ }
23
21
 
24
- if (options.baseUrl === null || options.baseUrl === undefined) {
25
- throw new ArgumentError('Must provide a base URL for the API');
26
- }
22
+ if (options.baseUrl === null || options.baseUrl === undefined) {
23
+ throw new ArgumentError('Must provide a base URL for the API');
24
+ }
25
+
26
+ if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
27
+ throw new ArgumentError('The provided base URL is invalid');
28
+ }
27
29
 
28
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
29
- throw new ArgumentError('The provided base URL is invalid');
30
+ /**
31
+ * Options object for the Rest Client instance.
32
+ *
33
+ * @type {object}
34
+ */
35
+ const clientOptions = {
36
+ errorFormatter: { message: 'message', name: 'error' },
37
+ headers: options.headers,
38
+ query: { repeatParams: false },
39
+ };
40
+
41
+ /**
42
+ * Provides an abstraction layer for consuming the
43
+ * {@link https://auth0.com/docs/api/v2#!/Client_Grants Auth0 Client Grants endpoint}.
44
+ *
45
+ * @type {external:RestClient}
46
+ */
47
+ const auth0RestClient = new Auth0RestClient(
48
+ `${options.baseUrl}/client-grants/:id`,
49
+ clientOptions,
50
+ options.tokenProvider
51
+ );
52
+ this.resource = new RetryRestClient(auth0RestClient, options.retry);
30
53
  }
31
54
 
32
55
  /**
33
- * Options object for the Rest Client instance.
56
+ * Create an Auth0 client grant.
57
+ *
58
+ * @example
59
+ * management.clientGrants.create(data, function (err) {
60
+ * if (err) {
61
+ * // Handle error.
62
+ * }
34
63
  *
35
- * @type {Object}
64
+ * // Client grant created.
65
+ * });
66
+ * @param {object} data The client data object.
67
+ * @param {Function} [cb] Callback function.
68
+ * @returns {Promise|undefined}
36
69
  */
37
- var clientOptions = {
38
- errorFormatter: { message: 'message', name: 'error' },
39
- headers: options.headers,
40
- query: { repeatParams: false }
41
- };
70
+ create(...args) {
71
+ return this.resource.create(...args);
72
+ }
42
73
 
43
74
  /**
44
- * Provides an abstraction layer for consuming the
45
- * {@link https://auth0.com/docs/api/v2#!/Client_Grants Auth0 Client Grants endpoint}.
75
+ * Get all Auth0 Client Grants.
76
+ *
77
+ * @example <caption>
78
+ * This method takes an optional object as first argument that may be used to
79
+ * specify pagination settings. If pagination options are not present,
80
+ * the first page of a limited number of results will be returned.
81
+ * </caption>
46
82
  *
47
- * @type {external:RestClient}
83
+ * // Pagination settings.
84
+ * var params = {
85
+ * per_page: 10,
86
+ * page: 0
87
+ * };
88
+ *
89
+ *
90
+ * management.clientGrants.getAll(params, function (err, grants) {
91
+ * console.log(grants.length);
92
+ * });
93
+ * @param {object} [params] Client Grants parameters.
94
+ * @param {number} [params.per_page] Number of results per page.
95
+ * @param {number} [params.page] Page number, zero indexed.
96
+ * @param {Function} [cb] Callback function.
97
+ * @returns {Promise|undefined}
48
98
  */
49
- var auth0RestClient = new Auth0RestClient(
50
- options.baseUrl + '/client-grants/:id',
51
- clientOptions,
52
- options.tokenProvider
53
- );
54
- this.resource = new RetryRestClient(auth0RestClient, options.retry);
55
- };
56
-
57
- /**
58
- * Create an Auth0 client grant.
59
- *
60
- * @method create
61
- * @memberOf module:management.ClientGrantsManager.prototype
62
- *
63
- * @example
64
- * management.clientGrants.create(data, function (err) {
65
- * if (err) {
66
- * // Handle error.
67
- * }
68
- *
69
- * // Client grant created.
70
- * });
71
- *
72
- * @param {Object} data The client data object.
73
- * @param {Function} [cb] Callback function.
74
- *
75
- * @return {Promise|undefined}
76
- */
77
- utils.wrapPropertyMethod(ClientGrantsManager, 'create', 'resource.create');
78
-
79
- /**
80
- * Get all Auth0 Client Grants.
81
- *
82
- * @method getAll
83
- * @memberOf module:management.ClientGrantsManager.prototype
84
- *
85
- * @example <caption>
86
- * This method takes an optional object as first argument that may be used to
87
- * specify pagination settings. If pagination options are not present,
88
- * the first page of a limited number of results will be returned.
89
- * </caption>
90
- *
91
- * // Pagination settings.
92
- * var params = {
93
- * per_page: 10,
94
- * page: 0
95
- * };
96
- *
97
- *
98
- * management.clientGrants.getAll(params, function (err, grants) {
99
- * console.log(grants.length);
100
- * });
101
- *
102
- * @param {Object} [params] Client Grants parameters.
103
- * @param {Number} [params.per_page] Number of results per page.
104
- * @param {Number} [params.page] Page number, zero indexed.
105
- * @param {Function} [cb] Callback function.
106
- *
107
- * @return {Promise|undefined}
108
- */
109
- utils.wrapPropertyMethod(ClientGrantsManager, 'getAll', 'resource.getAll');
99
+ getAll(...args) {
100
+ return this.resource.getAll(...args);
101
+ }
110
102
 
111
- /**
112
- * Update an Auth0 client grant.
113
- *
114
- * @method update
115
- * @memberOf module:management.ClientGrantsManager.prototype
116
- *
117
- * @example
118
- * var data = {
119
- * client_id: CLIENT_ID,
120
- * audience: AUDIENCE,
121
- * scope: []
122
- * };
123
- * var params = { id: CLIENT_GRANT_ID };
124
- *
125
- * management.clientGrants.update(params, data, function (err, grant) {
126
- * if (err) {
127
- * // Handle error.
128
- * }
129
- *
130
- * console.log(grant.id);
131
- * });
132
- *
133
- * @param {Object} params Client parameters.
134
- * @param {String} params.id Client grant ID.
135
- * @param {Object} data Updated client data.
136
- * @param {Function} [cb] Callback function.
137
- *
138
- * @return {Promise|undefined}
139
- */
140
- utils.wrapPropertyMethod(ClientGrantsManager, 'update', 'resource.patch');
103
+ /**
104
+ * Update an Auth0 client grant.
105
+ *
106
+ * @example
107
+ * var data = {
108
+ * client_id: CLIENT_ID,
109
+ * audience: AUDIENCE,
110
+ * scope: []
111
+ * };
112
+ * var params = { id: CLIENT_GRANT_ID };
113
+ *
114
+ * management.clientGrants.update(params, data, function (err, grant) {
115
+ * if (err) {
116
+ * // Handle error.
117
+ * }
118
+ *
119
+ * console.log(grant.id);
120
+ * });
121
+ * @param {object} params Client parameters.
122
+ * @param {string} params.id Client grant ID.
123
+ * @param {object} data Updated client data.
124
+ * @param {Function} [cb] Callback function.
125
+ * @returns {Promise|undefined}
126
+ */
127
+ update(...args) {
128
+ return this.resource.patch(...args);
129
+ }
141
130
 
142
- /**
143
- * Delete an Auth0 client grant.
144
- *
145
- * @method delete
146
- * @memberOf module:management.ClientGrantsManager.prototype
147
- *
148
- * @example
149
- * management.clientGrants.delete({ id: GRANT_ID }, function (err) {
150
- * if (err) {
151
- * // Handle error.
152
- * }
153
- *
154
- * // Grant deleted.
155
- * });
156
- *
157
- * @param {Object} params Client parameters.
158
- * @param {String} params.id Client grant ID.
159
- * @param {Function} [cb] Callback function.
160
- *
161
- * @return {Promise|undefined}
162
- */
163
- utils.wrapPropertyMethod(ClientGrantsManager, 'delete', 'resource.delete');
131
+ /**
132
+ * Delete an Auth0 client grant.
133
+ *
134
+ * @example
135
+ * management.clientGrants.delete({ id: GRANT_ID }, function (err) {
136
+ * if (err) {
137
+ * // Handle error.
138
+ * }
139
+ *
140
+ * // Grant deleted.
141
+ * });
142
+ * @param {object} params Client parameters.
143
+ * @param {string} params.id Client grant ID.
144
+ * @param {Function} [cb] Callback function.
145
+ * @returns {Promise|undefined}
146
+ */
147
+ delete(...args) {
148
+ return this.resource.delete(...args);
149
+ }
150
+ }
164
151
 
165
152
  module.exports = ClientGrantsManager;