@azure/msal-node 1.9.0 → 1.9.1

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/index.d.ts CHANGED
@@ -25,6 +25,6 @@ export type { OnBehalfOfRequest } from "./request/OnBehalfOfRequest";
25
25
  export type { UsernamePasswordRequest } from "./request/UsernamePasswordRequest";
26
26
  export type { RefreshTokenRequest } from "./request/RefreshTokenRequest";
27
27
  export type { SilentFlowRequest } from "./request/SilentFlowRequest";
28
- export { PromptValue, ResponseMode, AuthenticationResult, AccountInfo, ValidCacheType, AuthError, AuthErrorMessage, ClientAuthError, ClientAuthErrorMessage, ClientConfigurationError, ClientConfigurationErrorMessage, InteractionRequiredAuthError, InteractionRequiredAuthErrorMessage, ServerError, INetworkModule, NetworkRequestOptions, NetworkResponse, Logger, LogLevel, ProtocolMode, ICachePlugin, TokenCacheContext, ISerializableTokenCache, AzureCloudInstance, AzureCloudOptions } from "@azure/msal-common";
28
+ export { PromptValue, ResponseMode, AuthorizationCodePayload, AuthenticationResult, AccountInfo, ValidCacheType, AuthError, AuthErrorMessage, ClientAuthError, ClientAuthErrorMessage, ClientConfigurationError, ClientConfigurationErrorMessage, InteractionRequiredAuthError, InteractionRequiredAuthErrorMessage, ServerError, INetworkModule, NetworkRequestOptions, NetworkResponse, Logger, LogLevel, ProtocolMode, ICachePlugin, TokenCacheContext, ISerializableTokenCache, AzureCloudInstance, AzureCloudOptions } from "@azure/msal-common";
29
29
  export { version } from "./packageMetadata";
30
30
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAKA;;;GAGG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OA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AE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AACtO,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAGpF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,YAAY,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AACnF,YAAY,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,YAAY,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,YAAY,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,YAAY,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,YAAY,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,YAAY,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,YAAY,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGrE,OAAO,EAEH,WAAW,EACX,YAAY,EACZ,wBAAwB,EAExB,oBAAoB,EAEpB,WAAW,EACX,cAAc,EAEd,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,wBAAwB,EACxB,+BAA+B,EAC/B,4BAA4B,EAC5B,mCAAmC,EACnC,WAAW,EAEX,cAAc,EACd,qBAAqB,EACrB,eAAe,EAEf,MAAM,EACN,QAAQ,EAER,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EAEvB,kBAAkB,EAClB,iBAAiB,EACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC"}
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
7
  var msalCommon = require('@azure/msal-common');
8
- var axios = _interopDefault(require('axios'));
9
- var createHttpsProxyAgent = _interopDefault(require('https-proxy-agent'));
8
+ var http = _interopDefault(require('http'));
9
+ var https = _interopDefault(require('https'));
10
10
  var uuid = require('uuid');
11
11
  var crypto = _interopDefault(require('crypto'));
12
12
  var jsonwebtoken = require('jsonwebtoken');
@@ -56,7 +56,8 @@ const CharSet = {
56
56
 
57
57
  const Constants = {
58
58
  MSAL_SKU: "msal.js.node",
59
- JWT_BEARER_ASSERTION_TYPE: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
59
+ JWT_BEARER_ASSERTION_TYPE: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
60
+ AUTHORIZATION_PENDING: "authorization_pending"
60
61
  };
61
62
  /**
62
63
  * API Codes for Telemetry purposes.
@@ -109,29 +110,11 @@ class HttpClient {
109
110
  * @param options
110
111
  */
111
112
  async sendGetRequestAsync(url, options) {
112
- const request = {
113
- method: HttpMethod.GET,
114
- url: url,
115
-
116
- /* istanbul ignore next */
117
- headers: options && options.headers,
118
-
119
- /* istanbul ignore next */
120
- validateStatus: () => true
121
- };
122
-
123
- if (options && options.proxyUrl) {
124
- // for axios, this has to be disabled
125
- request.proxy = false;
126
- request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
113
+ if (options != null && options.proxyUrl) {
114
+ return networkRequestViaProxy(url, HttpMethod.GET, options);
115
+ } else {
116
+ return networkRequestViaHttps(url, HttpMethod.GET, options);
127
117
  }
128
-
129
- const response = await axios(request);
130
- return {
131
- headers: response.headers,
132
- body: response.data,
133
- status: response.status
134
- };
135
118
  }
136
119
  /**
137
120
  * Http Post request
@@ -141,36 +124,207 @@ class HttpClient {
141
124
 
142
125
 
143
126
  async sendPostRequestAsync(url, options, cancellationToken) {
144
- const request = {
145
- method: HttpMethod.POST,
146
- url: url,
127
+ if (options != null && options.proxyUrl) {
128
+ return networkRequestViaProxy(url, HttpMethod.POST, options, cancellationToken);
129
+ } else {
130
+ return networkRequestViaHttps(url, HttpMethod.POST, options, cancellationToken);
131
+ }
132
+ }
147
133
 
148
- /* istanbul ignore next */
149
- data: options && options.body || msalCommon.Constants.EMPTY_STRING,
150
- timeout: cancellationToken,
134
+ }
151
135
 
152
- /* istanbul ignore next */
153
- headers: options && options.headers,
136
+ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
137
+ const headers = (options == null ? void 0 : options.headers) || {};
138
+ const proxyUrl = new URL((options == null ? void 0 : options.proxyUrl) || "");
139
+ const destinationUrl = new URL(url); // "method: connect" must be used to establish a connection to the proxy
140
+
141
+ const tunnelRequestOptions = {
142
+ host: proxyUrl.hostname,
143
+ port: proxyUrl.port,
144
+ method: "CONNECT",
145
+ path: destinationUrl.hostname,
146
+ headers: headers
147
+ };
148
+
149
+ if (timeout) {
150
+ tunnelRequestOptions.timeout = timeout;
151
+ } // compose a request string for the socket
154
152
 
155
- /* istanbul ignore next */
156
- validateStatus: () => true
157
- };
158
153
 
