Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
var btoa = require('btoa');
var Client = require('node-rest-client').Client;
const fs = require('fs');
const path = require('path');
var client = new Client({
connection: {
ca: fs.readFileSync(
path.join('ssl-certs/va-ca-cert/', 'VA-Internal-CHAINED.crt')
)
}
});
module.exports.getAccessToken = function() {
let fullAuthentication = 'Basic ' + btoa(process.env.BASIC_AUTH_USERNAME + ':' + process.env.BASIC_AUTH_PASSWORD);
let args = {
parameters: {
grant_type: process.env.GRANT_TYPE,
username: process.env.USER_NAME,
password: process.env.PASSWORD
},
headers: {
Authorization: fullAuthentication,
'Content-Type': 'application/json'
}
};
let makeRestCall = function() {
return new Promise(function(resolve, reject) {
client.post(
process.env.END_POINT_BASE_URI + process.env.TOKEN_REQUEST,
args,
function(data) {
if (data) {
resolve('Bearer ' + data['access_token']);
} else {
reject(error => {
console.log('Auth.js error ', error)
})
}
})
});
};
let promise = makeRestCall();
return promise;
};