I have following code in auth.js
let request = require("request");
function getToken(callback) {
let options = { method: 'POST',
url: 'https://testsite/openid-connect/token',
headers:
{
'content-type': 'application/x-www-form-urlencoded'
},
form:
{
grant_type: 'password',
username: 'admin',
password: 'password',
client_id: '123'
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
callback(body.access_token);
});
}
module.exports = {
getToken,
};
and I'm calling the method getToken from another index.js file as
let authServ = require('./auth');
const token = authServ.getToken();
console.log(token);
but I get "undefined" returned in variable "token" instead of the actual token. Can someone please help where I'm doing wrong?