159
- if (options && options.proxyUrl) {
160
- // for axios, this has to be disabled
161
- request.proxy = false;
162
- request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
154
+ let postRequestStringContent = "";
155
+
156
+ if (httpMethod === HttpMethod.POST) {
157
+ const body = (options == null ? void 0 : options.body) || "";
158
+ postRequestStringContent = "Content-Type: application/x-www-form-urlencoded\r\n" + `Content-Length: ${body.length}\r\n` + `\r\n${body}`;
159
+ }
160
+
161
+ const outgoingRequestString = `${httpMethod.toUpperCase()} ${destinationUrl.href} HTTP/1.1\r\n` + `Host: ${destinationUrl.host}\r\n` + "Connection: close\r\n" + postRequestStringContent + "\r\n";
162
+ return new Promise((resolve, reject) => {
163
+ const request = http.request(tunnelRequestOptions);
164
+
165
+ if (tunnelRequestOptions.timeout) {
166
+ request.on("timeout", () => {
167
+ request.destroy();
168
+ reject(new Error("Request time out"));
169
+ });
163
170
  }
164
171
 
165
- const response = await axios(request);
166
- return {
167
- headers: response.headers,
168
- body: response.data,
169
- status: response.status
172
+ request.end(); // establish connection to the proxy
173
+
174
+ request.on("connect", (response, socket) => {
175
+ const statusCode = (response == null ? void 0 : response.statusCode) || 500;
176
+
177
+ if (statusCode < 200 || statusCode > 299) {
178
+ request.destroy();
179
+ socket.destroy();
180
+ reject(new Error(`HTTP status code ${statusCode}`));
181
+ }
182
+
183
+ if (tunnelRequestOptions.timeout) {
184
+ socket.setTimeout(tunnelRequestOptions.timeout);
185
+ socket.on("timeout", () => {
186
+ request.destroy();
187
+ socket.destroy();
188
+ reject(new Error("Request time out"));
189
+ });
190
+ } // make a request over an HTTP tunnel
191
+
192
+
193
+ socket.write(outgoingRequestString);
194
+ const data = [];
195
+ socket.on("data", chunk => {
196
+ data.push(chunk);
197
+ });
198
+ socket.on("end", () => {
199
+ // combine all received buffer streams into one buffer, and then into a string
200
+ const dataString = Buffer.concat([...data]).toString(); // separate each line into it's own entry in an arry
201
+
202
+ const dataStringArray = dataString.split("\r\n"); // the first entry will contain the statusCode
203
+
204
+ const statusCode = parseInt(dataStringArray[0].split(" ")[1]); // the last entry will contain the body
205
+
206
+ const body = dataStringArray[dataStringArray.length - 1]; // everything in between the first and last entries are the headers
207
+
208
+ const headersArray = dataStringArray.slice(1, dataStringArray.length - 2); // build an object out of all the headers
209
+
210
+ const entries = new Map();
211
+ headersArray.forEach(header => {
212
+ /**
213
+ * the header might look like "Content-Length: 1531", but that is just a string
214
+ * it needs to be converted to a key/value pair
215
+ * split the string at the first instance of ":"
216
+ * there may be more than one ":" if the value of the header is supposed to be a JSON object
217
+ */
218
+ const headerKeyValue = header.split(new RegExp(/:\s(.*)/s));
219
+ const headerKey = headerKeyValue[0];
220
+ let headerValue = headerKeyValue[1]; // check if the value of the header is supposed to be a JSON object
221
+
222
+ try {
223
+ const object = JSON.parse(headerValue); // if it is, then convert it from a string to a JSON object
224
+
225
+ if (object && typeof object === "object") {
226
+ headerValue = object;
227
+ }
228
+ } catch (e) {// otherwise, leave it as a string
229
+ }
230
+
231
+ entries.set(headerKey, headerValue);
232
+ });
233
+ const headers = Object.fromEntries(entries);
234
+ const networkResponse = {
235
+ headers: headers,
236
+ body: JSON.parse(body),
237
+ status: statusCode
238
+ };
239
+
240
+ if ((statusCode < 200 || statusCode > 299) && // do not destroy the request for the device code flow
241
+ networkResponse.body["error"] !== Constants.AUTHORIZATION_PENDING) {
242
+ request.destroy();
243
+ socket.destroy();
244
+ reject(new Error(`HTTP status code ${statusCode}`));
245
+ }
246
+
247
+ resolve(networkResponse);
248
+ });
249
+ socket.on("error", chunk => {
250
+ request.destroy();
251
+ socket.destroy();
252
+ reject(new Error(chunk.toString()));
253
+ });
254
+ });
255
+ request.on("error", chunk => {
256
+ request.destroy();
257
+ reject(new Error(chunk.toString()));
258
+ });
259
+ });
260
+ };
261
+
262
+ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
263
+ const isPostRequest = httpMethod === HttpMethod.POST;
264
+ const body = (options == null ? void 0 : options.body) || "";
265
+ const emptyHeaders = {};
266
+ const customOptions = {
267
+ method: httpMethod,
268
+ headers: (options == null ? void 0 : options.headers) || emptyHeaders
269
+ };
270
+
271
+ if (timeout) {
272
+ customOptions.timeout = timeout;
273
+ }
274
+
275
+ if (isPostRequest) {
276
+ // needed for post request to work
277
+ customOptions.headers = { ...customOptions.headers,
278
+ "Content-Length": body.length
170
279
  };
171
280
  }
172
281
 
173
- }
282
+ return new Promise((resolve, reject) => {
283
+ const request = https.request(url, customOptions);
284
+
285
+ if (timeout) {
286
+ request.on("timeout", () => {
287
+ request.destroy();
288
+ reject(new Error("Request time out"));
289
+ });
290
+ }
291
+
292
+ if (isPostRequest) {
293
+ request.write(body);
294
+ }
295
+
296
+ request.end();
297
+ request.on("response", response => {
298
+ const headers = response.headers;
299
+ const statusCode = response.statusCode;
300
+ const data = [];
301
+ response.on("data", chunk => {
302
+ data.push(chunk);
303
+ });
304
+ response.on("end", () => {
305
+ // combine all received buffer streams into one buffer, and then into a string
306
+ const body = Buffer.concat([...data]).toString();
307
+ const networkResponse = {
308
+ headers: headers,
309
+ body: JSON.parse(body),
310
+ status: statusCode
311
+ };
312
+
313
+ if ((statusCode < 200 || statusCode > 299) && // do not destroy the request for the device code flow
314
+ networkResponse.body["error"] !== Constants.AUTHORIZATION_PENDING) {
315
+ request.destroy();
316
+ reject(new Error(`HTTP status code ${statusCode}`));
317
+ }
318
+
319
+ resolve(networkResponse);
320
+ });
321
+ });
322
+ request.on("error", chunk => {
323
+ request.destroy();
324
+ reject(new Error(chunk.toString()));
325
+ });
326
+ });
327
+ };
174
328
 
