Skip to content

Commit c11406d

Browse files
[V5] Re-wrote msal-node's HttpClient to use NodeJS's native fetch API. (#8137)
1 parent ff8aa67 commit c11406d

File tree

9 files changed

+546
-1052
lines changed

9 files changed

+546
-1052
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Re-wrote HttpClient to use NodeJS's native fetch API (#8137)",
4+
"packageName": "@azure/msal-node",
5+
"email": "rginsburg@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

lib/msal-node/apiReview/msal-node.api.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ import { CommonRefreshTokenRequest } from '@azure/msal-common/node';
4242
import { CommonSilentFlowRequest } from '@azure/msal-common/node';
4343
import { CredentialEntity } from '@azure/msal-common/node';
4444
import { DeviceCodeResponse } from '@azure/msal-common/node';
45-
import http from 'http';
46-
import https from 'https';
4745
import { IAppTokenProvider } from '@azure/msal-common/node';
4846
import { ICachePlugin } from '@azure/msal-common/node';
4947
import { ICrypto } from '@azure/msal-common/node';
@@ -385,8 +383,6 @@ export type NodeAuthOptions = {
385383
export type NodeSystemOptions = {
386384
loggerOptions?: LoggerOptions;
387385
networkClient?: INetworkModule;
388-
proxyUrl?: string;
389-
customAgentOptions?: http.AgentOptions | https.AgentOptions;
390386
disableInternalRetries?: boolean;
391387
protocolMode?: ProtocolMode;
392388
};

lib/msal-node/docs/configuration.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ const msalConfig = {
5656
piiLoggingEnabled: false,
5757
logLevel: msal.LogLevel.Verbose,
5858
},
59-
proxyUrl: "",
60-
customAgentOptions: {},
6159
}
6260
}
6361

@@ -68,15 +66,15 @@ const msalInstance = new PublicClientApplication(msalConfig);
6866

6967
### Auth Config Options
7068

