-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proxyUrl option doesn't work behind a corporate proxy #6527
Comments
cc @Robbie-Microsoft @bgavrilMS Can you folks check this? |
Hi @rasulsafa - if you just use https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/msal-node-samples/custom-INetworkModule-and-network-tracing/HttpClientAxios.ts object (no MSAL), can you use it to make a call to https://login.microsoftonline.com/b458eb0a-178f-4197-8da4-514c0fe6f17b/v2.0/.well-known/openid-configuration ? This extensibility point gives you full control over the HTTP stack, so it's up to you to set it in such a way as to take into account the proxy. |
Similar issue #6483 |
Hi @bgavrilMS, I was not able to get it working with an Axios-based custom networkClient. It appears proxy support on Axios is also currently bugged as well. I was however able to make it work with node-fetch and https-proxy-agent as outlined in my original message |
Thanks for the summary @rasulsafa. Much appreciated that you provided the implementation that works for you. Can you link the Graph SDK API on this please? I will mark this as a bug then, to update the implementation to use |
What version of axios did you use when you tried this sample? It appears our samples use either 1.4.0 or 1.3.4. Other users have been able to get the axios implementation working before. For insight, we switched to manually writing http requests through the socket because we didn't want to rely on 3rd party libraries. If it supports proxies, we would like to switch to node's native fetch as soon that moves out of the experimental phase. |
@Robbie-Microsoft I had initially tried it with the latest version, 1.5.1. I just retested it with 1.4.0 and still get the endpoints resolution error. I understand not wanting to rely on third party libraries, but msal-node and the MS Graph Client having such disparate proxy support is pretty frustrating. The graph client as it is currently uses a fetch polyfill and is compatible with https-proxy-agent. If there's unlikely to be any major change until Node's native fetch supports proxies, then could I suggest a happy medium in the meantime? Currently, msal-node doesn't support
I'm able to successfully connect through the proxy. To preserve backwards compatibility, something like this can be done:
This way, we check if the end user passed in their own custom agent object, and if they did, we use that. If they just passed in a dictionary of options, we create the Agent object for them and use that. We check if it's either an http or https agent, because both are valid in |
Agreed, let's analyze the stance of Azure SDK and Microsoft Graph SDK and consolidate. |
Hello, Any news regarding this issue? Behind a corporate proxy, there's no way to connect, currently. |
Also, the current implementation does not supports authenticated pxy |
@bgavrilMS and I are still discussing this, but have other priorities right now. In the meantime, you all can implement your own custom network modules. See this sample. Note: Node's native fetch api is now stable in node v21 Additionally, we are not actively supporting msal-node v1 anymore unless there is a critical bug that needs to be addressed. |
We will revisit when we move to use Solution for folks wanting to use a proxy is to provide their own INetworkModule. |
Working INetworkModule implementation with ProxyTROUBLESHOOTING
import type { INetworkModule, NetworkRequestOptions, NetworkResponse } from "@azure/msal-node";
import { HttpsProxyAgent } from "https-proxy-agent";
import fetch from 'node-fetch';
const proxyUrl = process.env['HTTPS_PROXY'] || process.env['HTTP_PROXY'];
if (!proxyUrl) {
throw new Error('Missing HTTP/S_PROXY env');
}
export const proxyAgent = new HttpsProxyAgent(proxyUrl);
export class CustomHttpClient implements INetworkModule {
sendGetRequestAsync<T>(url: string, options?: NetworkRequestOptions): Promise<NetworkResponse<T>> {
return this.sendRequestAsync(url, 'GET', options);
}
sendPostRequestAsync<T>(url: string, options?: NetworkRequestOptions): Promise<NetworkResponse<T>> {
return this.sendRequestAsync(url, 'POST', options);
}
private async sendRequestAsync<T>(
url: string,
method: 'GET' | 'POST',
options: NetworkRequestOptions = {},
): Promise<NetworkResponse<T>> {
try {
const requestOptions = {
method: method,
headers: options.headers,
body: method === 'POST' ? options.body : undefined,
agent: proxyAgent,
};
console.log('>>> url', url, requestOptions);
const response = await fetch(url, requestOptions);
const data = await response.json() as any;
const headersObj: Record<string, string> = {};
response.headers.forEach((value, key) => {
headersObj[key] = value;
});
return {
headers: headersObj,
body: data,
status: response.status,
};
} catch (err) {
console.error('CustomRequest', err);
throw new Error('Custom request error');
}
}
} |
On a related note, if you're using Node 18+, native fetch breaks node-fetch and necessitates the usage of |
Core Library
MSAL Node (@azure/msal-node)
Core Library Version
1.18.3
Wrapper Library
Not Applicable
Wrapper Library Version
N/A
Public or Confidential Client?
Confidential
Description
For the past year or so, I have been using msal-node behind a corporate proxy with the workaround posted by another user here (overriding the networkClient with proxy-compatible versions of sendGetRequestAsync and sendPostRequestAsync). This has been working well, and now that msal-node natively supports proxies I wanted to try it out. Unfortunately, passing the proxyUrl parameter and disabling the custom networkClient yields an Endpoints Resolution Error
ClientAuthError: endpoints_resolution_error: Error: could not resolve endpoints. Please check network and try again. Detail: ClientAuthError: openid_config_error: Could not retrieve endpoints. Check your authority and verify the .well-known/openid-configuration endpoint returns the required endpoints. Attempted to retrieve endpoints from: https://login.microsoftonline.com/my tenant/v2.0/.well-known/openid-configuration
I investigated msal-nodes implementation of proxy compatibility to see if I could figure out the issue. Connection to the corporate proxy seemed to succeed. Log statements I put in the
networkRequestViaProxy
function showed that connection to the proxy was succeeding with200 Connection established
However, accessing microsoft's login servers seemed to be yielding a 400 Bad Request.And these are the contents of the
payload
variable in that function:The existing proxy implementation using http.request and manually writing http requests through the socket seems overly complex and dated and doesnt support the Proxy-Authorization header - it would be great if it were rewritten to use fetch and https-proxy-agent. They're far newer and cleaner, and it's how the MS Graph Client implements proxy support. I've never had a single issue with the Graph Clients proxy support.
Error Message
ClientAuthError: endpoints_resolution_error: Error: could not resolve endpoints. Please check network and try again. Detail: ClientAuthError: openid_config_error: Could not retrieve endpoints. Check your authority and verify the .well-known/openid-configuration endpoint returns the required endpoints. Attempted to retrieve endpoints from: https://login.microsoftonline.com/my tenant/v2.0/.well-known/openid-configuration
Msal Logs
No response
MSAL Configuration
Relevant Code Snippets
Reproduction Steps
Expected Behavior
The expected behavior is the 200 Ok response and msal-node being able to fetch the token
Identity Provider
Azure AD / MSA
Browsers Affected (Select all that apply)
None (Server), Other
Regression
No response
Source
External (Customer)
The text was updated successfully, but these errors were encountered: