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.