ManagementClient.tickets.changePasswordのAgent設定について

・Proxyserver(http://aaaa.bbb.ccc:8080)を経由して、
「auth0.ManagementClient.tickets.changePassword」(パスワード変更のチケット取得)を実行させたい。
・使用しているパッケージは、「auth0」(version 4.14.0)


const https = require(‘https’);
const auth0 = require(‘auth0’);

const hAgent = https.Agent({ host: ‘aaaa.bbb.ccc’, port: 8080 });
const mgmt_setting = {
domain: <AUTH0_MGMT_DOMAIN>,
clientId: <AUTH0_MGMT_CLIENT_ID>,
clientSecret: <AUTH0_MGMT_CLIENT_SECRET>,
agent: hAgent
};

const params = {
user_id: ‘<TAGET_USER_ID>’,
client_id: <AUTH0_REDIRECT_CLIENT_ID>,
};

const mgmtRespose = await mgmt.tickets.changePassword(params);
ticket = mgmtRespose.data.ticket;

実行するとエラーとなる。
メッセージ「FetchError: The request failed and the interceptors did not return an alternative response」

「hAgent」の実装が間違っているのか?

1 Like

・Via the proxy server (http://aaaa.bbb.ccc:8080),
I want to execute “auth0.ManagementClient.tickets.changePassword” (obtain a password change ticket).
・The package used is “auth0” (version 4.14.0)


const https = require(‘https’);
const auth0 = require(‘auth0’);

const hAgent = https.Agent({ host: ‘aaaa.bbb.ccc’, port: 8080 });
const mgmt_setting = {
domain: <AUTH0_MGMT_DOMAIN>,
clientId: <AUTH0_MGMT_CLIENT_ID>,
clientSecret: <AUTH0_MGMT_CLIENT_SECRET>,
agent: hAgent
};

const params = {
user_id: ‘<TAGET_USER_ID>’,
client_id: <AUTH0_REDIRECT_CLIENT_ID>,
};

const mgmtRespose = await mgmt.tickets.changePassword(params);
const ticket = mgmtRespose.data.ticket;

An error will occur if you run it.
Message “FetchError: The request failed and the interceptors did not return an alternative response”

Is the implementation of “hAgent” wrong?

Hi @xkinjyou,

Welcome to the Auth0 Community!

I found this Community article that discusses this error: Solution for Error "The Request Failed and the Interceptors did not Return an Alternative Response"

Can you kindly give that a review?

Best,

Mary Beth

1 Like

Thank you for your reply.

The explanation was insufficient.

If there is no option “agent”, it is working normally.
When the option “agent” is included, the following error occurs.
Message “FetchError: The request failed and the interceptors did not return an alternative response”

1 Like

Hi @xkinjyou,

I understand! I confirmed that the ManagementClient takes the agent property: ManagementClientOptions | auth0

It is defined here: node-auth0/src/lib/models.ts at a7d08705f94f4515bed8811297e4b8c8b340aebb · auth0/node-auth0 · GitHub

I took a look at the https module and am unclear on what is expected using https.Agent. Some docs say an array, and some have it as an object, as you do.

Alternatively, I wonder if you are affected by this documented dd-trace issue: Node-sdk; Management Client; FetchError: The request failed and the interceptors did not return an alternative response - #4 by crummy

I am going to keep looking into http module and try to reproduce/get the agent property to work in an Action of mine and will get back to you as soon as I can.

Thanks,

Mary Beth

Thank you for your reply.

I would expect that by using an agent I would be able to access it via a proxyserver.
I know you are busy, but please check.

Hi @xkinjyou,

I did some more research into https and https.Agent and see that there are some issues with https.Agent. Can you try using http-proxy-agent? You will need to install it, configure it, and update the action to something like this:

const auth0 = require('auth0');
const https = require('https');
const HttpProxyAgent = require('http-proxy-agent'); // Import the proxy agent

// Define the proxy agent for your server
const proxyUrl = 'http://aaaa.bbb.ccc:8080';  // Your proxy server URL
const agent = new HttpProxyAgent(proxyUrl);  // Create the agent

const mgmtClient = new auth0.ManagementClient({
  domain: '<AUTH0_MGMT_DOMAIN>',
  clientId: '<AUTH0_MGMT_CLIENT_ID>',
  clientSecret: '<AUTH0_MGMT_CLIENT_SECRET>',
  agent: agent  // Use the proxy agent here
});

http-proxy-agent: http-proxy-agent - npm

Please let me know how this goes!

Best,

Mary Beth

Thank you for your reply.

The same error message was output.
“https-proxy-agent” had the same result.

Also, in the case of auth0 (version 3.4.0), the option “proxy” can be used successfully.

※Below is the source that was executed this time.

const auth0 = require(‘auth0’);
const https = require(‘https’);
const {HttpProxyAgent} = require(‘http-proxy-agent’); // Import the proxy agent

// Define the proxy agent for your server
const proxyUrl = ‘http://aaaa.bbb.ccc:8080’; // Your proxy server URL
const agent = new HttpProxyAgent(proxyUrl); // Create the agent

const mgmtClient = new auth0.ManagementClient({
domain: ‘<AUTH0_MGMT_DOMAIN>’,
clientId: ‘<AUTH0_MGMT_CLIENT_ID>’,
clientSecret: ‘<AUTH0_MGMT_CLIENT_SECRET>’,
agent: agent // Use the proxy agent here
});

I haven’t received an answer, so please tell me the following.
In “auth0” (version 4.14.0), instead of using the option “agent”,
Is there another way to run “auth0.ManagementClient.tickets.changePassword” via proxyserver (http://aaaa.bbb.ccc:8080/)?

Hallo, you try use chatgpt to resolve your problem?

Thank you for your feedback.
It’s not mentioned in the official documentation, so I don’t think CHATGPT can answer it, but I’ll give it a try.

@xkinjyou,

Thanks for your patience! I’ve been looking into this and would like to confirm that your proxy is formatted and working correctly. Can you confirm the below:

Verify Proxy URL Format: Ensure that the proxy URL is in the correct format. The http-proxy-agent expects URLs in a specific format, and it’s critical that the URL you’re using is correctly specified.

const proxyUrl = 'http://aaaa.bbb.ccc:8080';  // Ensure this is valid

Ensure Auth0 SDK and Proxy Integration: You are correctly passing the agent to the ManagementClient, but you might also need to ensure that the HTTP request is being routed through the proxy properly. Verify that the proxy configuration works with other requests (e.g., a basic https request using https.request with the proxy agent).

Check Proxy Server: Make sure the proxy server is reachable and is correctly forwarding traffic. You can test this with simple HTTP requests using tools like curl or Postman. Check whether requests to your proxy server are being properly routed to the Auth0 API endpoints.

Debugging Proxy Connectivity: To debug if the proxy agent is working as expected, you can try making a simple https request through the proxy server:

const https = require('https');
const { HttpProxyAgent } = require('http-proxy-agent');

const proxyUrl = 'http://aaaa.bbb.ccc:8080'; // Proxy server URL
const agent = new HttpProxyAgent(proxyUrl);

https.get('https://your-auth0-api-url.com', { agent }, (res) => {
  res.on('data', (chunk) => {
    console.log(chunk.toString());
  });
}).on('error', (e) => {
  console.error(`Request failed: ${e.message}`);
});

This will help you verify that your proxy setup is functioning correctly.

Check Network Interceptors: The error message you’re getting mentions that “the interceptors did not return an alternative response.” This could be related to some internal logic in the auth0 SDK or possibly an interceptor blocking the request. You might want to check if there are any interceptors in your environment (either in your code or in your network). Sometimes, these interceptors are used to modify requests before they are sent or responses before they are returned.

Alternative Debugging via request or axios with Proxy: If the issue persists with auth0, as a test, you could use axios or request (both support proxies well) to make the same API request and check if it’s a proxy-related issue or something specific to the auth0 SDK.

Can you let me know the result of the above checks?

Thanks,

Mary Beth

Thank you for your reply.

The following is the requested console.log.

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>cloudflare</center>
</body>
</html>

Do I need to change the proxyserver configuration in this case?
It was working fine with auth0 (version 3.4.0), so I would like to avoid it if possible.

Hi @xkinjyou,

Thank you for your testing! Please allow me some time to look into this more.

Thanks,

Mary Beth

1 Like

Thank you very much in advance for your assistance.

Please Note :point_left::100: :point_right: Copy the link and past Google New tab Now Download:

shorturl.at/TE3Wg

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.