auth0 2.36.1 → 2.38.1
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/CHANGELOG.md +557 -0
- package/README.md +33 -11
- package/package.json +22 -15
- package/src/Auth0RestClient.js +72 -71
- package/src/RetryRestClient.js +78 -81
- package/src/auth/DatabaseAuthenticator.js +242 -259
- package/src/auth/OAUthWithIDTokenValidation.js +99 -103
- package/src/auth/OAuthAuthenticator.js +325 -344
- package/src/auth/PasswordlessAuthenticator.js +238 -252
- package/src/auth/TokensManager.js +231 -246
- package/src/auth/UsersManager.js +149 -160
- package/src/auth/idToken.js +22 -19
- package/src/auth/index.js +510 -581
- package/src/errors.js +23 -23
- package/src/index.js +3 -2
- package/src/management/ActionsManager.js +503 -585
- package/src/management/BlacklistedTokensManager.js +77 -84
- package/src/management/BrandingManager.js +141 -163
- package/src/management/ClientGrantsManager.js +132 -145
- package/src/management/ClientsManager.js +145 -161
- package/src/management/ConnectionsManager.js +215 -204
- package/src/management/CustomDomainsManager.js +140 -157
- package/src/management/DeviceCredentialsManager.js +95 -111
- package/src/management/EmailProviderManager.js +110 -128
- package/src/management/EmailTemplatesManager.js +96 -112
- package/src/management/GrantsManager.js +94 -101
- package/src/management/GuardianManager.js +381 -455
- package/src/management/HooksManager.js +283 -325
- package/src/management/JobsManager.js +310 -343
- package/src/management/LogStreamsManager.js +142 -158
- package/src/management/LogsManager.js +92 -99
- package/src/management/ManagementTokenProvider.js +112 -120
- package/src/management/MigrationsManager.js +81 -90
- package/src/management/OrganizationsManager.js +686 -761
- package/src/management/PromptsManager.js +160 -182
- package/src/management/ResourceServersManager.js +143 -160
- package/src/management/RolesManager.js +323 -369
- package/src/management/RulesConfigsManager.js +94 -110
- package/src/management/RulesManager.js +154 -176
- package/src/management/StatsManager.js +87 -103
- package/src/management/TenantManager.js +81 -97
- package/src/management/TicketsManager.js +107 -115
- package/src/management/UserBlocksManager.js +135 -162
- package/src/management/UsersManager.js +729 -852
- package/src/management/index.js +3094 -3619
- package/src/utils.js +31 -60
|
@@ -1,128 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
if (!options) {
|
|
28
|
+
throw new ArgumentError('Missing authenticator options');
|
|
29
|
+
}
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
if (typeof options !== 'object') {
|
|
32
|
+
throw new ArgumentError('The authenticator options must be an object');
|
|
33
|
+
}
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
94
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
84
|
+
if (data.organization) {
|
|
85
|
+
options.organization = data.organization;
|
|
86
|
+
}
|
|
100
87
|
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
} catch (idTokenError) {
|
|
113
|
-
return rej(idTokenError);
|
|
92
|
+
if (data.maxAge) {
|
|
93
|
+
options.maxAge = data.maxAge;
|
|
114
94
|
}
|
|
115
95
|
|
|
116
|
-
|
|
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
|
-
|
|
121
|
-
});
|
|
122
|
-
if (!cb) {
|
|
123
|
-
return createAndValidate;
|
|
120
|
+
createAndValidate.then((r) => cb(null, r)).catch((e) => cb(e));
|
|
124
121
|
}
|
|
125
|
-
|
|
126
|
-
};
|
|
122
|
+
}
|
|
127
123
|
|
|
128
124
|
module.exports = OAUthWithIDTokenValidation;
|