For development purposes, how can I call my local web api from auth0 rule

For development purposes, I want to call my local web api from auth0 rule. The error I get is (pulled from rules logs) -
Error: getaddrinfo ENOTFOUND my-web-api-1.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
errno: ‘ENOTFOUND’,
code: ‘ENOTFOUND’,

My api has been configured for authentication in auth0. I get the access token and use this token to make the api call.
Here is my rule script -

function (user, context, callback) {
  const axios = require('axios');
  //Request the access token
  const options = { method: 'POST',
    url: `https://${auth0.domain}/oauth/token`,
    headers: { 'content-type': 'application/json' },
    data: `{"client_id":"${configuration.RULE_APP_CLIENT_ID}","client_secret":"${configuration.RULE_APP_CLIENT_SECRET}","audience":"https://my-web-api-1.com","grant_type":"client_credentials"}` };
  axios(options)
    .then( res => {
      const access_token = res.data.access_token;
      const apiCallOpts = { method: 'GET',
                            url: 'https://my-web-api-1.com/<path>',
                            headers: { authorization: `Bearer ${access_token}`}
                          };
      axios(apiCallOpts).then(apiRes => {
        console.log(apiRes);
      }).catch( err => {
      		console.log(err);
    	});
    return callback(null, user, context);
    })
    .catch( err => {
      console.log(err);
    });  
}

NOTE: In my dev environment (windows 10) I did create inbound rules for the IP addresses mentioned here Auth0 IP Addresses for Allow Lists for US region.

It looks like this error is stating that the URL provided cannot be resolved, or doesn’t exist.

https://my-web-api-1.com

Thank you for your reply. I have created the entry in my host file as follows -

127.0.0.1 my-web-api-1.com

Is this approach valid for development purposes? Or do I have to publish my api to a publically accessible url?

The rule is running in a container in the cloud, so yes, it needs to accessible from there. The host file is like a static DNS for your machine IIRC.

Sounds good! Thank you Dan!

1 Like

No problem. Let us know if you have any other questions.

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