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,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var RestClient = require('rest-facade').Client;
|
|
5
|
-
var sanitizeArguments = require('../utils').sanitizeArguments;
|
|
1
|
+
const { ArgumentError } = require('rest-facade');
|
|
2
|
+
const RestClient = require('rest-facade').Client;
|
|
3
|
+
const { sanitizeArguments } = require('../utils');
|
|
6
4
|
|
|
7
5
|
function getParamsFromOptions(options) {
|
|
8
6
|
const params = {};
|
|
@@ -10,7 +8,7 @@ function getParamsFromOptions(options) {
|
|
|
10
8
|
return params;
|
|
11
9
|
}
|
|
12
10
|
if (options.forwardedFor) {
|
|
13
|
-
params._requestCustomizer = function(req) {
|
|
11
|
+
params._requestCustomizer = function (req) {
|
|
14
12
|
req.set('auth0-forwarded-for', options.forwardedFor);
|
|
15
13
|
};
|
|
16
14
|
}
|
|
@@ -18,283 +16,271 @@ function getParamsFromOptions(options) {
|
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
/**
|
|
21
|
-
* @class
|
|
22
19
|
* Handles authenticator with passwordless flows, e.g. SMS, Touch ID, etc.
|
|
23
|
-
* @constructor
|
|
24
|
-
* @memberOf module:auth
|
|
25
|
-
*
|
|
26
|
-
* @param {Object} options Authenticator options.
|
|
27
|
-
* @param {String} options.baseUrl The auth0 account URL.
|
|
28
|
-
* @param {String} [options.clientId] Default client ID.
|
|
29
|
-
* @param {String} [options.clientSecret] Default client secret.
|
|
30
|
-
* @param {OAuthAuthenticator} oauth OAuthAuthenticator instance.
|
|
31
20
|
*/
|
|
32
|
-
var PasswordlessAuthenticator = function(options, oauth) {
|
|
33
|
-
if (!options) {
|
|
34
|
-
throw new ArgumentError('Missing authenticator options');
|
|
35
|
-
}
|
|
36
21
|
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
class PasswordlessAuthenticator {
|
|
23
|
+
/**
|
|
24
|
+
* @param {object} options Authenticator options.
|
|
25
|
+
* @param {string} options.baseUrl The auth0 account URL.
|
|
26
|
+
* @param {string} [options.clientId] Default client ID.
|
|
27
|
+
* @param {string} [options.clientSecret] Default client secret.
|
|
28
|
+
* @param {OAuthAuthenticator} oauth OAuthAuthenticator instance.
|
|
29
|
+
*/
|
|
30
|
+
constructor(options, oauth) {
|
|
31
|
+
if (!options) {
|
|
32
|
+
throw new ArgumentError('Missing authenticator options');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof options !== 'object') {
|
|
36
|
+
throw new ArgumentError('The authenticator options must be an object');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Options object for the Rest Client instance.
|
|
41
|
+
*
|
|
42
|
+
* @type {object}
|
|
43
|
+
*/
|
|
44
|
+
const clientOptions = {
|
|
45
|
+
errorFormatter: { message: 'message', name: 'error' },
|
|
46
|
+
headers: options.headers,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
this.oauth = oauth;
|
|
50
|
+
this.passwordless = new RestClient(`${options.baseUrl}/passwordless/start`, clientOptions);
|
|
51
|
+
this.clientId = options.clientId;
|
|
52
|
+
this.clientSecret = options.clientSecret;
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
/**
|
|
42
|
-
*
|
|
56
|
+
* Sign in with the given user credentials.
|
|
57
|
+
*
|
|
58
|
+
* @example <caption>
|
|
59
|
+
* Once you have a verification code, use this endpoint to login
|
|
60
|
+
* the user with their phone number/email and verification code.
|
|
61
|
+
*
|
|
62
|
+
* https://auth0.com/docs/api/authentication#authenticate-user
|
|
63
|
+
* </caption>
|
|
64
|
+
*
|
|
65
|
+
* var data = {
|
|
66
|
+
* username: '{PHONE_NUMBER OR EMAIL}',
|
|
67
|
+
* otp: '{VERIFICATION_CODE}',
|
|
68
|
+
* realm: '{sms or email}' // OPTIONAL DEFAULTS TO SMS
|
|
69
|
+
* };
|
|
70
|
+
*
|
|
71
|
+
* auth0.passwordless.signIn(data, function (err) {
|
|
72
|
+
* if (err) {
|
|
73
|
+
* // Handle error.
|
|
74
|
+
* }
|
|
75
|
+
* });
|
|
76
|
+
* @example <caption>
|
|
77
|
+
* The user data object has the following structure.
|
|
78
|
+
* </caption>
|
|
79
|
+
*
|
|
80
|
+
* {
|
|
81
|
+
* id_token: String,
|
|
82
|
+
* access_token: String,
|
|
83
|
+
* token_type: String
|
|
84
|
+
* }
|
|
85
|
+
* @example <caption>
|
|
86
|
+
* LEGACY signIn using the `/oauth/ro` endpoint. When otp is not specified
|
|
87
|
+
* password is required. Given the user credentials (`phone_number` and `code`),
|
|
88
|
+
* it will do the authentication on the provider and return a JSON with
|
|
89
|
+
* the `access_token` and `id_token`.
|
|
90
|
+
*
|
|
91
|
+
* https://auth0.com/docs/api/authentication#resource-owner
|
|
92
|
+
* </caption>
|
|
43
93
|
*
|
|
44
|
-
*
|
|
94
|
+
* var data = {
|
|
95
|
+
* username: '{PHONE_NUMBER}',
|
|
96
|
+
* password: '{VERIFICATION_CODE}'
|
|
97
|
+
* };
|
|
98
|
+
*
|
|
99
|
+
* auth0.passwordless.signIn(data, function (err) {
|
|
100
|
+
* if (err) {
|
|
101
|
+
* // Handle error.
|
|
102
|
+
* }
|
|
103
|
+
* });
|
|
104
|
+
* @param {object} userData User credentials object.
|
|
105
|
+
* @param {string} userData.username The user's phone number if realm=sms, or the user's email if realm=email
|
|
106
|
+
* @param {string} userData.otp The user's verification code. Required
|
|
107
|
+
* @param {string} [userData.audience] API Identifier of the API for which you want to get an Access Token.
|
|
108
|
+
* @param {string} [userData.realm=sms] Realm string: "sms" or "email".
|
|
109
|
+
* @param {string} [userData.password] [DEPRECATED] Password required if using legacy /oauth/ro endpoint
|
|
110
|
+
* @param {string} [userData.connection=sms] [DEPRECATED] Connection string: "sms" or "email".
|
|
111
|
+
* @param {object} [options] Additional options.
|
|
112
|
+
* @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
113
|
+
* @param {Function} [cb] Method callback.
|
|
114
|
+
* @returns {Promise|undefined}
|
|
45
115
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
headers: options.headers
|
|
49
|
-
};
|
|
116
|
+
signIn(userData, options, cb) {
|
|
117
|
+
const { options: sanitizedOptions, cb: sanitizedCb } = sanitizeArguments(options, cb);
|
|
50
118
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.clientSecret = options.clientSecret;
|
|
55
|
-
};
|
|
119
|
+
if (!userData || typeof userData !== 'object') {
|
|
120
|
+
throw new ArgumentError('Missing user data object');
|
|
121
|
+
}
|
|
56
122
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* @example <caption>
|
|
63
|
-
* Once you have a verification code, use this endpoint to login
|
|
64
|
-
* the user with their phone number/email and verification code.
|
|
65
|
-
*
|
|
66
|
-
* https://auth0.com/docs/api/authentication#authenticate-user
|
|
67
|
-
* </caption>
|
|
68
|
-
*
|
|
69
|
-
* var data = {
|
|
70
|
-
* username: '{PHONE_NUMBER OR EMAIL}',
|
|
71
|
-
* otp: '{VERIFICATION_CODE}',
|
|
72
|
-
* realm: '{sms or email}' // OPTIONAL DEFAULTS TO SMS
|
|
73
|
-
* };
|
|
74
|
-
*
|
|
75
|
-
* auth0.passwordless.signIn(data, function (err) {
|
|
76
|
-
* if (err) {
|
|
77
|
-
* // Handle error.
|
|
78
|
-
* }
|
|
79
|
-
* });
|
|
80
|
-
*
|
|
81
|
-
* @example <caption>
|
|
82
|
-
* The user data object has the following structure.
|
|
83
|
-
* </caption>
|
|
84
|
-
*
|
|
85
|
-
* {
|
|
86
|
-
* id_token: String,
|
|
87
|
-
* access_token: String,
|
|
88
|
-
* token_type: String
|
|
89
|
-
* }
|
|
90
|
-
*
|
|
91
|
-
* @example <caption>
|
|
92
|
-
* LEGACY signIn using the `/oauth/ro` endpoint. When otp is not specified
|
|
93
|
-
* password is required. Given the user credentials (`phone_number` and `code`),
|
|
94
|
-
* it will do the authentication on the provider and return a JSON with
|
|
95
|
-
* the `access_token` and `id_token`.
|
|
96
|
-
*
|
|
97
|
-
* https://auth0.com/docs/api/authentication#resource-owner
|
|
98
|
-
* </caption>
|
|
99
|
-
*
|
|
100
|
-
* var data = {
|
|
101
|
-
* username: '{PHONE_NUMBER}',
|
|
102
|
-
* password: '{VERIFICATION_CODE}'
|
|
103
|
-
* };
|
|
104
|
-
*
|
|
105
|
-
* auth0.passwordless.signIn(data, function (err) {
|
|
106
|
-
* if (err) {
|
|
107
|
-
* // Handle error.
|
|
108
|
-
* }
|
|
109
|
-
* });
|
|
110
|
-
*
|
|
111
|
-
* @param {Object} userData User credentials object.
|
|
112
|
-
* @param {String} userData.username The user's phone number if realm=sms, or the user's email if realm=email
|
|
113
|
-
* @param {String} userData.otp The user's verification code. Required
|
|
114
|
-
* @param {String} [userData.realm=sms] Realm string: "sms" or "email".
|
|
115
|
-
* @param {String} [userData.password] [DEPRECATED] Password required if using legacy /oauth/ro endpoint
|
|
116
|
-
* @param {String} [userData.connection=sms] [DEPRECATED] Connection string: "sms" or "email".
|
|
117
|
-
* @param {Object} [options] Additional options.
|
|
118
|
-
* @param {String} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
119
|
-
* @param {Function} [cb] Method callback.
|
|
120
|
-
*
|
|
121
|
-
* @return {Promise|undefined}
|
|
122
|
-
*/
|
|
123
|
-
PasswordlessAuthenticator.prototype.signIn = function(userData, options, cb) {
|
|
124
|
-
var { options, cb } = sanitizeArguments(options, cb);
|
|
125
|
-
var defaultFields = {
|
|
126
|
-
client_id: this.clientId,
|
|
127
|
-
client_secret: this.clientSecret
|
|
128
|
-
};
|
|
129
|
-
var data = extend(defaultFields, userData);
|
|
123
|
+
const data = {
|
|
124
|
+
client_id: this.clientId,
|
|
125
|
+
client_secret: this.clientSecret,
|
|
126
|
+
...userData,
|
|
127
|
+
};
|
|
130
128
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
if (typeof data.username !== 'string' || data.username.trim().length === 0) {
|
|
130
|
+
throw new ArgumentError('username field (phone number) is required');
|
|
131
|
+
}
|
|
134
132
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
// If otp is provided, attempt to sign in using otp grant
|
|
134
|
+
if (typeof data.otp === 'string' && data.otp.trim().length > 0) {
|
|
135
|
+
if (!data.realm || (data.realm !== 'email' && data.realm !== 'sms')) {
|
|
136
|
+
data.realm = 'sms';
|
|
137
|
+
}
|
|
138
|
+
data.grant_type = 'http://auth0.com/oauth/grant-type/passwordless/otp';
|
|
139
|
+
return this.oauth.signIn(data, { type: 'token', ...sanitizedOptions }, sanitizedCb);
|
|
140
|
+
}
|
|
138
141
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
data.realm = 'sms';
|
|
142
|
+
// Don't let the user override the connection nor the grant type.
|
|
143
|
+
if (!data.connection || (data.connection !== 'email' && data.connection !== 'sms')) {
|
|
144
|
+
data.connection = 'sms';
|
|
143
145
|
}
|
|
144
|
-
data.grant_type = '
|
|
145
|
-
return this.oauth.signIn(data, extend({ type: 'token' }, options), cb);
|
|
146
|
-
}
|
|
146
|
+
data.grant_type = 'password';
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
data.grant_type = 'password';
|
|
148
|
+
if (typeof data.password !== 'string' || data.password.trim().length === 0) {
|
|
149
|
+
throw new ArgumentError('password field (verification code) is required');
|
|
150
|
+
}
|
|
153
151
|
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
console.warn(
|
|
153
|
+
'The oauth/ro endpoint has been deprecated. Please use the realm and otp parameters in this function.'
|
|
154
|
+
);
|
|
155
|
+
return this.oauth.signIn(data, sanitizedOptions, sanitizedCb);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Start passwordless flow sending an email.
|
|
160
|
+
*
|
|
161
|
+
* @example <caption>
|
|
162
|
+
* Given the user `email` address, it will send an email with:
|
|
163
|
+
*
|
|
164
|
+
* <ul>
|
|
165
|
+
* <li>A link (default, `send:"link"`). You can then authenticate with this
|
|
166
|
+
* user opening the link and he will be automatically logged in to the
|
|
167
|
+
* application. Optionally, you can append/override parameters to the link
|
|
168
|
+
* (like `scope`, `redirect_uri`, `protocol`, `response_type`, etc.) using
|
|
169
|
+
* `authParams` object.
|
|
170
|
+
* </li>
|
|
171
|
+
* <li>
|
|
172
|
+
* A verification code (`send:"code"`). You can then authenticate with
|
|
173
|
+
* this user using the `/oauth/ro` endpoint specifying `email` as
|
|
174
|
+
* `username` and `code` as `password`.
|
|
175
|
+
* </li>
|
|
176
|
+
* </ul>
|
|
177
|
+
*
|
|
178
|
+
* Find more information in the
|
|
179
|
+
* <a href="https://auth0.com/docs/auth-api#!#post--with_email">API Docs</a>
|
|
180
|
+
* </caption>
|
|
181
|
+
*
|
|
182
|
+
* var data = {
|
|
183
|
+
* email: '{EMAIL}',
|
|
184
|
+
* send: 'link',
|
|
185
|
+
* authParams: {} // Optional auth params.
|
|
186
|
+
* };
|
|
187
|
+
*
|
|
188
|
+
* auth0.passwordless.sendEmail(data, function (err) {
|
|
189
|
+
* if (err) {
|
|
190
|
+
* // Handle error.
|
|
191
|
+
* }
|
|
192
|
+
* });
|
|
193
|
+
* @param {object} userData User account data.
|
|
194
|
+
* @param {string} userData.email User email address.
|
|
195
|
+
* @param {string} userData.send The type of email to be sent.
|
|
196
|
+
* @param {object} [options] Additional options.
|
|
197
|
+
* @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
198
|
+
* @param {Function} [cb] Method callback.
|
|
199
|
+
* @returns {Promise|undefined}
|
|
200
|
+
*/
|
|
201
|
+
sendEmail(userData, options, cb) {
|
|
202
|
+
const { options: sanitizedOptions, cb: sanitizedCb } = sanitizeArguments(options, cb);
|
|
203
|
+
const data = {
|
|
204
|
+
client_id: this.clientId,
|
|
205
|
+
client_secret: this.clientSecret,
|
|
206
|
+
...userData,
|
|
207
|
+
};
|
|
208
|
+
const params = getParamsFromOptions(sanitizedOptions);
|
|
163
209
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
*
|
|
167
|
-
* @method sendEmail
|
|
168
|
-
* @memberOf module:auth.PasswordlessAuthenticator.prototype
|
|
169
|
-
* @example <caption>
|
|
170
|
-
* Given the user `email` address, it will send an email with:
|
|
171
|
-
*
|
|
172
|
-
* <ul>
|
|
173
|
-
* <li>A link (default, `send:"link"`). You can then authenticate with this
|
|
174
|
-
* user opening the link and he will be automatically logged in to the
|
|
175
|
-
* application. Optionally, you can append/override parameters to the link
|
|
176
|
-
* (like `scope`, `redirect_uri`, `protocol`, `response_type`, etc.) using
|
|
177
|
-
* `authParams` object.
|
|
178
|
-
* </li>
|
|
179
|
-
* <li>
|
|
180
|
-
* A verification code (`send:"code"`). You can then authenticate with
|
|
181
|
-
* this user using the `/oauth/ro` endpoint specifying `email` as
|
|
182
|
-
* `username` and `code` as `password`.
|
|
183
|
-
* </li>
|
|
184
|
-
* </ul>
|
|
185
|
-
*
|
|
186
|
-
* Find more information in the
|
|
187
|
-
* <a href="https://auth0.com/docs/auth-api#!#post--with_email">API Docs</a>
|
|
188
|
-
* </caption>
|
|
189
|
-
*
|
|
190
|
-
* var data = {
|
|
191
|
-
* email: '{EMAIL}',
|
|
192
|
-
* send: 'link',
|
|
193
|
-
* authParams: {} // Optional auth params.
|
|
194
|
-
* };
|
|
195
|
-
*
|
|
196
|
-
* auth0.passwordless.sendEmail(data, function (err) {
|
|
197
|
-
* if (err) {
|
|
198
|
-
* // Handle error.
|
|
199
|
-
* }
|
|
200
|
-
* });
|
|
201
|
-
*
|
|
202
|
-
* @param {Object} userData User account data.
|
|
203
|
-
* @param {String} userData.email User email address.
|
|
204
|
-
* @param {String} userData.send The type of email to be sent.
|
|
205
|
-
* @param {Object} [options] Additional options.
|
|
206
|
-
* @param {String} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
207
|
-
* @param {Function} [cb] Method callback.
|
|
208
|
-
*
|
|
209
|
-
* @return {Promise|undefined}
|
|
210
|
-
*/
|
|
211
|
-
PasswordlessAuthenticator.prototype.sendEmail = function(userData, options, cb) {
|
|
212
|
-
var { options, cb } = sanitizeArguments(options, cb);
|
|
213
|
-
var defaultFields = {
|
|
214
|
-
client_id: this.clientId,
|
|
215
|
-
client_secret: this.clientSecret
|
|
216
|
-
};
|
|
217
|
-
var params = getParamsFromOptions(options);
|
|
218
|
-
var data = extend(defaultFields, userData);
|
|
210
|
+
// Don't let the user override the connection nor the grant type.
|
|
211
|
+
data.connection = 'email';
|
|
219
212
|
|
|
220
|
-
|
|
221
|
-
|
|
213
|
+
if (!userData || typeof userData !== 'object') {
|
|
214
|
+
throw new ArgumentError('Missing user data object');
|
|
215
|
+
}
|
|
222
216
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
217
|
+
if (typeof data.email !== 'string' || data.email.trim().length === 0) {
|
|
218
|
+
throw new ArgumentError('email field is required');
|
|
219
|
+
}
|
|
226
220
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
221
|
+
if (typeof data.send !== 'string' || data.send.trim().length === 0) {
|
|
222
|
+
throw new ArgumentError('send field is required');
|
|
223
|
+
}
|
|
230
224
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
225
|
+
if (sanitizedCb && sanitizedCb instanceof Function) {
|
|
226
|
+
return this.passwordless.create(params, data, sanitizedCb);
|
|
227
|
+
}
|
|
234
228
|
|
|
235
|
-
|
|
236
|
-
return this.passwordless.create(params, data, cb);
|
|
229
|
+
return this.passwordless.create(params, data);
|
|
237
230
|
}
|
|
238
231
|
|
|
239
|
-
|
|
240
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Start passwordless flow sending an SMS.
|
|
234
|
+
*
|
|
235
|
+
* @example <caption>
|
|
236
|
+
* Given the user `phone_number`, it will send a SMS message with a
|
|
237
|
+
* verification code. You can then authenticate with this user using the
|
|
238
|
+
* `/oauth/ro` endpoint specifying `phone_number` as `username` and `code` as
|
|
239
|
+
* `password`:
|
|
240
|
+
* </caption>
|
|
241
|
+
*
|
|
242
|
+
* var data = {
|
|
243
|
+
* phone_number: '{PHONE}'
|
|
244
|
+
* };
|
|
245
|
+
*
|
|
246
|
+
* auth0.passwordless.sendSMS(data, function (err) {
|
|
247
|
+
* if (err) {
|
|
248
|
+
* // Handle error.
|
|
249
|
+
* }
|
|
250
|
+
* });
|
|
251
|
+
* @param {object} userData User account data.
|
|
252
|
+
* @param {string} userData.phone_number User phone number.
|
|
253
|
+
* @param {object} [options] Additional options.
|
|
254
|
+
* @param {string} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
255
|
+
* @param {Function} [cb] Method callback.
|
|
256
|
+
* @returns {Promise|undefined}
|
|
257
|
+
*/
|
|
258
|
+
sendSMS(userData, options, cb) {
|
|
259
|
+
const { options: sanitizedOptions, cb: sanitizedCb } = sanitizeArguments(options, cb);
|
|
260
|
+
const data = {
|
|
261
|
+
client_id: this.clientId,
|
|
262
|
+
client_secret: this.clientSecret,
|
|
263
|
+
...userData,
|
|
264
|
+
};
|
|
265
|
+
const params = getParamsFromOptions(sanitizedOptions);
|
|
241
266
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
*
|
|
245
|
-
* @method sendSMS
|
|
246
|
-
* @memberOf module:auth.PasswordlessAuthenticator.prototype
|
|
247
|
-
*
|
|
248
|
-
* @example <caption>
|
|
249
|
-
* Given the user `phone_number`, it will send a SMS message with a
|
|
250
|
-
* verification code. You can then authenticate with this user using the
|
|
251
|
-
* `/oauth/ro` endpoint specifying `phone_number` as `username` and `code` as
|
|
252
|
-
* `password`:
|
|
253
|
-
* </caption>
|
|
254
|
-
*
|
|
255
|
-
* var data = {
|
|
256
|
-
* phone_number: '{PHONE}'
|
|
257
|
-
* };
|
|
258
|
-
*
|
|
259
|
-
* auth0.passwordless.sendSMS(data, function (err) {
|
|
260
|
-
* if (err) {
|
|
261
|
-
* // Handle error.
|
|
262
|
-
* }
|
|
263
|
-
* });
|
|
264
|
-
*
|
|
265
|
-
* @param {Object} userData User account data.
|
|
266
|
-
* @param {String} userData.phone_number User phone number.
|
|
267
|
-
* @param {Object} [options] Additional options.
|
|
268
|
-
* @param {String} [options.forwardedFor] Value to be used for auth0-forwarded-for header
|
|
269
|
-
* @param {Function} [cb] Method callback.
|
|
270
|
-
*
|
|
271
|
-
* @return {Promise|undefined}
|
|
272
|
-
*/
|
|
273
|
-
PasswordlessAuthenticator.prototype.sendSMS = function(userData, options, cb) {
|
|
274
|
-
var { options, cb } = sanitizeArguments(options, cb);
|
|
275
|
-
var defaultFields = {
|
|
276
|
-
client_id: this.clientId,
|
|
277
|
-
client_secret: this.clientSecret
|
|
278
|
-
};
|
|
279
|
-
var params = getParamsFromOptions(options);
|
|
280
|
-
var data = extend(defaultFields, userData);
|
|
267
|
+
// Don't let the user override the connection nor the grant type.
|
|
268
|
+
data.connection = 'sms';
|
|
281
269
|
|
|
282
|
-
|
|
283
|
-
|
|
270
|
+
if (!userData || typeof userData !== 'object') {
|
|
271
|
+
throw new ArgumentError('Missing user data object');
|
|
272
|
+
}
|
|
284
273
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
274
|
+
if (typeof data.phone_number !== 'string' || data.phone_number.trim().length === 0) {
|
|
275
|
+
throw new ArgumentError('phone_number field is required');
|
|
276
|
+
}
|
|
288
277
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
278
|
+
if (sanitizedCb && sanitizedCb instanceof Function) {
|
|
279
|
+
return this.passwordless.create(params, data, sanitizedCb);
|
|
280
|
+
}
|
|
292
281
|
|
|
293
|
-
|
|
294
|
-
return this.passwordless.create(params, data, cb);
|
|
282
|
+
return this.passwordless.create(params, data);
|
|
295
283
|
}
|
|
296
|
-
|
|
297
|
-
return this.passwordless.create(params, data);
|
|
298
|
-
};
|
|
284
|
+
}
|
|
299
285
|
|
|
300
286
|
module.exports = PasswordlessAuthenticator;
|