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,128 +1,124 @@
1
- var jwt = require('jsonwebtoken');
2
- var jwksClient = require('jwks-rsa');
1
+ const jwt = require('jsonwebtoken');
2
+ const jwksClient = require('jwks-rsa');
3
+ const { ArgumentError } = require('rest-facade');
4
+ const validateIdToken = require('./idToken').validate;
3
5
 
4
- var ArgumentError = require('rest-facade').ArgumentError;
5
- var validateIdToken = require('./idToken').validate;
6
-
7
- var HS256_IGNORE_VALIDATION_MESSAGE =
6
+ const HS256_IGNORE_VALIDATION_MESSAGE =
8
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.';
9
8
 
10
9
  /**
11
- * @class
12
10
  * Abstracts the `oauth.create` method with additional id_token validation
13
- * @constructor
14
- * @memberOf module:auth
15
- *
16
- * @param {Object} oauth An instance of @type {OAuthAuthenticator}
17
- * @param {Object} options Authenticator options.
18
- * @param {String} options.domain AuthenticationClient server domain
19
- * @param {String} [options.clientId] Default client ID.
20
- * @param {String} [options.clientSecret] Default client Secret.
21
- * @param {String} [options.supportedAlgorithms] Algorithms that your application expects to receive
22
- * @param {Boolean} [options.__bypassIdTokenValidation] Whether the id_token should be validated or not
23
11
  */
24
- var OAUthWithIDTokenValidation = function(oauth, options) {
25
- if (!oauth) {
26
- throw new ArgumentError('Missing OAuthAuthenticator param');
27
- }
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
+ }
28
26
 
29
- if (!options) {
30
- throw new ArgumentError('Missing authenticator options');
31
- }
27
+ if (!options) {
28
+ throw new ArgumentError('Missing authenticator options');
29
+ }
32
30
 
33
- if (typeof options !== 'object') {
34
- throw new ArgumentError('The authenticator options must be an object');
35
- }
31
+ if (typeof options !== 'object') {
32
+ throw new ArgumentError('The authenticator options must be an object');
33
+ }
36
34
 
37
- this.oauth = oauth;
38
- this.__bypassIdTokenValidation = options.__bypassIdTokenValidation;
39
- this.clientId = options.clientId;
40
- this.clientSecret = options.clientSecret;
41
- this.domain = options.domain;
42
- this.supportedAlgorithms = options.supportedAlgorithms || ['HS256', 'RS256'];
43
- this._jwksClient = jwksClient({
44
- jwksUri: 'https://' + options.domain + '/.well-known/jwks.json'
45
- });
46
- };
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
+ }
47
45
 
48
- /**
49
- * Creates an oauth request and validates the id_token (if any)
50
- *
51
- * @method create
52
- * @memberOf module:auth.OAuthWithIDTokenValidation.prototype
53
- *
54
- * @param {Object} params OAuth parameters that are passed through
55
- * @param {Object} data Custom parameters sent to the OAuth endpoint
56
- * @param {Function} [callback] Callback function
57
- *
58
- * @return {Promise|undefined}
59
- */
60
- OAUthWithIDTokenValidation.prototype.create = function(params, data, cb) {
61
- const _this = this;
62
- const createAndValidate = this.oauth.create(params, data).then(r => {
63
- if (_this.__bypassIdTokenValidation) {
64
- return r;
65
- }
66
- if (r.id_token) {
67
- function getKey(header, callback) {
68
- if (header.alg === 'HS256') {
69
- if (!_this.clientSecret) {
70
- return callback({ message: HS256_IGNORE_VALIDATION_MESSAGE });
71
- }
72
- return callback(null, Buffer.from(_this.clientSecret, 'base64'));
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 });
73
60
  }
74
- _this._jwksClient.getSigningKey(header.kid, function(err, key) {
75
- if (err) {
76
- return callback(err);
77
- }
78
- var signingKey = key.publicKey || key.rsaPublicKey;
79
- return callback(null, signingKey);
80
- });
61
+ return callback(null, Buffer.from(_this.clientSecret, 'base64'));
81
62
  }
82
- return new Promise((res, rej) => {
83
- var options = {
84
- algorithms: this.supportedAlgorithms,
85
- audience: this.clientId,
86
- issuer: 'https://' + this.domain + '/'
87
- };
88
-
89
- if (data.organization) {
90
- options.organization = data.organization;
63
+ _this._jwksClient.getSigningKey(header.kid, (err, key) => {
64
+ if (err) {
65
+ return callback(err);
91
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
+ }
92
75
 
93
- if (data.nonce) {
94
- options.nonce = data.nonce;
95
- }
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
+ };
96
83
 
97
- if (data.maxAge) {
98
- options.maxAge = data.maxAge;
99
- }
84
+ if (data.organization) {
85
+ options.organization = data.organization;
86
+ }
100
87
 
101
- jwt.verify(r.id_token, getKey, options, function(err) {
102
- if (err) {
103
- if (err.message && err.message.includes(HS256_IGNORE_VALIDATION_MESSAGE)) {
104
- console.warn(HS256_IGNORE_VALIDATION_MESSAGE);
105
- } else {
106
- return rej(err);
107
- }
88
+ if (data.nonce) {
89
+ options.nonce = data.nonce;
108
90
  }
109
91
 
110
- try {
111
- validateIdToken(r.id_token, options);
112
- } catch (idTokenError) {
113
- return rej(idTokenError);
92
+ if (data.maxAge) {
93
+ options.maxAge = data.maxAge;
114
94
  }
115
95
 
116
- return res(r);
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
+ });
117
113
  });
118
- });
114
+ }
115
+ return r;
116
+ });
117
+ if (!cb) {
118
+ return createAndValidate;
119
119
  }
120
- return r;
121
- });
122
- if (!cb) {
123
- return createAndValidate;
120
+ createAndValidate.then((r) => cb(null, r)).catch((e) => cb(e));
124
121
  }
125
- createAndValidate.then(r => cb(null, r)).catch(e => cb(e));
126
- };
122
+ }
127
123
 
128
124
  module.exports = OAUthWithIDTokenValidation;