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.
- package/CHANGELOG.md +554 -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 +237 -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 -178
- 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,257 +1,242 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var ArgumentError = require('rest-facade').ArgumentError;
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const { ArgumentError } = require('rest-facade');
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
|
-
* @class TokensManager
|
|
8
5
|
* Provides methods for getting token data and exchanging tokens.
|
|
9
|
-
* @constructor
|
|
10
|
-
* @memberOf module:auth
|
|
11
|
-
*
|
|
12
|
-
* @param {Object} options Manager options.
|
|
13
|
-
* @param {String} options.baseUrl The auth0 account URL.
|
|
14
|
-
* @param {String} [options.headers] Default request headers.
|
|
15
|
-
* @param {String} [options.clientId] Default client ID.
|
|
16
|
-
* @param {String} [options.clientSecret] Default client Secret.
|
|
17
|
-
*/
|
|
18
|
-
var TokensManager = function(options) {
|
|
19
|
-
if (typeof options !== 'object') {
|
|
20
|
-
throw new ArgumentError('Missing tokens manager options');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (typeof options.baseUrl !== 'string') {
|
|
24
|
-
throw new ArgumentError('baseUrl field is required');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
this.baseUrl = options.baseUrl;
|
|
28
|
-
this.headers = options.headers || {};
|
|
29
|
-
this.clientId = options.clientId || '';
|
|
30
|
-
this.clientSecret = options.clientSecret || '';
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Given an ID token get the user profile linked to it.
|
|
35
|
-
*
|
|
36
|
-
* @method getInfo
|
|
37
|
-
* @memberOf module:auth.TokensManager.prototype
|
|
38
|
-
*
|
|
39
|
-
* @example <caption>
|
|
40
|
-
* Validates a JSON Web Token (signature and expiration) and returns the user
|
|
41
|
-
* information associated with the user id (sub property) of the token. Find
|
|
42
|
-
* more information in the
|
|
43
|
-
* <a href="https://auth0.com/docs/auth-api#!#post--tokeninfo">API Docs</a>.
|
|
44
|
-
* </caption>
|
|
45
|
-
*
|
|
46
|
-
* auth0.tokens.getInfo(token, function (err, tokenInfo) {
|
|
47
|
-
* if (err) {
|
|
48
|
-
* // Handle error.
|
|
49
|
-
* }
|
|
50
|
-
*
|
|
51
|
-
* console.log(tokenInfo);
|
|
52
|
-
* });
|
|
53
|
-
*
|
|
54
|
-
* @param {String} idToken User ID token.
|
|
55
|
-
* @param {Function} [cb] Method callback.
|
|
56
|
-
*
|
|
57
|
-
* @return {Promise|undefined}
|
|
58
6
|
*/
|
|
59
|
-
TokensManager
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
7
|
+
class TokensManager {
|
|
8
|
+
/**
|
|
9
|
+
* @param {object} options Manager options.
|
|
10
|
+
* @param {string} options.baseUrl The auth0 account URL.
|
|
11
|
+
* @param {string} [options.headers] Default request headers.
|
|
12
|
+
* @param {string} [options.clientId] Default client ID.
|
|
13
|
+
* @param {string} [options.clientSecret] Default client Secret.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options) {
|
|
16
|
+
if (typeof options !== 'object') {
|
|
17
|
+
throw new ArgumentError('Missing tokens manager options');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof options.baseUrl !== 'string') {
|
|
21
|
+
throw new ArgumentError('baseUrl field is required');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.baseUrl = options.baseUrl;
|
|
25
|
+
this.headers = options.headers || {};
|
|
26
|
+
this.clientId = options.clientId || '';
|
|
27
|
+
this.clientSecret = options.clientSecret || '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Given an ID token get the user profile linked to it.
|
|
32
|
+
*
|
|
33
|
+
* @example <caption>
|
|
34
|
+
* Validates a JSON Web Token (signature and expiration) and returns the user
|
|
35
|
+
* information associated with the user id (sub property) of the token. Find
|
|
36
|
+
* more information in the
|
|
37
|
+
* <a href="https://auth0.com/docs/auth-api#!#post--tokeninfo">API Docs</a>.
|
|
38
|
+
* </caption>
|
|
39
|
+
*
|
|
40
|
+
* auth0.tokens.getInfo(token, function (err, tokenInfo) {
|
|
41
|
+
* if (err) {
|
|
42
|
+
* // Handle error.
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* console.log(tokenInfo);
|
|
46
|
+
* });
|
|
47
|
+
* @param {string} idToken User ID token.
|
|
48
|
+
* @param {Function} [cb] Method callback.
|
|
49
|
+
* @returns {Promise|undefined}
|
|
50
|
+
*/
|
|
51
|
+
getInfo(idToken, cb) {
|
|
52
|
+
const headers = { ...this.headers };
|
|
53
|
+
|
|
54
|
+
if (idToken === null || idToken === undefined) {
|
|
55
|
+
throw new ArgumentError('An ID token is required');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (typeof idToken !== 'string' || idToken.trim().length === 0) {
|
|
59
|
+
throw new ArgumentError('The ID token is not valid');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Perform the request.
|
|
63
|
+
const promise = axios({
|
|
64
|
+
method: 'POST',
|
|
65
|
+
url: `${this.baseUrl}/tokeninfo`,
|
|
66
|
+
data: { id_token: idToken },
|
|
67
|
+
headers,
|
|
68
|
+
}).then(({ data }) => data);
|
|
69
|
+
|
|
70
|
+
// Use callback if given.
|
|
71
|
+
if (cb instanceof Function) {
|
|
72
|
+
promise.then(cb.bind(null, null)).catch(cb);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return promise;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Exchange the token of the logged in user with a token that is valid to call
|
|
81
|
+
* the API (signed with the API secret).
|
|
82
|
+
*
|
|
83
|
+
* @example <caption>
|
|
84
|
+
* Given an existing token, this endpoint will generate a new token signed
|
|
85
|
+
* with the target client secret. This is used to flow the identity of the
|
|
86
|
+
* user from the application to an API or across different APIs that are
|
|
87
|
+
* protected with different secrets. Find more information in the
|
|
88
|
+
* <a href="https://auth0.com/docs/auth-api#!#post--delegation">API Docs</a>.
|
|
89
|
+
* </caption>
|
|
90
|
+
*
|
|
91
|
+
* var data = {
|
|
92
|
+
* id_token: '{ID_TOKEN}',
|
|
93
|
+
* api_type: 'app',
|
|
94
|
+
* target: '{TARGET}',
|
|
95
|
+
* grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer'
|
|
96
|
+
* };
|
|
97
|
+
*
|
|
98
|
+
* auth0.tokens.getDelegationToken(data, function (err, token) {
|
|
99
|
+
* if (err) {
|
|
100
|
+
* // Handle error.
|
|
101
|
+
* }
|
|
102
|
+
*
|
|
103
|
+
* console.log(token);
|
|
104
|
+
* });
|
|
105
|
+
* @param {object} data Token data object.
|
|
106
|
+
* @param {string} data.id_token User ID token.
|
|
107
|
+
* @param {string} data.refresh_token User refresh token.
|
|
108
|
+
* @param {string} data.target Target client ID.
|
|
109
|
+
* @param {string} data.api_type The API to be used (aws, auth0, etc).
|
|
110
|
+
* @param {string} data.grant_type Grant type (password, jwt, etc).
|
|
111
|
+
* @param {Function} [cb] Callback function.
|
|
112
|
+
* @returns {Promise|undefined}
|
|
113
|
+
*/
|
|
114
|
+
getDelegationToken(data, cb) {
|
|
115
|
+
const body = { client_id: this.clientId, ...data };
|
|
116
|
+
const { headers } = this;
|
|
117
|
+
|
|
118
|
+
if (!data) {
|
|
119
|
+
throw new ArgumentError('Missing token data object');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const hasIdToken = typeof data.id_token === 'string' && data.id_token.trim().length !== 0;
|
|
123
|
+
|
|
124
|
+
const hasRefreshToken =
|
|
125
|
+
typeof data.refresh_token === 'string' && data.refresh_token.trim().length !== 0;
|
|
126
|
+
|
|
127
|
+
if (!hasIdToken && !hasRefreshToken) {
|
|
128
|
+
throw new ArgumentError('one of id_token or refresh_token is required');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (hasIdToken && hasRefreshToken) {
|
|
132
|
+
throw new ArgumentError(
|
|
133
|
+
'id_token and refresh_token fields cannot be specified simulatenously'
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (typeof data.target !== 'string' || data.target.trim().length === 0) {
|
|
138
|
+
throw new ArgumentError('target field is required');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (typeof data.api_type !== 'string' || data.api_type.trim().length === 0) {
|
|
142
|
+
throw new ArgumentError('api_type field is required');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (typeof data.grant_type !== 'string' || data.grant_type.trim().length === 0) {
|
|
146
|
+
throw new ArgumentError('grant_type field is required');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Perform the request.
|
|
150
|
+
const promise = axios({
|
|
151
|
+
method: 'POST',
|
|
152
|
+
url: `${this.baseUrl}/delegation`,
|
|
153
|
+
data: body,
|
|
154
|
+
headers,
|
|
155
|
+
}).then(({ data }) => data);
|
|
156
|
+
|
|
157
|
+
// Use callback if given.
|
|
158
|
+
if (cb instanceof Function) {
|
|
159
|
+
promise.then(cb.bind(null, null)).catch(cb);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return promise;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Proactively revoke an issued refresh token.
|
|
168
|
+
*
|
|
169
|
+
* @example <caption>
|
|
170
|
+
* Given an existing refresh token, this endpoint will revoke it in order
|
|
171
|
+
* to prevent unauthorized silently user authentication tokens refresh.
|
|
172
|
+
* Find more information in the <a href="https://auth0.com/docs/api/authentication#revoke-refresh-token">API Docs</a>.
|
|
173
|
+
* </caption>
|
|
174
|
+
*
|
|
175
|
+
* var data = {
|
|
176
|
+
* token: '{REFRESH_TOKEN}'
|
|
177
|
+
* };
|
|
178
|
+
*
|
|
179
|
+
* auth0.tokens.revokeRefreshToken(data, function (err, _) {
|
|
180
|
+
* if (err) {
|
|
181
|
+
* // Handle error.
|
|
182
|
+
* }
|
|
183
|
+
*
|
|
184
|
+
* // Do stuff.
|
|
185
|
+
* });
|
|
186
|
+
* @param {object} data Token data object.
|
|
187
|
+
* @param {string} data.token User refresh token.
|
|
188
|
+
* @param {string} [data.client_id] Target client ID.
|
|
189
|
+
* @param {string} [data.client_secret] Target client secret.
|
|
190
|
+
* @param {Function} [cb] Callback function.
|
|
191
|
+
* @returns {Promise|undefined}
|
|
192
|
+
*/
|
|
193
|
+
revokeRefreshToken(data, cb) {
|
|
194
|
+
if (!data) {
|
|
195
|
+
throw new ArgumentError('Missing token data object');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const hasToken = typeof data.token === 'string' && data.token.trim().length !== 0;
|
|
199
|
+
|
|
200
|
+
if (!hasToken) {
|
|
201
|
+
throw new ArgumentError('token property is required');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const hasClientId =
|
|
205
|
+
(data.client_id &&
|
|
206
|
+
typeof data.client_id === 'string' &&
|
|
207
|
+
data.client_id.trim().length !== 0) ||
|
|
208
|
+
this.clientId !== '';
|
|
209
|
+
|
|
210
|
+
if (!hasClientId) {
|
|
211
|
+
throw new ArgumentError(
|
|
212
|
+
'Neither token data client_id property or constructor clientId property has been set'
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const body = {
|
|
217
|
+
client_id: this.clientId,
|
|
218
|
+
client_secret: this.clientSecret,
|
|
219
|
+
...data,
|
|
220
|
+
};
|
|
215
221
|
|
|
216
|
-
|
|
217
|
-
throw new ArgumentError('token property is required');
|
|
218
|
-
}
|
|
222
|
+
const { headers } = this;
|
|
219
223
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
224
|
+
// Perform the request.
|
|
225
|
+
const promise = axios({
|
|
226
|
+
method: 'POST',
|
|
227
|
+
url: `${this.baseUrl}/oauth/revoke`,
|
|
228
|
+
data: body,
|
|
229
|
+
headers,
|
|
230
|
+
}).then(({ data }) => data);
|
|
223
231
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
232
|
+
// Use callback if given.
|
|
233
|
+
if (cb instanceof Function) {
|
|
234
|
+
promise.then(cb.bind(null, null)).catch(cb);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
229
237
|
|
|
230
|
-
|
|
231
|
-
{
|
|
232
|
-
client_id: this.clientId,
|
|
233
|
-
client_secret: this.clientSecret
|
|
234
|
-
},
|
|
235
|
-
data
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
var headers = this.headers;
|
|
239
|
-
|
|
240
|
-
// Perform the request.
|
|
241
|
-
var promise = axios({
|
|
242
|
-
method: 'POST',
|
|
243
|
-
url: this.baseUrl + '/oauth/revoke',
|
|
244
|
-
data: body,
|
|
245
|
-
headers: headers
|
|
246
|
-
}).then(({ data }) => data);
|
|
247
|
-
|
|
248
|
-
// Use callback if given.
|
|
249
|
-
if (cb instanceof Function) {
|
|
250
|
-
promise.then(cb.bind(null, null)).catch(cb);
|
|
251
|
-
return;
|
|
238
|
+
return promise;
|
|
252
239
|
}
|
|
253
|
-
|
|
254
|
-
return promise;
|
|
255
|
-
};
|
|
240
|
+
}
|
|
256
241
|
|
|
257
242
|
module.exports = TokensManager;
|