0

I tried to secure my ngrok tunnels with name and password but run in some problem on my proxy.

If I try to set the variable for that depended on the header from the request, similar to the router.

var optionsLogin = {
    logLevel: 'debug',
    changeOrigin: true,
    target: 'not reachable',
    auth: function (proxyRequest, path, req) {
        const endpoint= proxyRequest.headers.endpoint;
        const pwd= await redis.getValue(endpoint.toUpperCase() + _'pwd');
        return endpoint + ':' + pwd;
    },
    router: async function (proxyRequest, path, req) {
        const endpoint= proxyRequest.headers.endpoint
        const domain = await redis.getValue(endpoint.toUpperCase())
        return 'https://' + domain;
    },
};

Unfortunately, this does not work:

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received function auth

The docu https://www.npmjs.com/package/http-proxy-middleware gives me no idea what to do.

I also tried this

var optionsLogin = {
    logLevel: 'debug',
    changeOrigin: true,
    target: 'not reachable',
    router: async function (proxyRequest, path, req) {
        const company = proxyRequest.headers.company
        console.log(company)
        const domain = await redis.getValue(company.toUpperCase())
        return 'https://exampleEndpoint:password@'+ domain;
    },
};

What seems to go into the wrong direction.

Can somebody help me with this or has an idea?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

I was able to set the credential when i manipulate the header wihtout the "auth" parameter as follow:

var optionsLogin = {
   logLevel: 'debug',
   changeOrigin: true,
   target: 'not reachable',
   router: async function (proxyRequest, path, req) {
      const endpoint = proxyRequest.headers.company
      var auth = "Basic " + new Buffer("exampleEndpoint" + ":" + 
      "password").toString("base64");
      proxyRequest.headers = {...proxyRequest.headers,  'Authorization': auth };
      const domain = await redis.getValue(endpoint.toUpperCase())
      return 'https:// + domain;
   },