@azure/msal-node 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache/ITokenCache.d.ts +15 -15
- package/dist/cache/NodeStorage.cjs +425 -423
- package/dist/cache/NodeStorage.cjs.map +1 -1
- package/dist/cache/NodeStorage.d.ts +193 -193
- package/dist/cache/NodeStorage.mjs +423 -423
- package/dist/cache/TokenCache.cjs +267 -265
- package/dist/cache/TokenCache.cjs.map +1 -1
- package/dist/cache/TokenCache.d.ts +90 -90
- package/dist/cache/TokenCache.mjs +265 -265
- package/dist/cache/distributed/DistributedCachePlugin.cjs +28 -26
- package/dist/cache/distributed/DistributedCachePlugin.cjs.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
- package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
- package/dist/cache/distributed/ICacheClient.d.ts +17 -17
- package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
- package/dist/cache/serializer/Deserializer.cjs +169 -167
- package/dist/cache/serializer/Deserializer.cjs.map +1 -1
- package/dist/cache/serializer/Deserializer.d.ts +42 -42
- package/dist/cache/serializer/Deserializer.mjs +167 -167
- package/dist/cache/serializer/Serializer.cjs +139 -137
- package/dist/cache/serializer/Serializer.cjs.map +1 -1
- package/dist/cache/serializer/Serializer.d.ts +39 -39
- package/dist/cache/serializer/Serializer.mjs +137 -137
- package/dist/cache/serializer/SerializerTypes.d.ts +102 -102
- package/dist/client/ClientApplication.cjs +336 -334
- package/dist/client/ClientApplication.cjs.map +1 -1
- package/dist/client/ClientApplication.d.ts +143 -143
- package/dist/client/ClientApplication.mjs +334 -334
- package/dist/client/ClientAssertion.cjs +149 -143
- package/dist/client/ClientAssertion.cjs.map +1 -1
- package/dist/client/ClientAssertion.d.ts +55 -55
- package/dist/client/ClientAssertion.mjs +143 -143
- package/dist/client/ClientCredentialClient.cjs +196 -194
- package/dist/client/ClientCredentialClient.cjs.map +1 -1
- package/dist/client/ClientCredentialClient.d.ts +33 -33
- package/dist/client/ClientCredentialClient.mjs +194 -194
- package/dist/client/ConfidentialClientApplication.cjs +170 -169
- package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts +58 -58
- package/dist/client/ConfidentialClientApplication.mjs +168 -169
- package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
- package/dist/client/DeviceCodeClient.cjs +209 -207
- package/dist/client/DeviceCodeClient.cjs.map +1 -1
- package/dist/client/DeviceCodeClient.d.ts +53 -53
- package/dist/client/DeviceCodeClient.mjs +207 -207
- package/dist/client/IConfidentialClientApplication.d.ts +39 -39
- package/dist/client/IPublicClientApplication.d.ts +42 -42
- package/dist/client/ManagedIdentityApplication.cjs +86 -84
- package/dist/client/ManagedIdentityApplication.cjs.map +1 -1
- package/dist/client/ManagedIdentityApplication.d.ts +30 -30
- package/dist/client/ManagedIdentityApplication.mjs +84 -84
- package/dist/client/ManagedIdentityClient.cjs +62 -60
- package/dist/client/ManagedIdentityClient.cjs.map +1 -1
- package/dist/client/ManagedIdentityClient.d.ts +27 -27
- package/dist/client/ManagedIdentityClient.mjs +60 -60
- package/dist/client/ManagedIdentitySources/AppService.cjs +47 -45
- package/dist/client/ManagedIdentitySources/AppService.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AppService.d.ts +17 -17
- package/dist/client/ManagedIdentitySources/AppService.mjs +46 -46
- package/dist/client/ManagedIdentitySources/AzureArc.cjs +161 -120
- package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts +27 -23
- package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
- package/dist/client/ManagedIdentitySources/AzureArc.mjs +155 -122
- package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +124 -122
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +30 -30
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +122 -122
- package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.cjs +40 -38
- package/dist/client/ManagedIdentitySources/CloudShell.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/CloudShell.d.ts +16 -16
- package/dist/client/ManagedIdentitySources/CloudShell.mjs +39 -39
- package/dist/client/ManagedIdentitySources/Imds.cjs +45 -43
- package/dist/client/ManagedIdentitySources/Imds.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/Imds.d.ts +12 -12
- package/dist/client/ManagedIdentitySources/Imds.mjs +44 -44
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +56 -54
- package/dist/client/ManagedIdentitySources/ServiceFabric.cjs.map +1 -1
- package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +17 -17
- package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +55 -55
- package/dist/client/OnBehalfOfClient.cjs +204 -202
- package/dist/client/OnBehalfOfClient.cjs.map +1 -1
- package/dist/client/OnBehalfOfClient.d.ts +47 -47
- package/dist/client/OnBehalfOfClient.mjs +202 -202
- package/dist/client/PublicClientApplication.cjs +239 -237
- package/dist/client/PublicClientApplication.cjs.map +1 -1
- package/dist/client/PublicClientApplication.d.ts +72 -72
- package/dist/client/PublicClientApplication.mjs +237 -237
- package/dist/client/UsernamePasswordClient.cjs +97 -95
- package/dist/client/UsernamePasswordClient.cjs.map +1 -1
- package/dist/client/UsernamePasswordClient.d.ts +25 -25
- package/dist/client/UsernamePasswordClient.mjs +95 -95
- package/dist/config/Configuration.cjs +108 -106
- package/dist/config/Configuration.cjs.map +1 -1
- package/dist/config/Configuration.d.ts +131 -131
- package/dist/config/Configuration.mjs +106 -106
- package/dist/config/ManagedIdentityId.cjs +50 -48
- package/dist/config/ManagedIdentityId.cjs.map +1 -1
- package/dist/config/ManagedIdentityId.d.ts +11 -11
- package/dist/config/ManagedIdentityId.mjs +48 -48
- package/dist/config/ManagedIdentityRequestParameters.cjs +30 -28
- package/dist/config/ManagedIdentityRequestParameters.cjs.map +1 -1
- package/dist/config/ManagedIdentityRequestParameters.d.ts +11 -11
- package/dist/config/ManagedIdentityRequestParameters.mjs +28 -28
- package/dist/crypto/CryptoProvider.cjs +91 -89
- package/dist/crypto/CryptoProvider.cjs.map +1 -1
- package/dist/crypto/CryptoProvider.d.ts +62 -62
- package/dist/crypto/CryptoProvider.mjs +89 -89
- package/dist/crypto/GuidGenerator.cjs +24 -22
- package/dist/crypto/GuidGenerator.cjs.map +1 -1
- package/dist/crypto/GuidGenerator.d.ts +14 -14
- package/dist/crypto/GuidGenerator.mjs +22 -22
- package/dist/crypto/HashUtils.cjs +19 -13
- package/dist/crypto/HashUtils.cjs.map +1 -1
- package/dist/crypto/HashUtils.d.ts +8 -8
- package/dist/crypto/HashUtils.mjs +13 -13
- package/dist/crypto/PkceGenerator.cjs +55 -49
- package/dist/crypto/PkceGenerator.cjs.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +22 -22
- package/dist/crypto/PkceGenerator.mjs +49 -49
- package/dist/error/ManagedIdentityError.cjs +43 -41
- package/dist/error/ManagedIdentityError.cjs.map +1 -1
- package/dist/error/ManagedIdentityError.d.ts +30 -30
- package/dist/error/ManagedIdentityError.mjs +41 -41
- package/dist/error/ManagedIdentityErrorCodes.cjs +26 -24
- package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -1
- package/dist/error/ManagedIdentityErrorCodes.d.ts +22 -22
- package/dist/error/ManagedIdentityErrorCodes.mjs +24 -24
- package/dist/error/NodeAuthError.cjs +97 -95
- package/dist/error/NodeAuthError.cjs.map +1 -1
- package/dist/error/NodeAuthError.d.ts +73 -73
- package/dist/error/NodeAuthError.mjs +95 -95
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +45 -45
- package/dist/index.mjs +1 -1
- package/dist/internals.cjs +6 -8
- package/dist/internals.cjs.map +1 -1
- package/dist/internals.d.ts +6 -6
- package/dist/internals.mjs +4 -8
- package/dist/internals.mjs.map +1 -1
- package/dist/network/HttpClient.cjs +288 -281
- package/dist/network/HttpClient.cjs.map +1 -1
- package/dist/network/HttpClient.d.ts +25 -25
- package/dist/network/HttpClient.mjs +281 -281
- package/dist/network/HttpClientWithRetries.cjs +36 -34
- package/dist/network/HttpClientWithRetries.cjs.map +1 -1
- package/dist/network/HttpClientWithRetries.d.ts +11 -11
- package/dist/network/HttpClientWithRetries.mjs +34 -34
- package/dist/network/ILoopbackClient.d.ts +10 -10
- package/dist/network/LoopbackClient.cjs +87 -77
- package/dist/network/LoopbackClient.cjs.map +1 -1
- package/dist/network/LoopbackClient.d.ts +21 -21
- package/dist/network/LoopbackClient.d.ts.map +1 -1
- package/dist/network/LoopbackClient.mjs +81 -77
- package/dist/network/LoopbackClient.mjs.map +1 -1
- package/dist/packageMetadata.cjs +6 -4
- package/dist/packageMetadata.cjs.map +1 -1
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.mjs +4 -4
- package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
- package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
- package/dist/request/ClientCredentialRequest.d.ts +14 -14
- package/dist/request/DeviceCodeRequest.d.ts +15 -15
- package/dist/request/InteractiveRequest.d.ts +22 -22
- package/dist/request/ManagedIdentityRequest.d.ts +8 -8
- package/dist/request/ManagedIdentityRequestParams.d.ts +9 -9
- package/dist/request/OnBehalfOfRequest.d.ts +14 -14
- package/dist/request/RefreshTokenRequest.d.ts +17 -17
- package/dist/request/SignOutRequest.d.ts +5 -5
- package/dist/request/SilentFlowRequest.d.ts +16 -16
- package/dist/request/UsernamePasswordRequest.d.ts +19 -19
- package/dist/response/ManagedIdentityTokenResponse.d.ts +34 -34
- package/dist/retry/IHttpRetryPolicy.d.ts +5 -5
- package/dist/retry/LinearRetryPolicy.cjs +42 -40
- package/dist/retry/LinearRetryPolicy.cjs.map +1 -1
- package/dist/retry/LinearRetryPolicy.d.ts +11 -11
- package/dist/retry/LinearRetryPolicy.mjs +40 -40
- package/dist/utils/Constants.cjs +138 -136
- package/dist/utils/Constants.cjs.map +1 -1
- package/dist/utils/Constants.d.ts +141 -141
- package/dist/utils/Constants.mjs +136 -136
- package/dist/utils/EncodingUtils.cjs +46 -44
- package/dist/utils/EncodingUtils.cjs.map +1 -1
- package/dist/utils/EncodingUtils.d.ts +26 -26
- package/dist/utils/EncodingUtils.mjs +44 -44
- package/dist/utils/NetworkUtils.cjs +40 -38
- package/dist/utils/NetworkUtils.cjs.map +1 -1
- package/dist/utils/NetworkUtils.d.ts +5 -5
- package/dist/utils/NetworkUtils.mjs +38 -38
- package/package.json +2 -2
- package/src/client/ConfidentialClientApplication.ts +3 -3
- package/src/client/ManagedIdentitySources/AzureArc.ts +80 -25
- package/src/network/LoopbackClient.ts +6 -0
- package/src/packageMetadata.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
1
|
+
/*! @azure/msal-node v2.13.0 2024-08-13 */
|
|
2
2
|
'use strict';
|
|
3
3
|
import { HttpStatus } from '@azure/msal-common';
|
|
4
4
|
import { ProxyStatus, Constants, HttpMethod } from '../utils/Constants.mjs';
|
|
@@ -6,286 +6,286 @@ import { NetworkUtils } from '../utils/NetworkUtils.mjs';
|
|
|
6
6
|
import http from 'http';
|
|
7
7
|
import https from 'https';
|
|
8
8
|
|
|
9
|
-
/*
|
|
10
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
-
* Licensed under the MIT License.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* This class implements the API for network requests.
|
|
15
|
-
*/
|
|
16
|
-
class HttpClient {
|
|
17
|
-
constructor(proxyUrl, customAgentOptions) {
|
|
18
|
-
this.proxyUrl = proxyUrl || "";
|
|
19
|
-
this.customAgentOptions = customAgentOptions || {};
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Http Get request
|
|
23
|
-
* @param url
|
|
24
|
-
* @param options
|
|
25
|
-
*/
|
|
26
|
-
async sendGetRequestAsync(url, options, timeout) {
|
|
27
|
-
if (this.proxyUrl) {
|
|
28
|
-
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.GET, options, this.customAgentOptions, timeout);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return networkRequestViaHttps(url, HttpMethod.GET, options, this.customAgentOptions, timeout);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Http Post request
|
|
36
|
-
* @param url
|
|
37
|
-
* @param options
|
|
38
|
-
*/
|
|
39
|
-
async sendPostRequestAsync(url, options) {
|
|
40
|
-
if (this.proxyUrl) {
|
|
41
|
-
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.POST, options, this.customAgentOptions);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
return networkRequestViaHttps(url, HttpMethod.POST, options, this.customAgentOptions);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const networkRequestViaProxy = (destinationUrlString, proxyUrlString, httpMethod, options, agentOptions, timeout) => {
|
|
49
|
-
const destinationUrl = new URL(destinationUrlString);
|
|
50
|
-
const proxyUrl = new URL(proxyUrlString);
|
|
51
|
-
// "method: connect" must be used to establish a connection to the proxy
|
|
52
|
-
const headers = options?.headers || {};
|
|
53
|
-
const tunnelRequestOptions = {
|
|
54
|
-
host: proxyUrl.hostname,
|
|
55
|
-
port: proxyUrl.port,
|
|
56
|
-
method: "CONNECT",
|
|
57
|
-
path: destinationUrl.hostname,
|
|
58
|
-
headers: headers,
|
|
59
|
-
};
|
|
60
|
-
if (agentOptions && Object.keys(agentOptions).length) {
|
|
61
|
-
tunnelRequestOptions.agent = new http.Agent(agentOptions);
|
|
62
|
-
}
|
|
63
|
-
// compose a request string for the socket
|
|
64
|
-
let postRequestStringContent = "";
|
|
65
|
-
if (httpMethod === HttpMethod.POST) {
|
|
66
|
-
const body = options?.body || "";
|
|
67
|
-
postRequestStringContent =
|
|
68
|
-
"Content-Type: application/x-www-form-urlencoded\r\n" +
|
|
69
|
-
`Content-Length: ${body.length}\r\n` +
|
|
70
|
-
`\r\n${body}`;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// optional timeout is only for get requests (regionDiscovery, for example)
|
|
74
|
-
if (timeout) {
|
|
75
|
-
tunnelRequestOptions.timeout = timeout;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const outgoingRequestString = `${httpMethod.toUpperCase()} ${destinationUrl.href} HTTP/1.1\r\n` +
|
|
79
|
-
`Host: ${destinationUrl.host}\r\n` +
|
|
80
|
-
"Connection: close\r\n" +
|
|
81
|
-
postRequestStringContent +
|
|
82
|
-
"\r\n";
|
|
83
|
-
return new Promise((resolve, reject) => {
|
|
84
|
-
const request = http.request(tunnelRequestOptions);
|
|
85
|
-
if (timeout) {
|
|
86
|
-
request.on("timeout", () => {
|
|
87
|
-
request.destroy();
|
|
88
|
-
reject(new Error("Request time out"));
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
request.end();
|
|
92
|
-
// establish connection to the proxy
|
|
93
|
-
request.on("connect", (response, socket) => {
|
|
94
|
-
const proxyStatusCode = response?.statusCode || ProxyStatus.SERVER_ERROR;
|
|
95
|
-
if (proxyStatusCode < ProxyStatus.SUCCESS_RANGE_START ||
|
|
96
|
-
proxyStatusCode > ProxyStatus.SUCCESS_RANGE_END) {
|
|
97
|
-
request.destroy();
|
|
98
|
-
socket.destroy();
|
|
99
|
-
reject(new Error(`Error connecting to proxy. Http status code: ${response.statusCode}. Http status message: ${response?.statusMessage || "Unknown"}`));
|
|
100
|
-
}
|
|
101
|
-
// make a request over an HTTP tunnel
|
|
102
|
-
socket.write(outgoingRequestString);
|
|
103
|
-
const data = [];
|
|
104
|
-
socket.on("data", (chunk) => {
|
|
105
|
-
data.push(chunk);
|
|
106
|
-
});
|
|
107
|
-
socket.on("end", () => {
|
|
108
|
-
// combine all received buffer streams into one buffer, and then into a string
|
|
109
|
-
const dataString = Buffer.concat([...data]).toString();
|
|
110
|
-
// separate each line into it's own entry in an arry
|
|
111
|
-
const dataStringArray = dataString.split("\r\n");
|
|
112
|
-
// the first entry will contain the statusCode and statusMessage
|
|
113
|
-
const httpStatusCode = parseInt(dataStringArray[0].split(" ")[1]);
|
|
114
|
-
// remove "HTTP/1.1" and the status code to get the status message
|
|
115
|
-
const statusMessage = dataStringArray[0]
|
|
116
|
-
.split(" ")
|
|
117
|
-
.slice(2)
|
|
118
|
-
.join(" ");
|
|
119
|
-
// the last entry will contain the body
|
|
120
|
-
const body = dataStringArray[dataStringArray.length - 1];
|
|
121
|
-
// everything in between the first and last entries are the headers
|
|
122
|
-
const headersArray = dataStringArray.slice(1, dataStringArray.length - 2);
|
|
123
|
-
// build an object out of all the headers
|
|
124
|
-
const entries = new Map();
|
|
125
|
-
headersArray.forEach((header) => {
|
|
126
|
-
/**
|
|
127
|
-
* the header might look like "Content-Length: 1531", but that is just a string
|
|
128
|
-
* it needs to be converted to a key/value pair
|
|
129
|
-
* split the string at the first instance of ":"
|
|
130
|
-
* there may be more than one ":" if the value of the header is supposed to be a JSON object
|
|
131
|
-
*/
|
|
132
|
-
const headerKeyValue = header.split(new RegExp(/:\s(.*)/s));
|
|
133
|
-
const headerKey = headerKeyValue[0];
|
|
134
|
-
let headerValue = headerKeyValue[1];
|
|
135
|
-
// check if the value of the header is supposed to be a JSON object
|
|
136
|
-
try {
|
|
137
|
-
const object = JSON.parse(headerValue);
|
|
138
|
-
// if it is, then convert it from a string to a JSON object
|
|
139
|
-
if (object && typeof object === "object") {
|
|
140
|
-
headerValue = object;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
catch (e) {
|
|
144
|
-
// otherwise, leave it as a string
|
|
145
|
-
}
|
|
146
|
-
entries.set(headerKey, headerValue);
|
|
147
|
-
});
|
|
148
|
-
const headers = Object.fromEntries(entries);
|
|
149
|
-
const parsedHeaders = headers;
|
|
150
|
-
const networkResponse = NetworkUtils.getNetworkResponse(parsedHeaders, parseBody(httpStatusCode, statusMessage, parsedHeaders, body), httpStatusCode);
|
|
151
|
-
if ((httpStatusCode < HttpStatus.SUCCESS_RANGE_START ||
|
|
152
|
-
httpStatusCode > HttpStatus.SUCCESS_RANGE_END) &&
|
|
153
|
-
// do not destroy the request for the device code flow
|
|
154
|
-
networkResponse.body["error"] !==
|
|
155
|
-
Constants.AUTHORIZATION_PENDING) {
|
|
156
|
-
request.destroy();
|
|
157
|
-
}
|
|
158
|
-
resolve(networkResponse);
|
|
159
|
-
});
|
|
160
|
-
socket.on("error", (chunk) => {
|
|
161
|
-
request.destroy();
|
|
162
|
-
socket.destroy();
|
|
163
|
-
reject(new Error(chunk.toString()));
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
request.on("error", (chunk) => {
|
|
167
|
-
request.destroy();
|
|
168
|
-
reject(new Error(chunk.toString()));
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
const networkRequestViaHttps = (urlString, httpMethod, options, agentOptions, timeout) => {
|
|
173
|
-
const isPostRequest = httpMethod === HttpMethod.POST;
|
|
174
|
-
const body = options?.body || "";
|
|
175
|
-
const url = new URL(urlString);
|
|
176
|
-
const headers = options?.headers || {};
|
|
177
|
-
const customOptions = {
|
|
178
|
-
method: httpMethod,
|
|
179
|
-
headers: headers,
|
|
180
|
-
...NetworkUtils.urlToHttpOptions(url),
|
|
181
|
-
};
|
|
182
|
-
if (agentOptions && Object.keys(agentOptions).length) {
|
|
183
|
-
customOptions.agent = new https.Agent(agentOptions);
|
|
184
|
-
}
|
|
185
|
-
if (isPostRequest) {
|
|
186
|
-
// needed for post request to work
|
|
187
|
-
customOptions.headers = {
|
|
188
|
-
...customOptions.headers,
|
|
189
|
-
"Content-Length": body.length,
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
// optional timeout is only for get requests (regionDiscovery, for example)
|
|
194
|
-
if (timeout) {
|
|
195
|
-
customOptions.timeout = timeout;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return new Promise((resolve, reject) => {
|
|
199
|
-
let request;
|
|
200
|
-
// managed identity sources use http instead of https
|
|
201
|
-
if (customOptions.protocol === "http:") {
|
|
202
|
-
request = http.request(customOptions);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
request = https.request(customOptions);
|
|
206
|
-
}
|
|
207
|
-
if (isPostRequest) {
|
|
208
|
-
request.write(body);
|
|
209
|
-
}
|
|
210
|
-
if (timeout) {
|
|
211
|
-
request.on("timeout", () => {
|
|
212
|
-
request.destroy();
|
|
213
|
-
reject(new Error("Request time out"));
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
request.end();
|
|
217
|
-
request.on("response", (response) => {
|
|
218
|
-
const headers = response.headers;
|
|
219
|
-
const statusCode = response.statusCode;
|
|
220
|
-
const statusMessage = response.statusMessage;
|
|
221
|
-
const data = [];
|
|
222
|
-
response.on("data", (chunk) => {
|
|
223
|
-
data.push(chunk);
|
|
224
|
-
});
|
|
225
|
-
response.on("end", () => {
|
|
226
|
-
// combine all received buffer streams into one buffer, and then into a string
|
|
227
|
-
const body = Buffer.concat([...data]).toString();
|
|
228
|
-
const parsedHeaders = headers;
|
|
229
|
-
const networkResponse = NetworkUtils.getNetworkResponse(parsedHeaders, parseBody(statusCode, statusMessage, parsedHeaders, body), statusCode);
|
|
230
|
-
if ((statusCode < HttpStatus.SUCCESS_RANGE_START ||
|
|
231
|
-
statusCode > HttpStatus.SUCCESS_RANGE_END) &&
|
|
232
|
-
// do not destroy the request for the device code flow
|
|
233
|
-
networkResponse.body["error"] !==
|
|
234
|
-
Constants.AUTHORIZATION_PENDING) {
|
|
235
|
-
request.destroy();
|
|
236
|
-
}
|
|
237
|
-
resolve(networkResponse);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
request.on("error", (chunk) => {
|
|
241
|
-
request.destroy();
|
|
242
|
-
reject(new Error(chunk.toString()));
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
};
|
|
246
|
-
/**
|
|
247
|
-
* Check if extra parsing is needed on the repsonse from the server
|
|
248
|
-
* @param statusCode {number} the status code of the response from the server
|
|
249
|
-
* @param statusMessage {string | undefined} the status message of the response from the server
|
|
250
|
-
* @param headers {Record<string, string>} the headers of the response from the server
|
|
251
|
-
* @param body {string} the body from the response of the server
|
|
252
|
-
* @returns {Object} JSON parsed body or error object
|
|
253
|
-
*/
|
|
254
|
-
const parseBody = (statusCode, statusMessage, headers, body) => {
|
|
255
|
-
/*
|
|
256
|
-
* Informational responses (100 – 199)
|
|
257
|
-
* Successful responses (200 – 299)
|
|
258
|
-
* Redirection messages (300 – 399)
|
|
259
|
-
* Client error responses (400 – 499)
|
|
260
|
-
* Server error responses (500 – 599)
|
|
261
|
-
*/
|
|
262
|
-
let parsedBody;
|
|
263
|
-
try {
|
|
264
|
-
parsedBody = JSON.parse(body);
|
|
265
|
-
}
|
|
266
|
-
catch (error) {
|
|
267
|
-
let errorType;
|
|
268
|
-
let errorDescriptionHelper;
|
|
269
|
-
if (statusCode >= HttpStatus.CLIENT_ERROR_RANGE_START &&
|
|
270
|
-
statusCode <= HttpStatus.CLIENT_ERROR_RANGE_END) {
|
|
271
|
-
errorType = "client_error";
|
|
272
|
-
errorDescriptionHelper = "A client";
|
|
273
|
-
}
|
|
274
|
-
else if (statusCode >= HttpStatus.SERVER_ERROR_RANGE_START &&
|
|
275
|
-
statusCode <= HttpStatus.SERVER_ERROR_RANGE_END) {
|
|
276
|
-
errorType = "server_error";
|
|
277
|
-
errorDescriptionHelper = "A server";
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
errorType = "unknown_error";
|
|
281
|
-
errorDescriptionHelper = "An unknown";
|
|
282
|
-
}
|
|
283
|
-
parsedBody = {
|
|
284
|
-
error: errorType,
|
|
285
|
-
error_description: `${errorDescriptionHelper} error occured.\nHttp status code: ${statusCode}\nHttp status message: ${statusMessage || "Unknown"}\nHeaders: ${JSON.stringify(headers)}`,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
return parsedBody;
|
|
9
|
+
/*
|
|
10
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
+
* Licensed under the MIT License.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* This class implements the API for network requests.
|
|
15
|
+
*/
|
|
16
|
+
class HttpClient {
|
|
17
|
+
constructor(proxyUrl, customAgentOptions) {
|
|
18
|
+
this.proxyUrl = proxyUrl || "";
|
|
19
|
+
this.customAgentOptions = customAgentOptions || {};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Http Get request
|
|
23
|
+
* @param url
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
async sendGetRequestAsync(url, options, timeout) {
|
|
27
|
+
if (this.proxyUrl) {
|
|
28
|
+
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.GET, options, this.customAgentOptions, timeout);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return networkRequestViaHttps(url, HttpMethod.GET, options, this.customAgentOptions, timeout);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Http Post request
|
|
36
|
+
* @param url
|
|
37
|
+
* @param options
|
|
38
|
+
*/
|
|
39
|
+
async sendPostRequestAsync(url, options) {
|
|
40
|
+
if (this.proxyUrl) {
|
|
41
|
+
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.POST, options, this.customAgentOptions);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return networkRequestViaHttps(url, HttpMethod.POST, options, this.customAgentOptions);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const networkRequestViaProxy = (destinationUrlString, proxyUrlString, httpMethod, options, agentOptions, timeout) => {
|
|
49
|
+
const destinationUrl = new URL(destinationUrlString);
|
|
50
|
+
const proxyUrl = new URL(proxyUrlString);
|
|
51
|
+
// "method: connect" must be used to establish a connection to the proxy
|
|
52
|
+
const headers = options?.headers || {};
|
|
53
|
+
const tunnelRequestOptions = {
|
|
54
|
+
host: proxyUrl.hostname,
|
|
55
|
+
port: proxyUrl.port,
|
|
56
|
+
method: "CONNECT",
|
|
57
|
+
path: destinationUrl.hostname,
|
|
58
|
+
headers: headers,
|
|
59
|
+
};
|
|
60
|
+
if (agentOptions && Object.keys(agentOptions).length) {
|
|
61
|
+
tunnelRequestOptions.agent = new http.Agent(agentOptions);
|
|
62
|
+
}
|
|
63
|
+
// compose a request string for the socket
|
|
64
|
+
let postRequestStringContent = "";
|
|
65
|
+
if (httpMethod === HttpMethod.POST) {
|
|
66
|
+
const body = options?.body || "";
|
|
67
|
+
postRequestStringContent =
|
|
68
|
+
"Content-Type: application/x-www-form-urlencoded\r\n" +
|
|
69
|
+
`Content-Length: ${body.length}\r\n` +
|
|
70
|
+
`\r\n${body}`;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// optional timeout is only for get requests (regionDiscovery, for example)
|
|
74
|
+
if (timeout) {
|
|
75
|
+
tunnelRequestOptions.timeout = timeout;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const outgoingRequestString = `${httpMethod.toUpperCase()} ${destinationUrl.href} HTTP/1.1\r\n` +
|
|
79
|
+
`Host: ${destinationUrl.host}\r\n` +
|
|
80
|
+
"Connection: close\r\n" +
|
|
81
|
+
postRequestStringContent +
|
|
82
|
+
"\r\n";
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const request = http.request(tunnelRequestOptions);
|
|
85
|
+
if (timeout) {
|
|
86
|
+
request.on("timeout", () => {
|
|
87
|
+
request.destroy();
|
|
88
|
+
reject(new Error("Request time out"));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
request.end();
|
|
92
|
+
// establish connection to the proxy
|
|
93
|
+
request.on("connect", (response, socket) => {
|
|
94
|
+
const proxyStatusCode = response?.statusCode || ProxyStatus.SERVER_ERROR;
|
|
95
|
+
if (proxyStatusCode < ProxyStatus.SUCCESS_RANGE_START ||
|
|
96
|
+
proxyStatusCode > ProxyStatus.SUCCESS_RANGE_END) {
|
|
97
|
+
request.destroy();
|
|
98
|
+
socket.destroy();
|
|
99
|
+
reject(new Error(`Error connecting to proxy. Http status code: ${response.statusCode}. Http status message: ${response?.statusMessage || "Unknown"}`));
|
|
100
|
+
}
|
|
101
|
+
// make a request over an HTTP tunnel
|
|
102
|
+
socket.write(outgoingRequestString);
|
|
103
|
+
const data = [];
|
|
104
|
+
socket.on("data", (chunk) => {
|
|
105
|
+
data.push(chunk);
|
|
106
|
+
});
|
|
107
|
+
socket.on("end", () => {
|
|
108
|
+
// combine all received buffer streams into one buffer, and then into a string
|
|
109
|
+
const dataString = Buffer.concat([...data]).toString();
|
|
110
|
+
// separate each line into it's own entry in an arry
|
|
111
|
+
const dataStringArray = dataString.split("\r\n");
|
|
112
|
+
// the first entry will contain the statusCode and statusMessage
|
|
113
|
+
const httpStatusCode = parseInt(dataStringArray[0].split(" ")[1]);
|
|
114
|
+
// remove "HTTP/1.1" and the status code to get the status message
|
|
115
|
+
const statusMessage = dataStringArray[0]
|
|
116
|
+
.split(" ")
|
|
117
|
+
.slice(2)
|
|
118
|
+
.join(" ");
|
|
119
|
+
// the last entry will contain the body
|
|
120
|
+
const body = dataStringArray[dataStringArray.length - 1];
|
|
121
|
+
// everything in between the first and last entries are the headers
|
|
122
|
+
const headersArray = dataStringArray.slice(1, dataStringArray.length - 2);
|
|
123
|
+
// build an object out of all the headers
|
|
124
|
+
const entries = new Map();
|
|
125
|
+
headersArray.forEach((header) => {
|
|
126
|
+
/**
|
|
127
|
+
* the header might look like "Content-Length: 1531", but that is just a string
|
|
128
|
+
* it needs to be converted to a key/value pair
|
|
129
|
+
* split the string at the first instance of ":"
|
|
130
|
+
* there may be more than one ":" if the value of the header is supposed to be a JSON object
|
|
131
|
+
*/
|
|
132
|
+
const headerKeyValue = header.split(new RegExp(/:\s(.*)/s));
|
|
133
|
+
const headerKey = headerKeyValue[0];
|
|
134
|
+
let headerValue = headerKeyValue[1];
|
|
135
|
+
// check if the value of the header is supposed to be a JSON object
|
|
136
|
+
try {
|
|
137
|
+
const object = JSON.parse(headerValue);
|
|
138
|
+
// if it is, then convert it from a string to a JSON object
|
|
139
|
+
if (object && typeof object === "object") {
|
|
140
|
+
headerValue = object;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
// otherwise, leave it as a string
|
|
145
|
+
}
|
|
146
|
+
entries.set(headerKey, headerValue);
|
|
147
|
+
});
|
|
148
|
+
const headers = Object.fromEntries(entries);
|
|
149
|
+
const parsedHeaders = headers;
|
|
150
|
+
const networkResponse = NetworkUtils.getNetworkResponse(parsedHeaders, parseBody(httpStatusCode, statusMessage, parsedHeaders, body), httpStatusCode);
|
|
151
|
+
if ((httpStatusCode < HttpStatus.SUCCESS_RANGE_START ||
|
|
152
|
+
httpStatusCode > HttpStatus.SUCCESS_RANGE_END) &&
|
|
153
|
+
// do not destroy the request for the device code flow
|
|
154
|
+
networkResponse.body["error"] !==
|
|
155
|
+
Constants.AUTHORIZATION_PENDING) {
|
|
156
|
+
request.destroy();
|
|
157
|
+
}
|
|
158
|
+
resolve(networkResponse);
|
|
159
|
+
});
|
|
160
|
+
socket.on("error", (chunk) => {
|
|
161
|
+
request.destroy();
|
|
162
|
+
socket.destroy();
|
|
163
|
+
reject(new Error(chunk.toString()));
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
request.on("error", (chunk) => {
|
|
167
|
+
request.destroy();
|
|
168
|
+
reject(new Error(chunk.toString()));
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
const networkRequestViaHttps = (urlString, httpMethod, options, agentOptions, timeout) => {
|
|
173
|
+
const isPostRequest = httpMethod === HttpMethod.POST;
|
|
174
|
+
const body = options?.body || "";
|
|
175
|
+
const url = new URL(urlString);
|
|
176
|
+
const headers = options?.headers || {};
|
|
177
|
+
const customOptions = {
|
|
178
|
+
method: httpMethod,
|
|
179
|
+
headers: headers,
|
|
180
|
+
...NetworkUtils.urlToHttpOptions(url),
|
|
181
|
+
};
|
|
182
|
+
if (agentOptions && Object.keys(agentOptions).length) {
|
|
183
|
+
customOptions.agent = new https.Agent(agentOptions);
|
|
184
|
+
}
|
|
185
|
+
if (isPostRequest) {
|
|
186
|
+
// needed for post request to work
|
|
187
|
+
customOptions.headers = {
|
|
188
|
+
...customOptions.headers,
|
|
189
|
+
"Content-Length": body.length,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// optional timeout is only for get requests (regionDiscovery, for example)
|
|
194
|
+
if (timeout) {
|
|
195
|
+
customOptions.timeout = timeout;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
let request;
|
|
200
|
+
// managed identity sources use http instead of https
|
|
201
|
+
if (customOptions.protocol === "http:") {
|
|
202
|
+
request = http.request(customOptions);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
request = https.request(customOptions);
|
|
206
|
+
}
|
|
207
|
+
if (isPostRequest) {
|
|
208
|
+
request.write(body);
|
|
209
|
+
}
|
|
210
|
+
if (timeout) {
|
|
211
|
+
request.on("timeout", () => {
|
|
212
|
+
request.destroy();
|
|
213
|
+
reject(new Error("Request time out"));
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
request.end();
|
|
217
|
+
request.on("response", (response) => {
|
|
218
|
+
const headers = response.headers;
|
|
219
|
+
const statusCode = response.statusCode;
|
|
220
|
+
const statusMessage = response.statusMessage;
|
|
221
|
+
const data = [];
|
|
222
|
+
response.on("data", (chunk) => {
|
|
223
|
+
data.push(chunk);
|
|
224
|
+
});
|
|
225
|
+
response.on("end", () => {
|
|
226
|
+
// combine all received buffer streams into one buffer, and then into a string
|
|
227
|
+
const body = Buffer.concat([...data]).toString();
|
|
228
|
+
const parsedHeaders = headers;
|
|
229
|
+
const networkResponse = NetworkUtils.getNetworkResponse(parsedHeaders, parseBody(statusCode, statusMessage, parsedHeaders, body), statusCode);
|
|
230
|
+
if ((statusCode < HttpStatus.SUCCESS_RANGE_START ||
|
|
231
|
+
statusCode > HttpStatus.SUCCESS_RANGE_END) &&
|
|
232
|
+
// do not destroy the request for the device code flow
|
|
233
|
+
networkResponse.body["error"] !==
|
|
234
|
+
Constants.AUTHORIZATION_PENDING) {
|
|
235
|
+
request.destroy();
|
|
236
|
+
}
|
|
237
|
+
resolve(networkResponse);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
request.on("error", (chunk) => {
|
|
241
|
+
request.destroy();
|
|
242
|
+
reject(new Error(chunk.toString()));
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Check if extra parsing is needed on the repsonse from the server
|
|
248
|
+
* @param statusCode {number} the status code of the response from the server
|
|
249
|
+
* @param statusMessage {string | undefined} the status message of the response from the server
|
|
250
|
+
* @param headers {Record<string, string>} the headers of the response from the server
|
|
251
|
+
* @param body {string} the body from the response of the server
|
|
252
|
+
* @returns {Object} JSON parsed body or error object
|
|
253
|
+
*/
|
|
254
|
+
const parseBody = (statusCode, statusMessage, headers, body) => {
|
|
255
|
+
/*
|
|
256
|
+
* Informational responses (100 – 199)
|
|
257
|
+
* Successful responses (200 – 299)
|
|
258
|
+
* Redirection messages (300 – 399)
|
|
259
|
+
* Client error responses (400 – 499)
|
|
260
|
+
* Server error responses (500 – 599)
|
|
261
|
+
*/
|
|
262
|
+
let parsedBody;
|
|
263
|
+
try {
|
|
264
|
+
parsedBody = JSON.parse(body);
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
let errorType;
|
|
268
|
+
let errorDescriptionHelper;
|
|
269
|
+
if (statusCode >= HttpStatus.CLIENT_ERROR_RANGE_START &&
|
|
270
|
+
statusCode <= HttpStatus.CLIENT_ERROR_RANGE_END) {
|
|
271
|
+
errorType = "client_error";
|
|
272
|
+
errorDescriptionHelper = "A client";
|
|
273
|
+
}
|
|
274
|
+
else if (statusCode >= HttpStatus.SERVER_ERROR_RANGE_START &&
|
|
275
|
+
statusCode <= HttpStatus.SERVER_ERROR_RANGE_END) {
|
|
276
|
+
errorType = "server_error";
|
|
277
|
+
errorDescriptionHelper = "A server";
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
errorType = "unknown_error";
|
|
281
|
+
errorDescriptionHelper = "An unknown";
|
|
282
|
+
}
|
|
283
|
+
parsedBody = {
|
|
284
|
+
error: errorType,
|
|
285
|
+
error_description: `${errorDescriptionHelper} error occured.\nHttp status code: ${statusCode}\nHttp status message: ${statusMessage || "Unknown"}\nHeaders: ${JSON.stringify(headers)}`,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return parsedBody;
|
|
289
289
|
};
|
|
290
290
|
|
|
291
291
|
export { HttpClient };
|
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
/*! @azure/msal-node v2.
|
|
1
|
+
/*! @azure/msal-node v2.13.0 2024-08-13 */
|
|
2
2
|
'use strict';
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
|
+
|
|
5
7
|
var msalCommon = require('@azure/msal-common');
|
|
6
8
|
var Constants = require('../utils/Constants.cjs');
|
|
7
9
|
|
|
8
|
-
/*
|
|
9
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
-
* Licensed under the MIT License.
|
|
11
|
-
*/
|
|
12
|
-
class HttpClientWithRetries {
|
|
13
|
-
constructor(httpClientNoRetries, retryPolicy) {
|
|
14
|
-
this.httpClientNoRetries = httpClientNoRetries;
|
|
15
|
-
this.retryPolicy = retryPolicy;
|
|
16
|
-
}
|
|
17
|
-
async sendNetworkRequestAsyncHelper(httpMethod, url, options) {
|
|
18
|
-
if (httpMethod === Constants.HttpMethod.GET) {
|
|
19
|
-
return this.httpClientNoRetries.sendGetRequestAsync(url, options);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return this.httpClientNoRetries.sendPostRequestAsync(url, options);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async sendNetworkRequestAsync(httpMethod, url, options) {
|
|
26
|
-
// the underlying network module (custom or HttpClient) will make the call
|
|
27
|
-
let response = await this.sendNetworkRequestAsyncHelper(httpMethod, url, options);
|
|
28
|
-
let currentRetry = 0;
|
|
29
|
-
while (await this.retryPolicy.pauseForRetry(response.status, currentRetry, response.headers[msalCommon.HeaderNames.RETRY_AFTER])) {
|
|
30
|
-
response = await this.sendNetworkRequestAsyncHelper(httpMethod, url, options);
|
|
31
|
-
currentRetry++;
|
|
32
|
-
}
|
|
33
|
-
return response;
|
|
34
|
-
}
|
|
35
|
-
async sendGetRequestAsync(url, options) {
|
|
36
|
-
return this.sendNetworkRequestAsync(Constants.HttpMethod.GET, url, options);
|
|
37
|
-
}
|
|
38
|
-
async sendPostRequestAsync(url, options) {
|
|
39
|
-
return this.sendNetworkRequestAsync(Constants.HttpMethod.POST, url, options);
|
|
40
|
-
}
|
|
10
|
+
/*
|
|
11
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
12
|
+
* Licensed under the MIT License.
|
|
13
|
+
*/
|
|
14
|
+
class HttpClientWithRetries {
|
|
15
|
+
constructor(httpClientNoRetries, retryPolicy) {
|
|
16
|
+
this.httpClientNoRetries = httpClientNoRetries;
|
|
17
|
+
this.retryPolicy = retryPolicy;
|
|
18
|
+
}
|
|
19
|
+
async sendNetworkRequestAsyncHelper(httpMethod, url, options) {
|
|
20
|
+
if (httpMethod === Constants.HttpMethod.GET) {
|
|
21
|
+
return this.httpClientNoRetries.sendGetRequestAsync(url, options);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return this.httpClientNoRetries.sendPostRequestAsync(url, options);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async sendNetworkRequestAsync(httpMethod, url, options) {
|
|
28
|
+
// the underlying network module (custom or HttpClient) will make the call
|
|
29
|
+
let response = await this.sendNetworkRequestAsyncHelper(httpMethod, url, options);
|
|
30
|
+
let currentRetry = 0;
|
|
31
|
+
while (await this.retryPolicy.pauseForRetry(response.status, currentRetry, response.headers[msalCommon.HeaderNames.RETRY_AFTER])) {
|
|
32
|
+
response = await this.sendNetworkRequestAsyncHelper(httpMethod, url, options);
|
|
33
|
+
currentRetry++;
|
|
34
|
+
}
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
37
|
+
async sendGetRequestAsync(url, options) {
|
|
38
|
+
return this.sendNetworkRequestAsync(Constants.HttpMethod.GET, url, options);
|
|
39
|
+
}
|
|
40
|
+
async sendPostRequestAsync(url, options) {
|
|
41
|
+
return this.sendNetworkRequestAsync(Constants.HttpMethod.POST, url, options);
|
|
42
|
+
}
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
exports.HttpClientWithRetries = HttpClientWithRetries;
|