71-
| Option | Description | Format | Default Value |
72-
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
73-
| `clientId` | App ID of your application. Can be found in your [portal registration](../README.md#prerequisites). | UUID/GUID | None. This parameter is required in order for MSAL to perform any actions. |
74-
| `authority` | URI of the tenant to authenticate and authorize with. Usually takes the form of `https://{uri}/{tenantid}` (see [Authority](../../msal-common/docs/authority.md)) | String in URI format with tenant - `https://{uri}/{tenantid}` | `https://login.microsoftonline.com/common` |
75-
| `knownAuthorities` | An array of URIs that are known to be valid. Used in B2C scenarios. | Array of strings in URI format | Empty array `[]` |
76-
| `cloudDiscoveryMetadata` | A string containing the cloud discovery response. Used in AAD scenarios. See [Performance](../../msal-common/docs/performance.md) for more info | string | Empty string `""` |
77-
| `authorityMetadata` | A string containing the .well-known/openid-configuration endpoint response. See [Performance](../../msal-common/docs/performance.md) for more info | string | Empty string `""` |
78-
| `clientCapabilities` | Array of capabilities to be added to all network requests as part of the `xms_cc` claims request (see: [Client capability in MSAL](../../msal-common/docs/client-capability.md)) | Array of strings | [] |
79-
| `azureCloudOptions` | A defined set of azure cloud options for developers to default to their specific cloud authorities, for specific clouds supported please refer to the [AzureCloudInstance](aka.ms/msaljs/azure_cloud_instance) | [AzureCloudOptions](https://azuread.github.io/microsoft-authentication-library-for-js/ref/modules/_azure_msal_common.html#azurecloudoptions) | [AzureCloudInstance.None](msaljs/azure_cloud_instance) |
69+
| Option | Description | Format | Default Value |
70+
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
71+
| `clientId` | App ID of your application. Can be found in your [portal registration](../README.md#prerequisites). | UUID/GUID | None. This parameter is required in order for MSAL to perform any actions. |
72+
| `authority` | URI of the tenant to authenticate and authorize with. Usually takes the form of `https://{uri}/{tenantid}` (see [Authority](../../msal-common/docs/authority.md)) | String in URI format with tenant - `https://{uri}/{tenantid}` | `https://login.microsoftonline.com/common` |
73+
| `knownAuthorities` | An array of URIs that are known to be valid. Used in B2C scenarios. | Array of strings in URI format | Empty array `[]` |
74+
| `cloudDiscoveryMetadata` | A string containing the cloud discovery response. Used in AAD scenarios. See [Performance](../../msal-common/docs/performance.md) for more info | string | Empty string `""` |
75+
| `authorityMetadata` | A string containing the .well-known/openid-configuration endpoint response. See [Performance](../../msal-common/docs/performance.md) for more info | string | Empty string `""` |
76+
| `clientCapabilities` | Array of capabilities to be added to all network requests as part of the `xms_cc` claims request (see: [Client capability in MSAL](../../msal-common/docs/client-capability.md)) | Array of strings | [] |
77+
| `azureCloudOptions` | A defined set of azure cloud options for developers to default to their specific cloud authorities, for specific clouds supported please refer to the [AzureCloudInstance](aka.ms/msaljs/azure_cloud_instance) | [AzureCloudOptions](https://azuread.github.io/microsoft-authentication-library-for-js/ref/modules/_azure_msal_common.html#azurecloudoptions) | [AzureCloudInstance.None](msaljs/azure_cloud_instance) |
8078

8179
### Cache Config Options
8280

@@ -92,14 +90,12 @@ const msalInstance = new PublicClientApplication(msalConfig);
9290

9391
### System Config Options
9492

95-
| Option | Description | Format | Default Value |
96-
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
97-
| `loggerOptions` | Config object for logger. | See [below](#logger-config-options). | See [below](#logger-config-options). |
98-
| `NetworkClient` | Custom HTTP implementation | INetworkModule | [HttpClient.ts](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/src/network/HttpClient.ts) |
99-
| `proxyUrl` | The URL of the proxy the app is running behind | string | Empty string `""` |
100-
| `customAgentOptions` | Set of configurable options to set on a http(s) agent | Object - [NodeJS documentation on alloweable options](https://nodejs.org/docs/latest-v16.x/api/http.html#new-agentoptions) | Empty Object `{}` |
101-
| `disableInternalRetries` | A flag that disables MSALJS's built-in retry policies, allowing the app developer to specify their own retry policy. Currently, only Managed Identity flows have a retry policy. | boolean | boolean `false` |
102-
| `protocolMode` | Enum representing the protocol mode to use. If `"AAD"`, will function on the AAD v2 endpoints; if `"OIDC"`, will function on OIDC-compliant endpoints. | string | `"AAD"` |
93+
| Option | Description | Format | Default Value |
94+
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
95+
| `loggerOptions` | Config object for logger. | See [below](#logger-config-options). | See [below](#logger-config-options). |
96+
| `NetworkClient` | Custom HTTP implementation | INetworkModule | [HttpClient.ts](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/src/network/HttpClient.ts) |
97+
| `disableInternalRetries` | A flag that disables MSALJS's built-in retry policies, allowing the app developer to specify their own retry policy. Currently, only Managed Identity flows have a retry policy. | boolean | boolean `false` |
98+
| `protocolMode` | Enum representing the protocol mode to use. If `"AAD"`, will function on the AAD v2 endpoints; if `"OIDC"`, will function on OIDC-compliant endpoints. | string | `"AAD"` |
10399

104100
#### Logger Config Options
105101

lib/msal-node/docs/faq.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ MSAL Node supports self-service sign-up in the auth code flow. Please see our do
6868

6969
### Why doesn't my app function correctly when it's running behind a proxy?
7070

71-
Developers can provide a `proxyUrl` string in the system config options as detailed [here](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/configuration.md#system-config-options). Developers can also implement their own NetworkManager by instantiating an [INetworkModule](https://azuread.github.io/microsoft-authentication-library-for-js/ref/interfaces/_azure_msal_common.INetworkModule.html) and building proxy support in it.
72-
73-
### How do I implement a custom http(s) agent in MSAL Node?
74-
75-
Developers can use a custom http(s) agent by providing a `customAgentOptions` object in the system config options as detailed [here](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/configuration.md#system-config-options). Developers can also implement their own NetworkManager by instantiating an [INetworkModule](https://azuread.github.io/microsoft-authentication-library-for-js/ref/interfaces/_azure_msal_common.INetworkModule.html) and building custom http(s) agent support in it.
71+
MSAL-Node's HttpClient utilizes NodeJS's native fetch API for network requests, which currently doesn't have native proxy support. Developers can implement their own NetworkManager by instantiating an [INetworkModule](https://azuread.github.io/microsoft-authentication-library-for-js/ref/interfaces/_azure_msal_common.INetworkModule.html) and building proxy support in it. A sample for this can be found [here](../../../samples/msal-node-samples/custom-INetworkModule-and-network-tracing/README.md).
7672

7773
## B2C
7874

lib/msal-node/docs/v4-migration.md renamed to lib/msal-node/docs/v5-migration.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
# Migrating from MSAL Node v3 to v4
1+
# Migrating from MSAL Node v3 to v5 (v4 is being skipped)
22

33
## Dropped support for Node 16 and 18
4+
45
MSAL Node v4 no longer supports Node.js 16 or 18; you must use Node.js 20 or greater.
56

7+
## Dropped support for `proxyUrl` and `customAgentOptions`
8+
9+
MSAL Node v5 no longer provides optional configuration for the HttpClient.
10+
611
## Configuration Changes
712

13+
`proxyUrl` and `customAgentOptions` parameters are no longer configuration options.
14+
15+
```ts
16+
// BEFORE
17+
18+
NodeSystemOptions = {
19+
loggerOptions?: LoggerOptions;
20+
networkClient?: INetworkModule;
21+
proxyUrl?: string;
22+
customAgentOptions?: http.AgentOptions | https.AgentOptions;
23+
disableInternalRetries?: boolean;
24+
protocolMode?: ProtocolMode;
25+
};
26+
27+
// AFTER
28+
29+
NodeSystemOptions = {
30+
loggerOptions?: LoggerOptions;
31+
networkClient?: INetworkModule;
32+
disableInternalRetries?: boolean;
33+
protocolMode?: ProtocolMode;
34+
};
35+
```
36+
37+
Developers must now write their own custom HttpClient when proxy support is needed. We have an [existing sample](../../../samples/msal-node-samples/custom-INetworkModule-and-network-tracing/README.md) which showcases how to do this.
38+
839
The `protocolMode` parameter is no longer an auth config option and is instead a system config option.
940

1041
```ts

0 commit comments

Comments
 (0)