auth0 2.36.2 → 2.39.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 +41 -0
- package/README.md +33 -11
- package/package.json +22 -14
- 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 +510 -584
- 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,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var SanitizedError = require('../errors').SanitizedError;
|
|
8
|
-
var OAUthWithIDTokenValidation = require('./OAUthWithIDTokenValidation');
|
|
1
|
+
const { sanitizeArguments } = require('../utils');
|
|
2
|
+
const { ArgumentError } = require('rest-facade');
|
|
3
|
+
const RestClient = require('rest-facade').Client;
|
|
4
|
+
const { SanitizedError } = require('../errors');
|
|
5
|
+
const OAUthWithIDTokenValidation = require('./OAUthWithIDTokenValidation');
|
|
9
6
|
|
|
10
7
|
function getParamsFromOptions(options) {
|
|
11
8
|
const params = {};
|
|
@@ -13,7 +10,7 @@ function getParamsFromOptions(options) {
|
|
|
13
10
|
return params;
|
|
14
11
|
}
|
|
15
12
|
if (options.forwardedFor) {
|
|
16
|
-
params._requestCustomizer = function(req) {
|
|
13
|
+
params._requestCustomizer = function (req) {
|
|
17
14
|
req.set('auth0-forwarded-for', options.forwardedFor);
|
|
18
15
|
};
|
|
19
16
|
}
|
|
@@ -24,387 +21,371 @@ function getParamsFromOptions(options) {
|
|
|
24
21
|
}
|
|
25
22
|
|
|
26
23
|
/**
|
|
27
|
-
* @class
|
|
28
24
|
* Abstracts the sign-in, sign-up and change-password processes for Database &
|
|
29
25
|
* Active Directory authentication services.
|
|
30
|
-
* @constructor
|
|
31
|
-
* @memberOf module:auth
|
|
32
|
-
*
|
|
33
|
-
* @param {Object} options Authenticator options.
|
|
34
|
-
* @param {String} options.baseUrl The Auth0 account URL.
|
|
35
|
-
* @param {String} options.domain AuthenticationClient server domain
|
|
36
|
-
* @param {String} [options.clientId] Default client ID.
|
|
37
|
-
* @param {String} [options.clientSecret] Default client Secret.
|
|
38
|
-
* @param {Boolean} [options.__bypassIdTokenValidation] Whether the id_token should be validated or not
|
|
39
26
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
27
|
+
class OAuthAuthenticator {
|
|
28
|
+
/**
|
|
29
|
+
* @param {object} options Authenticator options.
|
|
30
|
+
* @param {string} options.baseUrl The Auth0 account URL.
|
|
31
|
+
* @param {string} options.domain AuthenticationClient server domain
|
|
32
|
+
* @param {string} [options.clientId] Default client ID.
|
|
33
|
+
* @param {string} [options.clientSecret] Default client Secret.
|
|
34
|
+
* @param {boolean} [options.__bypassIdTokenValidation] Whether the id_token should be validated or not
|
|
35
|
+
*/
|
|
36
|
+
constructor(options) {
|
|
37
|
+
if (!options) {
|
|
38
|
+
throw new ArgumentError('Missing authenticator options');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (typeof options !== 'object') {
|
|
42
|
+
throw new ArgumentError('The authenticator options must be an object');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Options object for the Rest Client instance.
|
|
47
|
+
*
|
|
48
|
+
* @type {object}
|
|
49
|
+
*/
|
|
50
|
+
const clientOptions = {
|
|
51
|
+
errorCustomizer: SanitizedError,
|
|
52
|
+
errorFormatter: { message: 'message', name: 'error' },
|
|
53
|
+
headers: options.headers,
|
|
54
|
+
};
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
this.oauth = new RestClient(`${options.baseUrl}/oauth/:type`, clientOptions);
|
|
57
|
+
this.oauthWithIDTokenValidation = new OAUthWithIDTokenValidation(this.oauth, options);
|
|
58
|
+
this.clientId = options.clientId;
|
|
59
|
+
this.clientSecret = options.clientSecret;
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
/**
|
|
50
|
-
*
|
|
63
|
+
* Sign in using a username and password.
|
|
64
|
+
*
|
|
65
|
+
* @example <caption>
|
|
66
|
+
* Given the user's credentials and the connection specified, it
|
|
67
|
+
* will return a JSON with the access_token and id_token.
|
|
68
|
+
* More information in the
|
|
69
|
+
*
|
|
70
|
+
* <a href="https://auth0.com/docs/api/authentication#database-ad-ldap-active-">
|
|
71
|
+
* API Docs
|
|
72
|
+
* </a>.
|
|
73
|
+
* </caption>
|
|
74
|
+
*
|
|
75
|
+
* var data = {
|
|
76
|
+
* client_id: '{CLIENT_ID}', // Optional field.
|
|
77
|
+
* username: '{USERNAME}',
|
|
78
|
+
* password: '{PASSWORD}',
|
|
79
|
+
* connection: '{CONNECTION_NAME}',
|
|
80
|
+
* scope: 'openid' // Optional field.
|
|
81
|
+
* };
|
|
82
|
+
*
|
|
83
|
+
* auth0.oauth.signIn(data, function (err, userData) {
|
|
84
|
+
* if (err) {
|
|
85
|
+
* // Handle error.
|
|
86
|
+
* }
|
|
51
87
|
*
|
|
52
|
-
*
|
|
88
|
+
* console.log(userData);
|
|
89
|
+
* });
|
|
90
|
+
* @param {object} userData User credentials object.
|
|
91
|
+
* @param {string} userData.username Username.
|
|
92
|
+
* @param {string} userData.password User password.
|
|
93
|
+
* @param {string} userData.connection The identity provider in use.
|
|
94
|
+
* @param {object} [options] Additional options.
|
|
95
|
+
* @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
96
|
+
* @param {Function} cb Callback
|
|
97
|
+
* @returns {Promise|undefined}
|
|
53
98
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Sign in using a username and password.
|
|
68
|
-
*
|
|
69
|
-
* @method signIn
|
|
70
|
-
* @memberOf module:auth.OAuthAuthenticator.prototype
|
|
71
|
-
*
|
|
72
|
-
* @example <caption>
|
|
73
|
-
* Given the user's credentials and the connection specified, it
|
|
74
|
-
* will return a JSON with the access_token and id_token.
|
|
75
|
-
* More information in the
|
|
76
|
-
* <a href="https://auth0.com/docs/api/authentication#database-ad-ldap-active-">
|
|
77
|
-
* API Docs
|
|
78
|
-
* </a>.
|
|
79
|
-
* </caption>
|
|
80
|
-
*
|
|
81
|
-
* var data = {
|
|
82
|
-
* client_id: '{CLIENT_ID}', // Optional field.
|
|
83
|
-
* username: '{USERNAME}',
|
|
84
|
-
* password: '{PASSWORD}',
|
|
85
|
-
* connection: '{CONNECTION_NAME}',
|
|
86
|
-
* scope: 'openid' // Optional field.
|
|
87
|
-
* };
|
|
88
|
-
*
|
|
89
|
-
* auth0.oauth.signIn(data, function (err, userData) {
|
|
90
|
-
* if (err) {
|
|
91
|
-
* // Handle error.
|
|
92
|
-
* }
|
|
93
|
-
*
|
|
94
|
-
* console.log(userData);
|
|
95
|
-
* });
|
|
96
|
-
*
|
|
97
|
-
* @param {Object} userData User credentials object.
|
|
98
|
-
* @param {String} userData.username Username.
|
|
99
|
-
* @param {String} userData.password User password.
|
|
100
|
-
* @param {String} userData.connection The identity provider in use.
|
|
101
|
-
* @param {Object} [options] Additional options.
|
|
102
|
-
* @param {String} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
103
|
-
*
|
|
104
|
-
* @return {Promise|undefined}
|
|
105
|
-
*/
|
|
106
|
-
OAuthAuthenticator.prototype.signIn = function(userData, options, cb) {
|
|
107
|
-
var { options, cb } = sanitizeArguments(options, cb);
|
|
108
|
-
var defaultParams = {
|
|
109
|
-
type: 'ro'
|
|
110
|
-
};
|
|
111
|
-
var params = extend(defaultParams, getParamsFromOptions(options));
|
|
112
|
-
var defaultFields = {
|
|
113
|
-
client_id: this.clientId,
|
|
114
|
-
grant_type: 'password',
|
|
115
|
-
scope: 'openid'
|
|
116
|
-
};
|
|
117
|
-
var data = extend(defaultFields, userData);
|
|
118
|
-
|
|
119
|
-
if (!userData || typeof userData !== 'object') {
|
|
120
|
-
throw new ArgumentError('Missing user data object');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
params.type === 'ro' &&
|
|
125
|
-
(typeof data.connection !== 'string' || data.connection.split().length === 0)
|
|
126
|
-
) {
|
|
127
|
-
throw new ArgumentError('connection field is required');
|
|
128
|
-
}
|
|
99
|
+
signIn(userData, options, cb) {
|
|
100
|
+
if (!userData || typeof userData !== 'object') {
|
|
101
|
+
throw new ArgumentError('Missing user data object');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const { options: sanitizedOptions, cb: sanitizedCb } = sanitizeArguments(options, cb);
|
|
105
|
+
const params = {
|
|
106
|
+
type: 'ro',
|
|
107
|
+
...getParamsFromOptions(sanitizedOptions),
|
|
108
|
+
};
|
|
129
109
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
110
|
+
const data = {
|
|
111
|
+
client_id: this.clientId,
|
|
112
|
+
grant_type: 'password',
|
|
113
|
+
scope: 'openid',
|
|
114
|
+
...userData,
|
|
115
|
+
};
|
|
133
116
|
|
|
134
|
-
|
|
135
|
-
|
|
117
|
+
if (
|
|
118
|
+
params.type === 'ro' &&
|
|
119
|
+
(typeof data.connection !== 'string' || data.connection.split().length === 0)
|
|
120
|
+
) {
|
|
121
|
+
throw new ArgumentError('connection field is required');
|
|
122
|
+
}
|
|
136
123
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
* @method passwordGrant
|
|
141
|
-
* @memberOf module:auth.OAuthAuthenticator.prototype
|
|
142
|
-
*
|
|
143
|
-
* @example <caption>
|
|
144
|
-
* Given the user's credentials perform the OAuth password grant
|
|
145
|
-
* or Password Realm grant if a realm is provided,
|
|
146
|
-
* it will return a JSON with the access_token and id_token.
|
|
147
|
-
* More information in the
|
|
148
|
-
* <a href="https://auth0.com/docs/api/authentication#resource-owner-password">
|
|
149
|
-
* API Docs
|
|
150
|
-
* </a>.
|
|
151
|
-
* </caption>
|
|
152
|
-
*
|
|
153
|
-
* var data = {
|
|
154
|
-
* client_id: '{CLIENT_ID}', // Optional field.
|
|
155
|
-
* username: '{USERNAME}',
|
|
156
|
-
* password: '{PASSWORD}',
|
|
157
|
-
* realm: '{CONNECTION_NAME}', // Optional field.
|
|
158
|
-
* scope: 'openid' // Optional field.
|
|
159
|
-
* };
|
|
160
|
-
*
|
|
161
|
-
* auth0.oauth.passwordGrant(data, function (err, userData) {
|
|
162
|
-
* if (err) {
|
|
163
|
-
* // Handle error.
|
|
164
|
-
* }
|
|
165
|
-
*
|
|
166
|
-
* console.log(userData);
|
|
167
|
-
* });
|
|
168
|
-
*
|
|
169
|
-
* @param {Object} userData User credentials object.
|
|
170
|
-
* @param {String} userData.username Username.
|
|
171
|
-
* @param {String} userData.password User password.
|
|
172
|
-
* @param {String} [userData.realm] Name of the realm to use to authenticate or the connection name
|
|
173
|
-
* @param {Object} [options] Additional options.
|
|
174
|
-
* @param {String} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
175
|
-
*
|
|
176
|
-
* @return {Promise|undefined}
|
|
177
|
-
*/
|
|
178
|
-
OAuthAuthenticator.prototype.passwordGrant = function(userData, options, cb) {
|
|
179
|
-
var { options, cb } = sanitizeArguments(options, cb);
|
|
180
|
-
var defaultParams = {
|
|
181
|
-
type: 'token'
|
|
182
|
-
};
|
|
183
|
-
var params = extend(defaultParams, getParamsFromOptions(options));
|
|
184
|
-
var defaultFields = {
|
|
185
|
-
client_id: this.clientId,
|
|
186
|
-
client_secret: this.clientSecret,
|
|
187
|
-
grant_type: 'password'
|
|
188
|
-
};
|
|
189
|
-
var data = extend(defaultFields, userData);
|
|
190
|
-
|
|
191
|
-
if (!userData || typeof userData !== 'object') {
|
|
192
|
-
throw new ArgumentError('Missing user data object');
|
|
193
|
-
}
|
|
124
|
+
if (sanitizedCb && sanitizedCb instanceof Function) {
|
|
125
|
+
return this.oauthWithIDTokenValidation.create(params, data, sanitizedCb);
|
|
126
|
+
}
|
|
194
127
|
|
|
195
|
-
|
|
196
|
-
throw new ArgumentError('username field is required');
|
|
128
|
+
return this.oauthWithIDTokenValidation.create(params, data);
|
|
197
129
|
}
|
|
198
130
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Sign in using a username and password
|
|
133
|
+
*
|
|
134
|
+
* @example <caption>
|
|
135
|
+
* Given the user's credentials perform the OAuth password grant
|
|
136
|
+
* or Password Realm grant if a realm is provided,
|
|
137
|
+
* it will return a JSON with the access_token and id_token.
|
|
138
|
+
*
|
|
139
|
+
* More information in the
|
|
140
|
+
* <a href="https://auth0.com/docs/api/authentication#resource-owner-password">
|
|
141
|
+
* API Docs
|
|
142
|
+
* </a>.
|
|
143
|
+
* </caption>
|
|
144
|
+
*
|
|
145
|
+
* var data = {
|
|
146
|
+
* client_id: '{CLIENT_ID}', // Optional field.
|
|
147
|
+
* username: '{USERNAME}',
|
|
148
|
+
* password: '{PASSWORD}',
|
|
149
|
+
* realm: '{CONNECTION_NAME}', // Optional field.
|
|
150
|
+
* scope: 'openid' // Optional field.
|
|
151
|
+
* };
|
|
152
|
+
*
|
|
153
|
+
* auth0.oauth.passwordGrant(data, function (err, userData) {
|
|
154
|
+
* if (err) {
|
|
155
|
+
* // Handle error.
|
|
156
|
+
* }
|
|
157
|
+
*
|
|
158
|
+
* console.log(userData);
|
|
159
|
+
* });
|
|
160
|
+
* @param {object} userData User credentials object.
|
|
161
|
+
* @param {string} userData.username Username.
|
|
162
|
+
* @param {string} userData.password User password.
|
|
163
|
+
* @param {string} [userData.realm] Name of the realm to use to authenticate or the connection name
|
|
164
|
+
* @param {object} [options] Additional options.
|
|
165
|
+
* @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
166
|
+
* @param {Function} cb Callback
|
|
167
|
+
* @returns {Promise|undefined}
|
|
168
|
+
*/
|
|
169
|
+
passwordGrant(userData, options, cb) {
|
|
170
|
+
const { options: sanitizedOptions, cb: sanitizedCb } = sanitizeArguments(options, cb);
|
|
171
|
+
|
|
172
|
+
if (!userData || typeof userData !== 'object') {
|
|
173
|
+
throw new ArgumentError('Missing user data object');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const data = {
|
|
177
|
+
client_id: this.clientId,
|
|
178
|
+
client_secret: this.clientSecret,
|
|
179
|
+
grant_type: 'password',
|
|
180
|
+
...userData,
|
|
181
|
+
};
|
|
202
182
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
183
|
+
if (typeof data.username !== 'string' || data.username.split().length === 0) {
|
|
184
|
+
throw new ArgumentError('username field is required');
|
|
185
|
+
}
|
|
206
186
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
187
|
+
if (typeof data.password !== 'string' || data.password.split().length === 0) {
|
|
188
|
+
throw new ArgumentError('password field is required');
|
|
189
|
+
}
|
|
210
190
|
|
|
211
|
-
|
|
212
|
-
|
|
191
|
+
if (typeof data.realm === 'string' && data.realm.split().length !== 0) {
|
|
192
|
+
data.grant_type = 'http://auth0.com/oauth/grant-type/password-realm';
|
|
193
|
+
}
|
|
213
194
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
* @memberOf module:auth.OAuthAuthenticator.prototype
|
|
219
|
-
*
|
|
220
|
-
* @example <caption>
|
|
221
|
-
* Given a refresh token from a previous authentication request
|
|
222
|
-
* it will return a JSON with the access_token and id_token if
|
|
223
|
-
* the openid scope was originally included.
|
|
224
|
-
* More information in the
|
|
225
|
-
* <a href="https://auth0.com/docs/api/authentication#refresh-token">
|
|
226
|
-
* API Docs
|
|
227
|
-
* </a>.
|
|
228
|
-
* </caption>
|
|
229
|
-
*
|
|
230
|
-
* var data = {
|
|
231
|
-
* refresh_token: '{REFRESH_TOKEN}',
|
|
232
|
-
* };
|
|
233
|
-
*
|
|
234
|
-
* auth0.oauth.refreshToken(data, function (err, data) {
|
|
235
|
-
* if (err) {
|
|
236
|
-
* // Handle error.
|
|
237
|
-
* }
|
|
238
|
-
*
|
|
239
|
-
* console.log(data);
|
|
240
|
-
* });
|
|
241
|
-
*
|
|
242
|
-
* @param {Object} data Data object.
|
|
243
|
-
* @param {String} data.refresh_token Refresh token.
|
|
244
|
-
*
|
|
245
|
-
* @return {Promise|undefined}
|
|
246
|
-
*/
|
|
247
|
-
OAuthAuthenticator.prototype.refreshToken = function(data, cb) {
|
|
248
|
-
if (!data || typeof data !== 'object') {
|
|
249
|
-
throw new ArgumentError('Missing data object');
|
|
250
|
-
}
|
|
195
|
+
const params = {
|
|
196
|
+
type: 'token',
|
|
197
|
+
...getParamsFromOptions(sanitizedOptions),
|
|
198
|
+
};
|
|
251
199
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
grant_type: 'refresh_token'
|
|
256
|
-
};
|
|
200
|
+
if (sanitizedCb && sanitizedCb instanceof Function) {
|
|
201
|
+
return this.oauthWithIDTokenValidation.create(params, data, sanitizedCb);
|
|
202
|
+
}
|
|
257
203
|
|
|
258
|
-
|
|
259
|
-
if (typeof data.refresh_token !== 'string' || data.refresh_token.split().length === 0) {
|
|
260
|
-
throw new ArgumentError('refresh_token is required');
|
|
204
|
+
return this.oauthWithIDTokenValidation.create(params, data);
|
|
261
205
|
}
|
|
262
206
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Exchange a refresh token
|
|
209
|
+
*
|
|
210
|
+
* @example <caption>
|
|
211
|
+
* Given a refresh token from a previous authentication request
|
|
212
|
+
* it will return a JSON with the access_token and id_token if
|
|
213
|
+
* the openid scope was originally included.
|
|
214
|
+
* More information in the
|
|
215
|
+
* <a href="https://auth0.com/docs/api/authentication#refresh-token">
|
|
216
|
+
* API Docs
|
|
217
|
+
* </a>.
|
|
218
|
+
* </caption>
|
|
219
|
+
*
|
|
220
|
+
* var data = {
|
|
221
|
+
* refresh_token: '{REFRESH_TOKEN}',
|
|
222
|
+
* };
|
|
223
|
+
*
|
|
224
|
+
* auth0.oauth.refreshToken(data, function (err, data) {
|
|
225
|
+
* if (err) {
|
|
226
|
+
* // Handle error.
|
|
227
|
+
* }
|
|
228
|
+
*
|
|
229
|
+
* console.log(data);
|
|
230
|
+
* });
|
|
231
|
+
* @param {object} data Data object.
|
|
232
|
+
* @param {string} data.refresh_token Refresh token.
|
|
233
|
+
* @param {Function} cb Callback
|
|
234
|
+
* @returns {Promise|undefined}
|
|
235
|
+
*/
|
|
236
|
+
refreshToken(data, cb) {
|
|
237
|
+
if (!data || typeof data !== 'object') {
|
|
238
|
+
throw new ArgumentError('Missing data object');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
data = {
|
|
242
|
+
client_id: this.clientId,
|
|
243
|
+
client_secret: this.clientSecret,
|
|
244
|
+
grant_type: 'refresh_token',
|
|
245
|
+
...data,
|
|
246
|
+
};
|
|
266
247
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return this.oauth.create(params, data);
|
|
271
|
-
};
|
|
248
|
+
if (typeof data.refresh_token !== 'string' || data.refresh_token.split().length === 0) {
|
|
249
|
+
throw new ArgumentError('refresh_token is required');
|
|
250
|
+
}
|
|
272
251
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
* @method socialSignIn
|
|
277
|
-
* @memberOf module:auth.OAuthAuthenticator.prototype
|
|
278
|
-
*
|
|
279
|
-
* @param {Object} data User credentials object.
|
|
280
|
-
* @param {String} data.access_token User access token.
|
|
281
|
-
* @param {String} data.connection Identity provider.
|
|
282
|
-
*
|
|
283
|
-
* @return {Promise|undefined}
|
|
284
|
-
*/
|
|
285
|
-
OAuthAuthenticator.prototype.socialSignIn = function(data, cb) {
|
|
286
|
-
var params = {
|
|
287
|
-
type: 'access_token'
|
|
288
|
-
};
|
|
252
|
+
const params = {
|
|
253
|
+
type: 'token',
|
|
254
|
+
};
|
|
289
255
|
|
|
290
|
-
|
|
291
|
-
|
|
256
|
+
if (cb && cb instanceof Function) {
|
|
257
|
+
return this.oauth.create(params, data, cb);
|
|
258
|
+
}
|
|
259
|
+
return this.oauth.create(params, data);
|
|
292
260
|
}
|
|
293
261
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
262
|
+
/**
|
|
263
|
+
* Sign in using a social provider access token.
|
|
264
|
+
*
|
|
265
|
+
* @param {object} data User credentials object.
|
|
266
|
+
* @param {string} data.access_token User access token.
|
|
267
|
+
* @param {string} data.connection Identity provider.
|
|
268
|
+
* @param {Function} cb Callback
|
|
269
|
+
* @returns {Promise|undefined}
|
|
270
|
+
*/
|
|
271
|
+
socialSignIn(data, cb) {
|
|
272
|
+
const params = {
|
|
273
|
+
type: 'access_token',
|
|
274
|
+
};
|
|
297
275
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
276
|
+
if (typeof data !== 'object') {
|
|
277
|
+
throw new ArgumentError('Missing user credential objects');
|
|
278
|
+
}
|
|
301
279
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
280
|
+
if (typeof data.access_token !== 'string' || data.access_token.trim().length === 0) {
|
|
281
|
+
throw new ArgumentError('access_token field is required');
|
|
282
|
+
}
|
|
305
283
|
|
|
306
|
-
|
|
307
|
-
|
|
284
|
+
if (typeof data.connection !== 'string' || data.connection.trim().length === 0) {
|
|
285
|
+
throw new ArgumentError('connection field is required');
|
|
286
|
+
}
|
|
308
287
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
};
|
|
288
|
+
if (cb && cb instanceof Function) {
|
|
289
|
+
return this.oauth.create(params, data, cb);
|
|
290
|
+
}
|
|
313
291
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
client_id: this.clientId,
|
|
317
|
-
client_secret: this.clientSecret
|
|
318
|
-
};
|
|
292
|
+
return this.oauth.create(params, data);
|
|
293
|
+
}
|
|
319
294
|
|
|
320
|
-
|
|
295
|
+
clientCredentialsGrant(options, cb) {
|
|
296
|
+
if (!options || typeof options !== 'object') {
|
|
297
|
+
throw new ArgumentError('Missing options object');
|
|
298
|
+
}
|
|
321
299
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
300
|
+
const data = {
|
|
301
|
+
grant_type: 'client_credentials',
|
|
302
|
+
client_id: this.clientId,
|
|
303
|
+
client_secret: this.clientSecret,
|
|
304
|
+
...options,
|
|
305
|
+
};
|
|
325
306
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
307
|
+
if (!data.client_id || data.client_id.trim().length === 0) {
|
|
308
|
+
throw new ArgumentError('client_id field is required');
|
|
309
|
+
}
|
|
329
310
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
311
|
+
if (!data.client_secret || data.client_secret.trim().length === 0) {
|
|
312
|
+
throw new ArgumentError('client_secret field is required');
|
|
313
|
+
}
|
|
333
314
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
315
|
+
const params = {
|
|
316
|
+
type: 'token',
|
|
317
|
+
};
|
|
337
318
|
|
|
338
|
-
|
|
339
|
-
|
|
319
|
+
if (cb && cb instanceof Function) {
|
|
320
|
+
return this.oauth.create(params, data, cb);
|
|
321
|
+
}
|
|
340
322
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
*
|
|
344
|
-
* @method authorizationCodeGrant
|
|
345
|
-
* @memberOf module:auth.OAuthAuthenticator.prototype
|
|
346
|
-
*
|
|
347
|
-
* @example <caption>
|
|
348
|
-
* Given the code returned in the URL params after the redirect
|
|
349
|
-
* from successful authentication, exchange the code for auth0
|
|
350
|
-
* credentials. It will return JSON with the access_token and id_token.
|
|
351
|
-
* More information in the
|
|
352
|
-
* <a href="https://auth0.com/docs/api/authentication#authorization-code-grant">
|
|
353
|
-
* API Docs
|
|
354
|
-
* </a>.
|
|
355
|
-
* </caption>
|
|
356
|
-
*
|
|
357
|
-
* var options = {
|
|
358
|
-
* code: '{CODE}',
|
|
359
|
-
* redirect_uri: '{REDIRECT_URI}',
|
|
360
|
-
* organization: '{ORGANIZATION_ID}' // Optiional field.
|
|
361
|
-
* };
|
|
362
|
-
*
|
|
363
|
-
* auth0.oauth.authorizationCodeGrant(options, function (err, userData) {
|
|
364
|
-
* if (err) {
|
|
365
|
-
* // Handle error.
|
|
366
|
-
* }
|
|
367
|
-
*
|
|
368
|
-
* console.log(userData);
|
|
369
|
-
* });
|
|
370
|
-
*
|
|
371
|
-
* @param {Object} options Authorization code payload
|
|
372
|
-
* @param {String} options.organization Organization ID
|
|
373
|
-
* @param {String} options.code Code in URL returned after authentication
|
|
374
|
-
* @param {String} options.redirect_uri The URL to which Auth0 will redirect the browser after authorization has been granted by the user.
|
|
375
|
-
*
|
|
376
|
-
* @return {Promise|undefined}
|
|
377
|
-
*/
|
|
378
|
-
OAuthAuthenticator.prototype.authorizationCodeGrant = function(options, cb) {
|
|
379
|
-
var params = {
|
|
380
|
-
type: 'token'
|
|
381
|
-
};
|
|
323
|
+
return this.oauth.create(params, data);
|
|
324
|
+
}
|
|
382
325
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
326
|
+
/**
|
|
327
|
+
* Sign in using an authorization code
|
|
328
|
+
*
|
|
329
|
+
* @example <caption>
|
|
330
|
+
* Given the code returned in the URL params after the redirect
|
|
331
|
+
* from successful authentication, exchange the code for auth0
|
|
332
|
+
* credentials. It will return JSON with the access_token and id_token.
|
|
333
|
+
* More information in the
|
|
334
|
+
* <a href="https://auth0.com/docs/api/authentication#authorization-code-grant">
|
|
335
|
+
* API Docs
|
|
336
|
+
* </a>.
|
|
337
|
+
* </caption>
|
|
338
|
+
*
|
|
339
|
+
* var options = {
|
|
340
|
+
* code: '{CODE}',
|
|
341
|
+
* redirect_uri: '{REDIRECT_URI}',
|
|
342
|
+
* organization: '{ORGANIZATION_ID}' // Optiional field.
|
|
343
|
+
* };
|
|
344
|
+
*
|
|
345
|
+
* auth0.oauth.authorizationCodeGrant(options, function (err, userData) {
|
|
346
|
+
* if (err) {
|
|
347
|
+
* // Handle error.
|
|
348
|
+
* }
|
|
349
|
+
*
|
|
350
|
+
* console.log(userData);
|
|
351
|
+
* });
|
|
352
|
+
* @param {object} options Authorization code payload
|
|
353
|
+
* @param {string} options.organization Organization ID
|
|
354
|
+
* @param {string} options.code Code in URL returned after authentication
|
|
355
|
+
* @param {string} options.redirect_uri The URL to which Auth0 will redirect the browser after authorization has been granted by the user.
|
|
356
|
+
* @param {Function} cb Callback
|
|
357
|
+
* @returns {Promise|undefined}
|
|
358
|
+
*/
|
|
359
|
+
authorizationCodeGrant(options, cb) {
|
|
360
|
+
if (!options || typeof options !== 'object') {
|
|
361
|
+
throw new ArgumentError('Missing options object');
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const data = {
|
|
365
|
+
grant_type: 'authorization_code',
|
|
366
|
+
client_id: this.clientId,
|
|
367
|
+
client_secret: this.clientSecret,
|
|
368
|
+
...options,
|
|
369
|
+
};
|
|
388
370
|
|
|
389
|
-
|
|
371
|
+
if (!data.code || data.code.trim().length === 0) {
|
|
372
|
+
throw new ArgumentError('code field is required');
|
|
373
|
+
}
|
|
390
374
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
375
|
+
if (!data.redirect_uri || data.redirect_uri.trim().length === 0) {
|
|
376
|
+
throw new ArgumentError('redirect_uri field is required');
|
|
377
|
+
}
|
|
394
378
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
379
|
+
const params = {
|
|
380
|
+
type: 'token',
|
|
381
|
+
};
|
|
398
382
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
383
|
+
if (cb && cb instanceof Function) {
|
|
384
|
+
return this.oauthWithIDTokenValidation.create(params, data, cb);
|
|
385
|
+
}
|
|
402
386
|
|
|
403
|
-
|
|
404
|
-
return this.oauthWithIDTokenValidation.create(params, data, cb);
|
|
387
|
+
return this.oauthWithIDTokenValidation.create(params, data);
|
|
405
388
|
}
|
|
406
|
-
|
|
407
|
-
return this.oauthWithIDTokenValidation.create(params, data);
|
|
408
|
-
};
|
|
389
|
+
}
|
|
409
390
|
|
|
410
391
|
module.exports = OAuthAuthenticator;
|