175
329
  /*
176
330
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1603,7 +1757,7 @@ class TokenCache {
1603
1757
 
1604
1758
  /* eslint-disable header/header */
1605
1759
  const name = "@azure/msal-node";
1606
- const version = "1.9.0";
1760
+ const version = "1.9.1";
1607
1761
 
1608
1762
  /*
1609
1763
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1917,7 +2071,7 @@ class ClientApplication {
1917
2071
  authorityMetadata: this.config.auth.authorityMetadata,
1918
2072
  azureRegionConfiguration
1919
2073
  };
1920
- return await msalCommon.AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
2074
+ return await msalCommon.AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions, this.config.system.proxyUrl);
1921
2075
  }
1922
2076
  /**
1923
2077
  * Clear the cache
@@ -2117,13 +2271,13 @@ class ClientAssertion {
2117
2271
  * "." means any string character, "+" means match 1 or more times, and "?" means the shortest match.
2118
2272
  * The "g" at the end of the regex means search the string globally, and the "s" enables the "." to match newlines.
2119
2273
  */
2120
- const regexToFindCerts = /-----BEGIN CERTIFICATE-----\n(.+?)\n-----END CERTIFICATE-----/gs;
2274
+ const regexToFindCerts = /-----BEGIN CERTIFICATE-----\r*\n(.+?)\r*\n-----END CERTIFICATE-----/gs;
2121
2275
  const certs = [];
2122
2276
  let matches;
2123
2277
 
2124
2278
  while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
2125
2279
  // matches[1] represents the first parens capture group in the regex.
2126
- certs.push(matches[1].replace(/\n/, msalCommon.Constants.EMPTY_STRING));
2280
+ certs.push(matches[1].replace(/\r*\n/g, msalCommon.Constants.EMPTY_STRING));
2127
2281
  }
2128
2282
 
2129
2283
  return certs;