auth0 / node-auth0

Node.js client library for the Auth0 platform.
MIT License
628 stars 307 forks source link

Proxy issue with auth0 npm package version 4.0.1 #955

Closed theshubhamshivhare closed 10 months ago

theshubhamshivhare commented 10 months ago

Checklist

Description

I am trying to use the auth0 NPM package v4.0.1 to export users from Auth0. However, I am encountering a proxy issue that prevents me from doing so. The issue only occurs when I use the latest version of the auth0 npm package (v4.0.1) and when I have VPN enabled. When I turn off the VPN, the issue is resolved. However, this is not a desirable solution as I want to use the latest version of the auth0 NPM package and keep our VPN on for security reasons.

I have tried to update my code to use httpsAgent, but it did not work either. I am still looking for other ways to fix the proxy issue with auth0 NPM package 4.0.1 and VPN.

The code is given below for your reference.

var ManagementClient = require('auth0').ManagementClient;
// import { HttpsProxyAgent } from 'https-proxy-agent';
var { HttpsProxyAgent } = require('https-proxy-agent')
var endpointProxy = 'http://genproxy:8080'
var agent = new HttpsProxyAgent(endpointProxy);

function backup() {
    var management = new ManagementClient({
        domain: '',
        clientId: '',
        clientSecret: '',
        agent: agent
    });
    var params = {
        name: ''
    };
    management.connections.getAll(params).then(data => {
        console.log(data)
    }).catch(err => {
        console.log(err)
    })
}
backup()

The image below shows the error that occurred.

Error Image

I would appreciate any guidance you can provide.

Reproduction

I have done the following steps: a) installed the auth0 v4.0.1 NPM package, b) coded to obtain the Auth0 Database Connection ID, and c) encountered a proxy issue that caused failure.

Additional context

No response

node-auth0 version

4.0.1

Node.js version

18.18.0

adamjmcgrath commented 10 months ago

Hi @theshubhamshivhare - native fetch doesn't support the https-proxy-agent package yet.

You'll need to use something like node-fetch for this to work, eg

var ManagementClient = require('auth0').ManagementClient;
var { HttpsProxyAgent } = require('https-proxy-agent')
var endpointProxy = 'http://genproxy:8080'
var agent = new HttpsProxyAgent(endpointProxy);
var nodeFetch = require('node-fetch'); // <= using v2 for cjs import

function backup() {
    var management = new ManagementClient({
        domain: '',
        clientId: '',
        clientSecret: '',
        agent: agent,
        fetch: nodeFetch // <= customize the SDK to use node-fetch instead of native
    });
    var params = {
        name: ''
    };
    management.connections.getAll(params).then(data => {
        console.log(data)
    }).catch(err => {
        console.log(err)
    })
}
backup()
adamjmcgrath commented 10 months ago

Closing as I believe https://github.com/auth0/node-auth0/issues/955#issuecomment-1764618775 answers your question