How do I use the Management Client via a proxy server in "node-auth0 4.27.0"?

What should I do if I want to connect to Auth0’s “Management Client” via a proxy server I have set up myself?

Hi @xkinjyou, and welcome back to the Auth0 Community!

I will look into it and come back to you with what I found.

Thanks!
Teodor.

Hi again @xkinjyou!

You’ll need to configure the Auth0 Node.js SDK to use a custom HTTP agent that routes requests through your proxy. The easiest way to do this is with the https-proxy-agent library.

You’ll have to create an instance of the HttpsProxyAgent with your proxy server’s URL and pass it into the ManagementClient configuration.

Please try something like this:

import { ManagementClient } from 'auth0';
import { HttpsProxyAgent } from 'https-proxy-agent';

const proxyUrl = 'http://your-proxy-server.com:8080';

const proxyAgent = new HttpsProxyAgent(proxyUrl);

const management = new ManagementClient({
  domain: 'YOUR_AUTH0_DOMAIN',
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET',
  proxy: proxyAgent,
});

async function testConnection() {
  try {
    const users = await management.users.getAll({ per_page: 1 });
    console.log('Successfully fetched users via proxy.');
  } catch (error) {
    console.error('Error fetching users:', error);
  }
}

testConnection();

If your proxy server requires a username and password, include them in the URL like this: http://user:password@your-proxy-server.com:8080

I hope this helps!

Sincerely,
Teodor.