-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy path_sfAuthUserCredentials.js
More file actions
47 lines (38 loc) · 1.48 KB
/
_sfAuthUserCredentials.js
File metadata and controls
47 lines (38 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
// Initialize constants
const config = require('config');
// Include B2C Commerce API functions
const sfAuthenticate = require('../apis/sfdc/auth/_authUserCredentials');
/**
* @function _sfAuthUserCredentials
* @description Attempts to authenticate against the ST instance leveraging existing
* user credentials -- and returns the results of the request via the CLI.
*
* @param {Object} environmentDef Represents the already-validated environment details to use when performing the actions
* @returns {Promise} Returns the result of the authentication attempt
*/
module.exports = environmentDef => new Promise(async (resolve, reject) => {
// Roll-up the validation results to a single object
const output = {
apiCalls: {
sfAuthenticate: {
authResults: undefined,
error: undefined
}
},
outputDisplay: []
};
try {
// Audit the authorization token for future rest requests
output.apiCalls.sfAuthenticate.authResults = await sfAuthenticate(
environmentDef.sfLoginUrl,
environmentDef.sfUsername,
environmentDef.sfPassword,
environmentDef.sfSecurityToken);
// Output the result of the authentication attempt
output.outputDisplay.push(output.apiCalls.sfAuthenticate.authResults.accessToken);
resolve(output);
} catch (e) {
reject(`${config.get('errors.sf.unableToAuthenticate')}`);
}
});