I am trying to make a call to an inhouse API in order to embed data into JWTs that are issued from Auth0. However, I keep getting this error (courtesy of RealTime web task):
Error: connect ECONNREFUSED 127.0.0.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1133:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 443,
config: {
adapter: [Function: httpAdapter],
transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'axios/0.15.2',
'Content-Length': 218
},
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
method: 'POST',
url: 'https:/xxx.us.auth0.com/oauth/token',
data: '{"grant_type":"client_credentials","client_id":"xxx","client_secret":"xxx","audience":"xxx"}'
},
response: undefined
}
I can confirm that the url that gets hit is indeed the url for our Skynamo instance. Below is the code snippet that gave rise to the error.
const path = require("path");
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
const axios = require("axios");
// the base URL for the licensing server. This should be
// replaced with the production url
const auth0 = `https://${event.tenant.id}.us.auth0.com`;
const url = path.join(auth0, "oauth/token");
const audience = path.join(auth0, "api/v2/");
const options = {
method: "POST",
url: url,
headers: { "content-type": "application/x-www-form-urlencoded" },
data: {
grant_type: "client_credentials",
client_id: "xxx",
client_secret: "xxx",
audience: audience,
},
};
let data = null;
try {
data = (await axios.request(options)).data;
} catch (err) {
console.error(`Could not post to '${url}': ${err}`);
console.error(err);
return;
}
if (data === null) {
console.warn(`No data was found in request to '${url}`);
return;
}
const token = data["access_token"];
if (typeof token === "undefined") {
console.error(`token could not be found from data response: ${data}`);
return;
}
};
/**
* Handler that will be invoked when this action is resuming after an external redirect. If your
* onExecutePostLogin function does not perform a redirect, this function can be safely ignored.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
// exports.onContinuePostLogin = async (event, api) => {
// };