# TCPWrapper error during axios inside Auth0 post login action

**URL:** <https://community.auth0.com/t/tcpwrapper-error-during-axios-inside-auth0-post-login-action/72679>\
**Category:** Get Help\
**Created:** [November 5, 2021, 2:07pm UTC](https://community.auth0.com/t/tcpwrapper-error-during-axios-inside-auth0-post-login-action/72679 "2021-11-05T14:07:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonkofogeorge](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jasonkofogeorge/32/32809_2.png) [@jasonkofogeorge](https://community.auth0.com/u/jasonkofogeorge)\
**Post date:** [November 5, 2021, 2:07pm UTC](https://community.auth0.com/t/tcpwrapper-error-during-axios-inside-auth0-post-login-action/72679/1 "2021-11-05T14:07:05Z")

</div>

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):

```bash
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.

```plaintext
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) => {
// };

```

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 10, 2021, 12:44am UTC](https://community.auth0.com/t/tcpwrapper-error-during-axios-inside-auth0-post-login-action/72679/3 "2021-11-10T00:44:04Z")

</div>

Hi @jasonkofogeorge,

Welcome to the Auth0 Community!

From looking at the code snippets that you shared, it seems that you are trying to get a Management API Access Token in a Post Login Action.

After testing, I have managed to get the Management API to work in Actions with the following snippet:

```auto
exports.onExecutePostLogin = async (event, api) => {
  var axios = require("axios").default;
  var options = {
    method: 'POST',
    url: 'https://YOUR_DOMAIN.REGION.auth0.com/oauth/token',
    headers: {'content-type': 'application/json'},
    data: {
      grant_type: 'client_credentials',
      client_id: 'YOUR_CLIENT_ID',
      client_secret: 'YOUR_CLIENT_SECRET',
      audience: 'https://YOUR_DOMAIN.REGION.auth0.com/api/v2/'
      
    }
  };
  axios.request(options).then(function (response) {
    console.log("access token: ",response.data.access_token);
  }).catch(function (error) {
    console.error(error);
  });
}

```

I recommend that you give this a try and then append your custom error handling logic on top of this example.

Alternatively, you could follow this [How can I use the Management API in Actions?](https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947) FAQ which describes how to use the Management API with the [Management Client](https://auth0.github.io/node-auth0/module-management.ManagementClient.html).

Hoped this helps!

Please let me know if there are any other questions. I’d be glad to help.

Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 25, 2021, 12:44am UTC](https://community.auth0.com/t/tcpwrapper-error-during-axios-inside-auth0-post-login-action/72679/4 "2021-11-25T00:44:27Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
