@azure/msal-node 1.14.5 → 1.14.6

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.
@@ -16,19 +16,15 @@ var jsonwebtoken = require('jsonwebtoken');
16
16
  * Copyright (c) Microsoft Corporation. All rights reserved.
17
17
  * Licensed under the MIT License.
18
18
  */
19
-
20
19
  /**
21
20
  * http methods
22
21
  */
23
22
  var HttpMethod;
24
-
25
23
  (function (HttpMethod) {
26
24
  HttpMethod["GET"] = "get";
27
25
  HttpMethod["POST"] = "post";
28
26
  })(HttpMethod || (HttpMethod = {}));
29
-
30
27
  var HttpStatus;
31
-
32
28
  (function (HttpStatus) {
33
29
  HttpStatus[HttpStatus["SUCCESS_RANGE_START"] = 200] = "SUCCESS_RANGE_START";
34
30
  HttpStatus[HttpStatus["SUCCESS_RANGE_END"] = 299] = "SUCCESS_RANGE_END";
@@ -38,9 +34,7 @@ var HttpStatus;
38
34
  HttpStatus[HttpStatus["SERVER_ERROR_RANGE_START"] = 500] = "SERVER_ERROR_RANGE_START";
39
35
  HttpStatus[HttpStatus["SERVER_ERROR_RANGE_END"] = 599] = "SERVER_ERROR_RANGE_END";
40
36
  })(HttpStatus || (HttpStatus = {}));
41
-
42
37
  var ProxyStatus;
43
-
44
38
  (function (ProxyStatus) {
45
39
  ProxyStatus[ProxyStatus["SUCCESS_RANGE_START"] = 200] = "SUCCESS_RANGE_START";
46
40
  ProxyStatus[ProxyStatus["SUCCESS_RANGE_END"] = 299] = "SUCCESS_RANGE_END";
@@ -49,32 +43,26 @@ var ProxyStatus;
49
43
  /**
50
44
  * Constants used for region discovery
51
45
  */
52
-
53
-
54
46
  const REGION_ENVIRONMENT_VARIABLE = "REGION_NAME";
55
47
  /**
56
48
  * Constant used for PKCE
57
49
  */
58
-
59
50
  const RANDOM_OCTET_SIZE = 32;
60
51
  /**
61
52
  * Constants used in PKCE
62
53
  */
63
-
64
54
  const Hash = {
65
55
  SHA256: "sha256"
66
56
  };
67
57
  /**
68
58
  * Constants for encoding schemes
69
59
  */
70
-
71
60
  const CharSet = {
72
61
  CV_CHARSET: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
73
62
  };
74
63
  /**
75
64
  * Constants
76
65
  */
77
-
78
66
  const Constants = {
79
67
  MSAL_SKU: "msal.js.node",
80
68
  JWT_BEARER_ASSERTION_TYPE: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
@@ -89,9 +77,7 @@ const Constants = {
89
77
  * 600-699 Device Code Flow
90
78
  * 800-899 Auth Code Flow
91
79
  */
92
-
93
80
  var ApiId;
94
-
95
81
  (function (ApiId) {
96
82
  ApiId[ApiId["acquireTokenSilent"] = 62] = "acquireTokenSilent";
97
83
  ApiId[ApiId["acquireTokenByUsernamePassword"] = 371] = "acquireTokenByUsernamePassword";
@@ -103,8 +89,6 @@ var ApiId;
103
89
  /**
104
90
  * JWT constants
105
91
  */
106
-
107
-
108
92
  const JwtConstants = {
109
93
  ALGORITHM: "alg",
110
94
  RSA_256: "RS256",
@@ -134,7 +118,6 @@ class NetworkUtils {
134
118
  status: statusCode
135
119
  };
136
120
  }
137
-
138
121
  }
139
122
 
140
123
  /*
@@ -144,7 +127,6 @@ class NetworkUtils {
144
127
  /**
145
128
  * This class implements the API for network requests.
146
129
  */
147
-
148
130
  class HttpClient {
149
131
  /**
150
132
  * Http Get request
@@ -163,8 +145,6 @@ class HttpClient {
163
145
  * @param url
164
146
  * @param options
165
147
  */
166
-
167
-
168
148
  async sendPostRequestAsync(url, options, cancellationToken) {
169
149
  if (options != null && options.proxyUrl) {
170
150
  return networkRequestViaProxy(url, HttpMethod.POST, options, cancellationToken);
@@ -172,14 +152,12 @@ class HttpClient {
172
152
  return networkRequestViaHttps(url, HttpMethod.POST, options, cancellationToken);
173
153
  }
174
154
  }
175
-
176
155
  }
177
-
178
156
  const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
179
157
  const headers = (options == null ? void 0 : options.headers) || {};
180
158
  const proxyUrl = new URL((options == null ? void 0 : options.proxyUrl) || "");
181
- const destinationUrl = new URL(url); // "method: connect" must be used to establish a connection to the proxy
182
-
159
+ const destinationUrl = new URL(url);
160
+ // "method: connect" must be used to establish a connection to the proxy
183
161
  const tunnelRequestOptions = {
184
162
  host: proxyUrl.hostname,
185
163
  port: proxyUrl.port,
@@ -187,41 +165,33 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
187
165
  path: destinationUrl.hostname,
188
166
  headers: headers
189
167
  };
190
-
191
168
  if (timeout) {
192
169
  tunnelRequestOptions.timeout = timeout;
193
- } // compose a request string for the socket
194
-
195
-
170
+ }
171
+ // compose a request string for the socket
196
172
  let postRequestStringContent = "";
197
-
198
173
  if (httpMethod === HttpMethod.POST) {
199
174
  const body = (options == null ? void 0 : options.body) || "";
200
175
  postRequestStringContent = "Content-Type: application/x-www-form-urlencoded\r\n" + `Content-Length: ${body.length}\r\n` + `\r\n${body}`;
201
176
  }
202
-
203
177
  const outgoingRequestString = `${httpMethod.toUpperCase()} ${destinationUrl.href} HTTP/1.1\r\n` + `Host: ${destinationUrl.host}\r\n` + "Connection: close\r\n" + postRequestStringContent + "\r\n";
204
178
  return new Promise((resolve, reject) => {
205
179
  const request = http__default.request(tunnelRequestOptions);
206
-
207
180
  if (tunnelRequestOptions.timeout) {
208
181
  request.on("timeout", () => {
209
182
  request.destroy();
210
183
  reject(new Error("Request time out"));
211
184
  });
212
185
  }
213
-
214
- request.end(); // establish connection to the proxy
215
-
186
+ request.end();
187
+ // establish connection to the proxy
216
188
  request.on("connect", (response, socket) => {
217
189
  const proxyStatusCode = (response == null ? void 0 : response.statusCode) || ProxyStatus.SERVER_ERROR;
218
-
219
190
  if (proxyStatusCode < ProxyStatus.SUCCESS_RANGE_START || proxyStatusCode > ProxyStatus.SUCCESS_RANGE_END) {
220
191
  request.destroy();
221
192
  socket.destroy();
222
193
  reject(new Error(`Error connecting to proxy. Http status code: ${response.statusCode}. Http status message: ${(response == null ? void 0 : response.statusMessage) || "Unknown"}`));
223
194
  }
224
-
225
195
  if (tunnelRequestOptions.timeout) {
226
196
  socket.setTimeout(tunnelRequestOptions.timeout);
227
197
  socket.on("timeout", () => {
@@ -229,9 +199,8 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
229
199
  socket.destroy();
230
200
  reject(new Error("Request time out"));
231
201
  });
232
- } // make a request over an HTTP tunnel
233
-
234
-
202
+ }
203
+ // make a request over an HTTP tunnel
235
204
  socket.write(outgoingRequestString);
236
205
  const data = [];
237
206
  socket.on("data", chunk => {
@@ -239,18 +208,18 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
239
208
  });
240
209
  socket.on("end", () => {
241
210
  // combine all received buffer streams into one buffer, and then into a string
242
- const dataString = Buffer.concat([...data]).toString(); // separate each line into it's own entry in an arry
243
-
244
- const dataStringArray = dataString.split("\r\n"); // the first entry will contain the statusCode and statusMessage
245
-
246
- const httpStatusCode = parseInt(dataStringArray[0].split(" ")[1]); // remove "HTTP/1.1" and the status code to get the status message
247
-
248
- const statusMessage = dataStringArray[0].split(" ").slice(2).join(" "); // the last entry will contain the body
249
-
250
- const body = dataStringArray[dataStringArray.length - 1]; // everything in between the first and last entries are the headers
251
-
252
- const headersArray = dataStringArray.slice(1, dataStringArray.length - 2); // build an object out of all the headers
253
-
211
+ const dataString = Buffer.concat([...data]).toString();
212
+ // separate each line into it's own entry in an arry
213
+ const dataStringArray = dataString.split("\r\n");
214
+ // the first entry will contain the statusCode and statusMessage
215
+ const httpStatusCode = parseInt(dataStringArray[0].split(" ")[1]);
216
+ // remove "HTTP/1.1" and the status code to get the status message
217
+ const statusMessage = dataStringArray[0].split(" ").slice(2).join(" ");
218
+ // the last entry will contain the body
219
+ const body = dataStringArray[dataStringArray.length - 1];
220
+ // everything in between the first and last entries are the headers
221
+ const headersArray = dataStringArray.slice(1, dataStringArray.length - 2);
222
+ // build an object out of all the headers
254
223
  const entries = new Map();
255
224
  headersArray.forEach(header => {
256
225
  /**
@@ -261,28 +230,27 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
261
230
  */
262
231
  const headerKeyValue = header.split(new RegExp(/:\s(.*)/s));
263
232
  const headerKey = headerKeyValue[0];
264
- let headerValue = headerKeyValue[1]; // check if the value of the header is supposed to be a JSON object
265
-
233
+ let headerValue = headerKeyValue[1];
234
+ // check if the value of the header is supposed to be a JSON object
266
235
  try {
267
- const object = JSON.parse(headerValue); // if it is, then convert it from a string to a JSON object
268
-
236
+ const object = JSON.parse(headerValue);
237
+ // if it is, then convert it from a string to a JSON object
269
238
  if (object && typeof object === "object") {
270
239
  headerValue = object;
271
240
  }
272
- } catch (e) {// otherwise, leave it as a string
241
+ } catch (e) {
242
+ // otherwise, leave it as a string
273
243
  }
274
-
275
244
  entries.set(headerKey, headerValue);
276
245
  });
277
246
  const headers = Object.fromEntries(entries);
278
247
  const parsedHeaders = headers;
279
248
  const networkResponse = NetworkUtils.getNetworkResponse(parsedHeaders, parseBody(httpStatusCode, statusMessage, parsedHeaders, body), httpStatusCode);
280
-
281
- if ((httpStatusCode < HttpStatus.SUCCESS_RANGE_START || httpStatusCode > HttpStatus.SUCCESS_RANGE_END) && // do not destroy the request for the device code flow
249
+ if ((httpStatusCode < HttpStatus.SUCCESS_RANGE_START || httpStatusCode > HttpStatus.SUCCESS_RANGE_END) &&
250
+ // do not destroy the request for the device code flow
282
251
  networkResponse.body["error"] !== Constants.AUTHORIZATION_PENDING) {
283
252
  request.destroy();
284
253
  }
285
-
286
254
  resolve(networkResponse);
287
255
  });
288
256
  socket.on("error", chunk => {
@@ -297,7 +265,6 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
297
265
  });
298
266
  });
299
267
  };
300
-
301
268
  const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
302
269
  const isPostRequest = httpMethod === HttpMethod.POST;
303
270
  const body = (options == null ? void 0 : options.body) || "";
@@ -306,32 +273,27 @@ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
306
273
  method: httpMethod,
307
274
  headers: (options == null ? void 0 : options.headers) || emptyHeaders
308
275
  };
309
-
310
276
  if (timeout) {
311
277
  customOptions.timeout = timeout;
312
278
  }
313
-
314
279
  if (isPostRequest) {
315
280
  // needed for post request to work
316
- customOptions.headers = { ...customOptions.headers,
281
+ customOptions.headers = {
282
+ ...customOptions.headers,
317
283
  "Content-Length": body.length
318
284
  };
319
285
  }
320
-
321
286
  return new Promise((resolve, reject) => {
322
287
  const request = https.request(url, customOptions);
323
-
324
288
  if (timeout) {
325
289
  request.on("timeout", () => {
326
290
  request.destroy();
327
291
  reject(new Error("Request time out"));
328
292
  });
329
293
  }
330
-
331
294
  if (isPostRequest) {
332
295
  request.write(body);
333
296
  }
334
-
335
297
  request.end();
336
298
  request.on("response", response => {
337
299
  const headers = response.headers;
@@ -346,12 +308,11 @@ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
346
308
  const body = Buffer.concat([...data]).toString();
347
309
  const parsedHeaders = headers;
348
310
  const networkResponse = NetworkUtils.getNetworkResponse(parsedHeaders, parseBody(statusCode, statusMessage, parsedHeaders, body), statusCode);
349
-
350
- if ((statusCode < HttpStatus.SUCCESS_RANGE_START || statusCode > HttpStatus.SUCCESS_RANGE_END) && // do not destroy the request for the device code flow
311
+ if ((statusCode < HttpStatus.SUCCESS_RANGE_START || statusCode > HttpStatus.SUCCESS_RANGE_END) &&
312
+ // do not destroy the request for the device code flow
351
313
  networkResponse.body["error"] !== Constants.AUTHORIZATION_PENDING) {
352
314
  request.destroy();
353
315
  }
354
-
355
316
  resolve(networkResponse);
356
317
  });
357
318
  });
@@ -369,8 +330,6 @@ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
369
330
  * @param body {string} the body from the response of the server
370
331
  * @returns {Object} JSON parsed body or error object
371
332
  */
372
-
373
-
374
333
  const parseBody = (statusCode, statusMessage, headers, body) => {
375
334
  /*
376
335
  * Informational responses (100 – 199)
@@ -380,13 +339,11 @@ const parseBody = (statusCode, statusMessage, headers, body) => {
380
339
  * Server error responses (500 – 599)
381
340
  */
382
341
  let parsedBody;
383
-
384
342
  try {
385
343
  parsedBody = JSON.parse(body);
386
344
  } catch (error) {
387
345
  let errorType;
388
346
  let errorDescriptionHelper;
389
-
390
347
  if (statusCode >= HttpStatus.CLIENT_ERROR_RANGE_START && statusCode <= HttpStatus.CLIENT_ERROR_RANGE_END) {
391
348
  errorType = "client_error";
392
349
  errorDescriptionHelper = "A client";
@@ -397,13 +354,11 @@ const parseBody = (statusCode, statusMessage, headers, body) => {
397
354
  errorType = "unknown_error";
398
355
  errorDescriptionHelper = "An unknown";
399
356
  }
400
-
401
357
  parsedBody = {
402
358
  error: errorType,
403
359
  error_description: `${errorDescriptionHelper} error occured.\nHttp status code: ${statusCode}\nHttp status message: ${statusMessage || "Unknown"}\nHeaders: ${JSON.stringify(headers)}`
404
360
  };
405
361
  }
406
-
407
362
  return parsedBody;
408
363
  };
409
364
 
@@ -434,7 +389,8 @@ const DEFAULT_AUTH_OPTIONS = {
434
389
  };
435
390
  const DEFAULT_CACHE_OPTIONS = {};
436
391
  const DEFAULT_LOGGER_OPTIONS = {
437
- loggerCallback: () => {// allow users to not set logger call back
392
+ loggerCallback: () => {
393
+ // allow users to not set logger call back
438
394
  },
439
395
  piiLoggingEnabled: false,
440
396
  logLevel: msalCommon.LogLevel.Info
@@ -461,24 +417,31 @@ const DEFAULT_TELEMETRY_OPTIONS = {
461
417
  * @returns Configuration
462
418
  * @public
463
419
  */
464
-
465
420
  function buildAppConfiguration({
466
421
  auth,
467
422
  cache,
468
423
  system,
469
424
  telemetry
470
425
  }) {
426
+ const providedSystemOptions = {
427
+ ...system,
428
+ loggerOptions: (system == null ? void 0 : system.loggerOptions) || DEFAULT_LOGGER_OPTIONS
429
+ };
471
430
  return {
472
- auth: { ...DEFAULT_AUTH_OPTIONS,
431
+ auth: {
432
+ ...DEFAULT_AUTH_OPTIONS,
473
433
  ...auth
474
434
  },
475
- cache: { ...DEFAULT_CACHE_OPTIONS,
435
+ cache: {
436
+ ...DEFAULT_CACHE_OPTIONS,
476
437
  ...cache
477
438
  },
478
- system: { ...DEFAULT_SYSTEM_OPTIONS,
479
- ...system
439
+ system: {
440
+ ...DEFAULT_SYSTEM_OPTIONS,
441
+ ...providedSystemOptions
480
442
  },
481
- telemetry: { ...DEFAULT_TELEMETRY_OPTIONS,
443
+ telemetry: {
444
+ ...DEFAULT_TELEMETRY_OPTIONS,
482
445
  ...telemetry
483
446
  }
484
447
  };
@@ -501,13 +464,10 @@ class GuidGenerator {
501
464
  * verifies if a string is GUID
502
465
  * @param guid
503
466
  */
504
-
505
-
506
467
  isGuid(guid) {
507
468
  const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
508
469
  return regexGuid.test(guid);
509
470
  }
510
-
511
471
  }
512
472
 
513
473
  /*
@@ -528,8 +488,6 @@ class EncodingUtils {
528
488
  * encode a URL
529
489
  * @param str
530
490
  */
531
-
532
-
533
491
  static base64EncodeUrl(str, encoding) {
534
492
  return EncodingUtils.base64Encode(str, encoding).replace(/=/g, msalCommon.Constants.EMPTY_STRING).replace(/\+/g, "-").replace(/\//g, "_");
535
493
  }
@@ -539,26 +497,19 @@ class EncodingUtils {
539
497
  *
540
498
  * @param base64Str Base64 encoded text
541
499
  */
542
-
543
-
544
500
  static base64Decode(base64Str) {
545
501
  return Buffer.from(base64Str, "base64").toString("utf8");
546
502
  }
547
503
  /**
548
504
  * @param base64Str Base64 encoded Url
549
505
  */
550
-
551
-
552
506
  static base64DecodeUrl(base64Str) {
553
507
  let str = base64Str.replace(/-/g, "+").replace(/_/g, "/");
554
-
555
508
  while (str.length % 4) {
556
509
  str += "=";
557
510
  }
558
-
559
511
  return EncodingUtils.base64Decode(str);
560
512
  }
561
-
562
513
  }
563
514
 
564
515
  /*
@@ -573,7 +524,6 @@ class HashUtils {
573
524
  sha256(buffer) {
574
525
  return crypto.createHash(Hash.SHA256).update(buffer).digest();
575
526
  }
576
-
577
527
  }
578
528
 
579
529
  /*
@@ -583,7 +533,6 @@ class HashUtils {
583
533
  /**
584
534
  * https://tools.ietf.org/html/rfc7636#page-8
585
535
  */
586
-
587
536
  class PkceGenerator {
588
537
  constructor() {
589
538
  this.hashUtils = new HashUtils();
@@ -592,8 +541,6 @@ class PkceGenerator {
592
541
  * generates the codeVerfier and the challenge from the codeVerfier
593
542
  * reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
594
543
  */
595
-
596
-
597
544
  async generatePkceCodes() {
598
545
  const verifier = this.generateCodeVerifier();
599
546
  const challenge = this.generateCodeChallengeFromVerifier(verifier);
@@ -605,15 +552,11 @@ class PkceGenerator {
605
552
  /**
606
553
  * generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
607
554
  */
608
-
609
-
610
555
  generateCodeVerifier() {
611
556
  const charArr = [];
612
557
  const maxNumber = 256 - 256 % CharSet.CV_CHARSET.length;
613
-
614
558
  while (charArr.length <= RANDOM_OCTET_SIZE) {
615
559
  const byte = crypto.randomBytes(1)[0];
616
-
617
560
  if (byte >= maxNumber) {
618
561
  /*
619
562
  * Ignore this number to maintain randomness.
@@ -621,11 +564,9 @@ class PkceGenerator {
621
564
  */
622
565
  continue;
623
566
  }
624
-
625
567
  const index = byte % CharSet.CV_CHARSET.length;
626
568
  charArr.push(CharSet.CV_CHARSET[index]);
627
569
  }
628
-
629
570
  const verifier = charArr.join(msalCommon.Constants.EMPTY_STRING);
630
571
  return EncodingUtils.base64EncodeUrl(verifier);
631
572
  }
@@ -633,12 +574,9 @@ class PkceGenerator {
633
574
  * generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
634
575
  * @param codeVerifier
635
576
  */
636
-
637
-
638
577
  generateCodeChallengeFromVerifier(codeVerifier) {
639
578
  return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
640
579
  }
641
-
642
580
  }
643
581
 
644
582
  /*
@@ -650,7 +588,6 @@ class PkceGenerator {
650
588
  * implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
651
589
  * @public
652
590
  */
653
-
654
591
  class CryptoProvider {
655
592
  constructor() {
656
593
  // Browser crypto needs to be validated first before any other classes can be set.
@@ -662,8 +599,6 @@ class CryptoProvider {
662
599
  * Creates a new random GUID - used to populate state and nonce.
663
600
  * @returns string (GUID)
664
601
  */
665
-
666
-
667
602
  createNewGuid() {
668
603
  return this.guidGenerator.generateGuid();
669
604
  }
@@ -671,8 +606,6 @@ class CryptoProvider {
671
606
  * Encodes input string to base64.
672
607
  * @param input - string to be encoded
673
608
  */
674
-
675
-
676
609
  base64Encode(input) {
677
610
  return EncodingUtils.base64Encode(input);
678
611
  }
@@ -680,24 +613,18 @@ class CryptoProvider {
680
613
  * Decodes input string from base64.
681
614
  * @param input - string to be decoded
682
615
  */
683
-
684
-
685
616
  base64Decode(input) {
686
617
  return EncodingUtils.base64Decode(input);
687
618
  }
688
619
  /**
689
620
  * Generates PKCE codes used in Authorization Code Flow.
690
621
  */
691
-
692
-
693
622
  generatePkceCodes() {
694
623
  return this.pkceGenerator.generatePkceCodes();
695
624
  }
696
625
  /**
697
626
  * Generates a keypair, stores it and returns a thumbprint - not yet implemented for node
698
627
  */
699
-
700
-
701
628
  getPublicKeyThumbprint() {
702
629
  throw new Error("Method not implemented.");
703
630
  }
@@ -705,36 +632,27 @@ class CryptoProvider {
705
632
  * Removes cryptographic keypair from key store matching the keyId passed in
706
633
  * @param kid
707
634
  */
708
-
709
-
710
635
  removeTokenBindingKey() {
711
636
  throw new Error("Method not implemented.");
712
637
  }
713
638
  /**
714
639
  * Removes all cryptographic keys from Keystore
715
640
  */
716
-
717
-
718
641
  clearKeystore() {
719
642
  throw new Error("Method not implemented.");
720
643
  }
721
644
  /**
722
645
  * Signs the given object as a jwt payload with private key retrieved by given kid - currently not implemented for node
723
646
  */
724
-
725
-
726
647
  signJwt() {
727
648
  throw new Error("Method not implemented.");
728
649
  }
729
650
  /**
730
651
  * Returns the SHA-256 hash of an input string
731
652
  */
732
-
733
-
734
653
  async hashString(plainText) {
735
654
  return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString("base64"), "base64");
736
655
  }
737
-
738
656
  }
739
657
 
740
658
  /*
@@ -744,7 +662,6 @@ class CryptoProvider {
744
662
  /**
745
663
  * This class deserializes cache entities read from the file into in memory object types defined internally
746
664
  */
747
-
748
665
  class Deserializer {
749
666
  /**
750
667
  * Parse the JSON blob in memory and deserialize the content
@@ -758,11 +675,8 @@ class Deserializer {
758
675
  * Deserializes accounts to AccountEntity objects
759
676
  * @param accounts
760
677
  */
761
-
762
-
763
678
  static deserializeAccounts(accounts) {
764
679
  const accountObjects = {};
765
-
766
680
  if (accounts) {
767
681
  Object.keys(accounts).map(function (key) {
768
682
  const serializedAcc = accounts[key];
@@ -783,18 +697,14 @@ class Deserializer {
783
697
  accountObjects[key] = account;
784
698
  });
785
699
  }
786
-
787
700
  return accountObjects;
788
701
  }
789
702
  /**
790
703
  * Deserializes id tokens to IdTokenEntity objects
791
704
  * @param idTokens
792
705
  */
793
-
794
-
795
706
  static deserializeIdTokens(idTokens) {
796
707
  const idObjects = {};
797
-
798
708
  if (idTokens) {
799
709
  Object.keys(idTokens).map(function (key) {
800
710
  const serializedIdT = idTokens[key];
@@ -811,18 +721,14 @@ class Deserializer {
811
721
  idObjects[key] = idToken;
812
722
  });
813
723
  }
814
-
815
724
  return idObjects;
816
725
  }
817
726
  /**
818
727
  * Deserializes access tokens to AccessTokenEntity objects
819
728
  * @param accessTokens
820
729
  */
821
-
822
-
823
730
  static deserializeAccessTokens(accessTokens) {
824
731
  const atObjects = {};
825
-
826
732
  if (accessTokens) {
827
733
  Object.keys(accessTokens).map(function (key) {
828
734
  const serializedAT = accessTokens[key];
@@ -849,18 +755,14 @@ class Deserializer {
849
755
  atObjects[key] = accessToken;
850
756
  });
851
757
  }
852
-
853
758
  return atObjects;
854
759
  }
855
760
  /**
856
761
  * Deserializes refresh tokens to RefreshTokenEntity objects
857
762
  * @param refreshTokens
858
763
  */
859
-
860
-
861
764
  static deserializeRefreshTokens(refreshTokens) {
862
765
  const rtObjects = {};
863
-
864
766
  if (refreshTokens) {
865
767
  Object.keys(refreshTokens).map(function (key) {
866
768
  const serializedRT = refreshTokens[key];
@@ -879,18 +781,14 @@ class Deserializer {
879
781
  rtObjects[key] = refreshToken;
880
782
  });
881
783
  }
882
-
883
784
  return rtObjects;
884
785
  }
885
786
  /**
886
787
  * Deserializes appMetadata to AppMetaData objects
887
788
  * @param appMetadata
888
789
  */
889
-
890
-
891
790
  static deserializeAppMetadata(appMetadata) {
892
791
  const appMetadataObjects = {};
893
-
894
792
  if (appMetadata) {
895
793
  Object.keys(appMetadata).map(function (key) {
896
794
  const serializedAmdt = appMetadata[key];
@@ -904,15 +802,12 @@ class Deserializer {
904
802
  appMetadataObjects[key] = amd;
905
803
  });
906
804
  }
907
-
908
805
  return appMetadataObjects;
909
806
  }
910
807
  /**
911
808
  * Deserialize an inMemory Cache
912
809
  * @param jsonCache
913
810
  */
914
-
915
-
916
811
  static deserializeAllCache(jsonCache) {
917
812
  return {
918
813
  accounts: jsonCache.Account ? this.deserializeAccounts(jsonCache.Account) : {},
@@ -922,7 +817,6 @@ class Deserializer {
922
817
  appMetadata: jsonCache.AppMetadata ? this.deserializeAppMetadata(jsonCache.AppMetadata) : {}
923
818
  };
924
819
  }
925
-
926
820
  }
927
821
 
928
822
  /*
@@ -941,8 +835,6 @@ class Serializer {
941
835
  * Serialize Accounts
942
836
  * @param accCache
943
837
  */
944
-
945
-
946
838
  static serializeAccounts(accCache) {
947
839
  const accounts = {};
948
840
  Object.keys(accCache).map(function (key) {
@@ -966,8 +858,6 @@ class Serializer {
966
858
  * Serialize IdTokens
967
859
  * @param idTCache
968
860
  */
969
-
970
-
971
861
  static serializeIdTokens(idTCache) {
972
862
  const idTokens = {};
973
863
  Object.keys(idTCache).map(function (key) {
@@ -987,8 +877,6 @@ class Serializer {
987
877
  * Serializes AccessTokens
988
878
  * @param atCache
989
879
  */
990
-
991
-
992
880
  static serializeAccessTokens(atCache) {
993
881
  const accessTokens = {};
994
882
  Object.keys(atCache).map(function (key) {
@@ -1018,8 +906,6 @@ class Serializer {
1018
906
  * Serialize refreshTokens
1019
907
  * @param rtCache
1020
908
  */
1021
-
1022
-
1023
909
  static serializeRefreshTokens(rtCache) {
1024
910
  const refreshTokens = {};
1025
911
  Object.keys(rtCache).map(function (key) {
@@ -1041,8 +927,6 @@ class Serializer {
1041
927
  * Serialize amdtCache
1042
928
  * @param amdtCache
1043
929
  */
1044
-
1045
-
1046
930
  static serializeAppMetadata(amdtCache) {
1047
931
  const appMetadata = {};
1048
932
  Object.keys(amdtCache).map(function (key) {
@@ -1059,8 +943,6 @@ class Serializer {
1059
943
  * Serialize the cache
1060
944
  * @param jsonContent
1061
945
  */
1062
-
1063
-
1064
946
  static serializeAllCache(inMemCache) {
1065
947
  return {
1066
948
  Account: this.serializeAccounts(inMemCache.accounts),
@@ -1070,7 +952,6 @@ class Serializer {
1070
952
  AppMetadata: this.serializeAppMetadata(inMemCache.appMetadata)
1071
953
  };
1072
954
  }
1073
-
1074
955
  }
1075
956
 
1076
957
  /*
@@ -1081,7 +962,6 @@ class Serializer {
1081
962
  * This class implements Storage for node, reading cache from user specified storage location or an extension library
1082
963
  * @public
1083
964
  */
1084
-
1085
965
  class NodeStorage extends msalCommon.CacheManager {
1086
966
  constructor(logger, clientId, cryptoImpl) {
1087
967
  super(clientId, cryptoImpl);
@@ -1093,16 +973,12 @@ class NodeStorage extends msalCommon.CacheManager {
1093
973
  * Queue up callbacks
1094
974
  * @param func - a callback function for cache change indication
1095
975
  */
1096
-
1097
-
1098
976
  registerChangeEmitter(func) {
1099
977
  this.changeEmitters.push(func);
1100
978
  }
1101
979
  /**
1102
980
  * Invoke the callback when cache changes
1103
981
  */
1104
-
1105
-
1106
982
  emitChange() {
1107
983
  this.changeEmitters.forEach(func => func.call(null));
1108
984
  }
@@ -1110,8 +986,6 @@ class NodeStorage extends msalCommon.CacheManager {
1110
986
  * Converts cacheKVStore to InMemoryCache
1111
987
  * @param cache - key value store
1112
988
  */
1113
-
1114
-
1115
989
  cacheToInMemoryCache(cache) {
1116
990
  const inMemoryCache = {
1117
991
  accounts: {},
@@ -1120,7 +994,6 @@ class NodeStorage extends msalCommon.CacheManager {
1120
994
  refreshTokens: {},
1121
995
  appMetadata: {}
1122
996
  };
1123
-
1124
997
  for (const key in cache) {
1125
998
  if (cache[key] instanceof msalCommon.AccountEntity) {
1126
999
  inMemoryCache.accounts[key] = cache[key];
@@ -1136,36 +1009,32 @@ class NodeStorage extends msalCommon.CacheManager {
1136
1009
  continue;
1137
1010
  }
1138
1011
  }
1139
-
1140
1012
  return inMemoryCache;
1141
1013
  }
1142
1014
  /**
1143
1015
  * converts inMemoryCache to CacheKVStore
1144
1016
  * @param inMemoryCache - kvstore map for inmemory
1145
1017
  */
1146
-
1147
-
1148
1018
  inMemoryCacheToCache(inMemoryCache) {
1149
1019
  // convert in memory cache to a flat Key-Value map
1150
1020
  let cache = this.getCache();
1151
- cache = { ...cache,
1021
+ cache = {
1022
+ ...cache,
1152
1023
  ...inMemoryCache.accounts,
1153
1024
  ...inMemoryCache.idTokens,
1154
1025
  ...inMemoryCache.accessTokens,
1155
1026
  ...inMemoryCache.refreshTokens,
1156
1027
  ...inMemoryCache.appMetadata
1157
- }; // convert in memory cache to a flat Key-Value map
1158
-
1028
+ };
1029
+ // convert in memory cache to a flat Key-Value map
1159
1030
  return cache;
1160
1031
  }
1161
1032
  /**
1162
1033
  * gets the current in memory cache for the client
1163
1034
  */
1164
-
1165
-
1166
1035
  getInMemoryCache() {
1167
- this.logger.trace("Getting in-memory cache"); // convert the cache key value store to inMemoryCache
1168
-
1036
+ this.logger.trace("Getting in-memory cache");
1037
+ // convert the cache key value store to inMemoryCache
1169
1038
  const inMemoryCache = this.cacheToInMemoryCache(this.getCache());
1170
1039
  return inMemoryCache;
1171
1040
  }
@@ -1173,11 +1042,9 @@ class NodeStorage extends msalCommon.CacheManager {
1173
1042
  * sets the current in memory cache for the client
1174
1043
  * @param inMemoryCache - key value map in memory
1175
1044
  */
1176
-
1177
-
1178
1045
  setInMemoryCache(inMemoryCache) {
1179
- this.logger.trace("Setting in-memory cache"); // convert and append the inMemoryCache to cacheKVStore
1180
-
1046
+ this.logger.trace("Setting in-memory cache");
1047
+ // convert and append the inMemoryCache to cacheKVStore
1181
1048
  const cache = this.inMemoryCacheToCache(inMemoryCache);
1182
1049
  this.setCache(cache);
1183
1050
  this.emitChange();
@@ -1185,8 +1052,6 @@ class NodeStorage extends msalCommon.CacheManager {
1185
1052
  /**
1186
1053
  * get the current cache key-value store
1187
1054
  */
1188
-
1189
-
1190
1055
  getCache() {
1191
1056
  this.logger.trace("Getting cache key-value store");
1192
1057
  return this.cache;
@@ -1195,23 +1060,19 @@ class NodeStorage extends msalCommon.CacheManager {
1195
1060
  * sets the current cache (key value store)
1196
1061
  * @param cacheMap - key value map
1197
1062
  */
1198
-
1199
-
1200
1063
  setCache(cache) {
1201
1064
  this.logger.trace("Setting cache key value store");
1202
- this.cache = cache; // mark change in cache
1203
-
1065
+ this.cache = cache;
1066
+ // mark change in cache
1204
1067
  this.emitChange();
1205
1068
  }
1206
1069
  /**
1207
1070
  * Gets cache item with given key.
1208
1071
  * @param key - lookup key for the cache entry
1209
1072
  */
1210
-
1211
-
1212
1073
  getItem(key) {
1213
- this.logger.tracePii(`Item key: ${key}`); // read cache
1214
-
1074
+ this.logger.tracePii(`Item key: ${key}`);
1075
+ // read cache
1215
1076
  const cache = this.getCache();
1216
1077
  return cache[key];
1217
1078
  }
@@ -1220,37 +1081,29 @@ class NodeStorage extends msalCommon.CacheManager {
1220
1081
  * @param key - lookup key for the cache entry
1221
1082
  * @param value - value of the cache entry
1222
1083
  */
1223
-
1224
-
1225
1084
  setItem(key, value) {
1226
- this.logger.tracePii(`Item key: ${key}`); // read cache
1227
-
1085
+ this.logger.tracePii(`Item key: ${key}`);
1086
+ // read cache
1228
1087
  const cache = this.getCache();
1229
- cache[key] = value; // write to cache
1230
-
1088
+ cache[key] = value;
1089
+ // write to cache
1231
1090
  this.setCache(cache);
1232
1091
  }
1233
1092
  /**
1234
1093
  * fetch the account entity
1235
1094
  * @param accountKey - lookup key to fetch cache type AccountEntity
1236
1095
  */
1237
-
1238
-
1239
1096
  getAccount(accountKey) {
1240
1097
  const account = this.getItem(accountKey);
1241
-
1242
1098
  if (msalCommon.AccountEntity.isAccountEntity(account)) {
1243
1099
  return account;
1244
1100
  }
1245
-
1246
1101
  return null;
1247
1102
  }
1248
1103
  /**
1249
1104
  * set account entity
1250
1105
  * @param account - cache value to be set of type AccountEntity
1251
1106
  */
1252
-
1253
-
1254
1107
  setAccount(account) {
1255
1108
  const accountKey = account.generateAccountKey();
1256
1109
  this.setItem(accountKey, account);
@@ -1259,23 +1112,17 @@ class NodeStorage extends msalCommon.CacheManager {
1259
1112
  * fetch the idToken credential
1260
1113
  * @param idTokenKey - lookup key to fetch cache type IdTokenEntity
1261
1114
  */
1262
-
1263
-
1264
1115
  getIdTokenCredential(idTokenKey) {
1265
1116
  const idToken = this.getItem(idTokenKey);
1266
-
1267
1117
  if (msalCommon.IdTokenEntity.isIdTokenEntity(idToken)) {
1268
1118
  return idToken;
1269
1119
  }
1270
-
1271
1120
  return null;
1272
1121
  }
1273
1122
  /**
1274
1123
  * set idToken credential
1275
1124
  * @param idToken - cache value to be set of type IdTokenEntity
1276
1125
  */
1277
-
1278
-
1279
1126
  setIdTokenCredential(idToken) {
1280
1127
  const idTokenKey = idToken.generateCredentialKey();
1281
1128
  this.setItem(idTokenKey, idToken);
@@ -1284,23 +1131,17 @@ class NodeStorage extends msalCommon.CacheManager {
1284
1131
  * fetch the accessToken credential
1285
1132
  * @param accessTokenKey - lookup key to fetch cache type AccessTokenEntity
1286
1133
  */
1287
-
1288
-
1289
1134
  getAccessTokenCredential(accessTokenKey) {
1290
1135
  const accessToken = this.getItem(accessTokenKey);
1291
-
1292
1136
  if (msalCommon.AccessTokenEntity.isAccessTokenEntity(accessToken)) {
1293
1137
  return accessToken;
1294
1138
  }
1295
-
1296
1139
  return null;
1297
1140
  }
1298
1141
  /**
1299
1142
  * set accessToken credential
1300
1143
  * @param accessToken - cache value to be set of type AccessTokenEntity
1301
1144
  */
1302
-
1303
-
1304
1145
  setAccessTokenCredential(accessToken) {
1305
1146
  const accessTokenKey = accessToken.generateCredentialKey();
1306
1147
  this.setItem(accessTokenKey, accessToken);
@@ -1309,23 +1150,17 @@ class NodeStorage extends msalCommon.CacheManager {
1309
1150
  * fetch the refreshToken credential
1310
1151
  * @param refreshTokenKey - lookup key to fetch cache type RefreshTokenEntity
1311
1152
  */
1312
-
1313
-
1314
1153
  getRefreshTokenCredential(refreshTokenKey) {
1315
1154
  const refreshToken = this.getItem(refreshTokenKey);
1316
-
1317
1155
  if (msalCommon.RefreshTokenEntity.isRefreshTokenEntity(refreshToken)) {
1318
1156
  return refreshToken;
1319
1157
  }
1320
-
1321
1158
  return null;
1322
1159
  }
1323
1160
  /**
1324
1161
  * set refreshToken credential
1325
1162
  * @param refreshToken - cache value to be set of type RefreshTokenEntity
1326
1163
  */
1327
-
1328
-
1329
1164
  setRefreshTokenCredential(refreshToken) {
1330
1165
  const refreshTokenKey = refreshToken.generateCredentialKey();
1331
1166
  this.setItem(refreshTokenKey, refreshToken);
@@ -1334,23 +1169,17 @@ class NodeStorage extends msalCommon.CacheManager {
1334
1169
  * fetch appMetadata entity from the platform cache
1335
1170
  * @param appMetadataKey - lookup key to fetch cache type AppMetadataEntity
1336
1171
  */
1337
-
1338
-
1339
1172
  getAppMetadata(appMetadataKey) {
1340
1173
  const appMetadata = this.getItem(appMetadataKey);
1341
-
1342
1174
  if (msalCommon.AppMetadataEntity.isAppMetadataEntity(appMetadataKey, appMetadata)) {
1343
1175
  return appMetadata;
1344
1176
  }
1345
-
1346
1177
  return null;
1347
1178
  }
1348
1179
  /**
1349
1180
  * set appMetadata entity to the platform cache
1350
1181
  * @param appMetadata - cache value to be set of type AppMetadataEntity
1351
1182
  */
1352
-
1353
-
1354
1183
  setAppMetadata(appMetadata) {
1355
1184
  const appMetadataKey = appMetadata.generateAppMetadataKey();
1356
1185
  this.setItem(appMetadataKey, appMetadata);
@@ -1359,15 +1188,11 @@ class NodeStorage extends msalCommon.CacheManager {
1359
1188
  * fetch server telemetry entity from the platform cache
1360
1189
  * @param serverTelemetrykey - lookup key to fetch cache type ServerTelemetryEntity
1361
1190
  */
1362
-
1363
-
1364
1191
  getServerTelemetry(serverTelemetrykey) {
1365
1192
  const serverTelemetryEntity = this.getItem(serverTelemetrykey);
1366
-
1367
1193
  if (serverTelemetryEntity && msalCommon.ServerTelemetryEntity.isServerTelemetryEntity(serverTelemetrykey, serverTelemetryEntity)) {
1368
1194
  return serverTelemetryEntity;
1369
1195
  }
1370
-
1371
1196
  return null;
1372
1197
  }
1373
1198
  /**
@@ -1375,8 +1200,6 @@ class NodeStorage extends msalCommon.CacheManager {
1375
1200
  * @param serverTelemetryKey - lookup key to fetch cache type ServerTelemetryEntity
1376
1201
  * @param serverTelemetry - cache value to be set of type ServerTelemetryEntity
1377
1202
  */
1378
-
1379
-
1380
1203
  setServerTelemetry(serverTelemetryKey, serverTelemetry) {
1381
1204
  this.setItem(serverTelemetryKey, serverTelemetry);
1382
1205
  }
@@ -1384,22 +1207,16 @@ class NodeStorage extends msalCommon.CacheManager {
1384
1207
  * fetch authority metadata entity from the platform cache
1385
1208
  * @param key - lookup key to fetch cache type AuthorityMetadataEntity
1386
1209
  */
1387
-
1388
-
1389
1210
  getAuthorityMetadata(key) {
1390
1211
  const authorityMetadataEntity = this.getItem(key);
1391
-
1392
1212
  if (authorityMetadataEntity && msalCommon.AuthorityMetadataEntity.isAuthorityMetadataEntity(key, authorityMetadataEntity)) {
1393
1213
  return authorityMetadataEntity;
1394
1214
  }
1395
-
1396
1215
  return null;
1397
1216
  }
1398
1217
  /**
1399
1218
  * Get all authority metadata keys
1400
1219
  */
1401
-
1402
-
1403
1220
  getAuthorityMetadataKeys() {
1404
1221
  return this.getKeys().filter(key => {
1405
1222
  return this.isAuthorityMetadata(key);
@@ -1410,8 +1227,6 @@ class NodeStorage extends msalCommon.CacheManager {
1410
1227
  * @param key - lookup key to fetch cache type AuthorityMetadataEntity
1411
1228
  * @param metadata - cache value to be set of type AuthorityMetadataEntity
1412
1229
  */
1413
-
1414
-
1415
1230
  setAuthorityMetadata(key, metadata) {
1416
1231
  this.setItem(key, metadata);
1417
1232
  }
@@ -1419,15 +1234,11 @@ class NodeStorage extends msalCommon.CacheManager {
1419
1234
  * fetch throttling entity from the platform cache
1420
1235
  * @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
1421
1236
  */
1422
-
1423
-
1424
1237
  getThrottlingCache(throttlingCacheKey) {
1425
1238
  const throttlingCache = this.getItem(throttlingCacheKey);
1426
-
1427
1239
  if (throttlingCache && msalCommon.ThrottlingEntity.isThrottlingEntity(throttlingCacheKey, throttlingCache)) {
1428
1240
  return throttlingCache;
1429
1241
  }
1430
-
1431
1242
  return null;
1432
1243
  }
1433
1244
  /**
@@ -1435,8 +1246,6 @@ class NodeStorage extends msalCommon.CacheManager {
1435
1246
  * @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
1436
1247
  * @param throttlingCache - cache value to be set of type ThrottlingEntity
1437
1248
  */
1438
-
1439
-
1440
1249
  setThrottlingCache(throttlingCacheKey, throttlingCache) {
1441
1250
  this.setItem(throttlingCacheKey, throttlingCache);
1442
1251
  }
@@ -1445,57 +1254,46 @@ class NodeStorage extends msalCommon.CacheManager {
1445
1254
  * @param key - lookup key to remove a cache entity
1446
1255
  * @param inMemory - key value map of the cache
1447
1256
  */
1448
-
1449
-
1450
1257
  removeItem(key) {
1451
- this.logger.tracePii(`Item key: ${key}`); // read inMemoryCache
1452
-
1258
+ this.logger.tracePii(`Item key: ${key}`);
1259
+ // read inMemoryCache
1453
1260
  let result = false;
1454
1261
  const cache = this.getCache();
1455
-
1456
1262
  if (!!cache[key]) {
1457
1263
  delete cache[key];
1458
1264
  result = true;
1459
- } // write to the cache after removal
1460
-
1461
-
1265
+ }
1266
+ // write to the cache after removal
1462
1267
  if (result) {
1463
1268
  this.setCache(cache);
1464
1269
  this.emitChange();
1465
1270
  }
1466
-
1467
1271
  return result;
1468
1272
  }
1469
1273
  /**
1470
1274
  * Checks whether key is in cache.
1471
1275
  * @param key - look up key for a cache entity
1472
1276
  */
1473
-
1474
-
1475
1277
  containsKey(key) {
1476
1278
  return this.getKeys().includes(key);
1477
1279
  }
1478
1280
  /**
1479
1281
  * Gets all keys in window.
1480
1282
  */
1481
-
1482
-
1483
1283
  getKeys() {
1484
- this.logger.trace("Retrieving all cache keys"); // read cache
1485
-
1284
+ this.logger.trace("Retrieving all cache keys");
1285
+ // read cache
1486
1286
  const cache = this.getCache();
1487
1287
  return [...Object.keys(cache)];
1488
1288
  }
1489
1289
  /**
1490
1290
  * Clears all cache entries created by MSAL (except tokens).
1491
1291
  */
1492
-
1493
-
1494
1292
  async clear() {
1495
- this.logger.trace("Clearing cache entries created by MSAL"); // read inMemoryCache
1496
-
1497
- const cacheKeys = this.getKeys(); // delete each element
1498
-
1293
+ this.logger.trace("Clearing cache entries created by MSAL");
1294
+ // read inMemoryCache
1295
+ const cacheKeys = this.getKeys();
1296
+ // delete each element
1499
1297
  cacheKeys.forEach(key => {
1500
1298
  this.removeItem(key);
1501
1299
  });
@@ -1505,8 +1303,6 @@ class NodeStorage extends msalCommon.CacheManager {
1505
1303
  * Initialize in memory cache from an exisiting cache vault
1506
1304
  * @param cache - blob formatted cache (JSON)
1507
1305
  */
1508
-
1509
-
1510
1306
  static generateInMemoryCache(cache) {
1511
1307
  return Deserializer.deserializeAllCache(Deserializer.deserializeJSONBlob(cache));
1512
1308
  }
@@ -1514,22 +1310,16 @@ class NodeStorage extends msalCommon.CacheManager {
1514
1310
  * retrieves the final JSON
1515
1311
  * @param inMemoryCache - itemised cache read from the JSON
1516
1312
  */
1517
-
1518
-
1519
1313
  static generateJsonCache(inMemoryCache) {
1520
1314
  return Serializer.serializeAllCache(inMemoryCache);
1521
1315
  }
1522
1316
  /**
1523
1317
  * Updates a credential's cache key if the current cache key is outdated
1524
1318
  */
1525
-
1526
-
1527
1319
  updateCredentialCacheKey(currentCacheKey, credential) {
1528
1320
  const updatedCacheKey = credential.generateCredentialKey();
1529
-
1530
1321
  if (currentCacheKey !== updatedCacheKey) {
1531
1322
  const cacheItem = this.getItem(currentCacheKey);
1532
-
1533
1323
  if (cacheItem) {
1534
1324
  this.removeItem(currentCacheKey);
1535
1325
  this.setItem(updatedCacheKey, cacheItem);
@@ -1539,10 +1329,8 @@ class NodeStorage extends msalCommon.CacheManager {
1539
1329
  this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
1540
1330
  }
1541
1331
  }
1542
-
1543
1332
  return currentCacheKey;
1544
1333
  }
1545
-
1546
1334
  }
1547
1335
 
1548
1336
  /*
@@ -1560,43 +1348,35 @@ const defaultSerializedCache = {
1560
1348
  * In-memory token cache manager
1561
1349
  * @public
1562
1350
  */
1563
-
1564
1351
  class TokenCache {
1565
1352
  constructor(storage, logger, cachePlugin) {
1566
1353
  this.cacheHasChanged = false;
1567
1354
  this.storage = storage;
1568
1355
  this.storage.registerChangeEmitter(this.handleChangeEvent.bind(this));
1569
-
1570
1356
  if (cachePlugin) {
1571
1357
  this.persistence = cachePlugin;
1572
1358
  }
1573
-
1574
1359
  this.logger = logger;
1575
1360
  }
1576
1361
  /**
1577
1362
  * Set to true if cache state has changed since last time serialize or writeToPersistence was called
1578
1363
  */
1579
-
1580
-
1581
1364
  hasChanged() {
1582
1365
  return this.cacheHasChanged;
1583
1366
  }
1584
1367
  /**
1585
1368
  * Serializes in memory cache to JSON
1586
1369
  */
1587
-
1588
-
1589
1370
  serialize() {
1590
1371
  this.logger.trace("Serializing in-memory cache");
1591
- let finalState = Serializer.serializeAllCache(this.storage.getInMemoryCache()); // if cacheSnapshot not null or empty, merge
1592
-
1372
+ let finalState = Serializer.serializeAllCache(this.storage.getInMemoryCache());
1373
+ // if cacheSnapshot not null or empty, merge
1593
1374
  if (!msalCommon.StringUtils.isEmpty(this.cacheSnapshot)) {
1594
1375
  this.logger.trace("Reading cache snapshot from disk");
1595
1376
  finalState = this.mergeState(JSON.parse(this.cacheSnapshot), finalState);
1596
1377
  } else {
1597
1378
  this.logger.trace("No cache snapshot to merge");
1598
1379
  }
1599
-
1600
1380
  this.cacheHasChanged = false;
1601
1381
  return JSON.stringify(finalState);
1602
1382
  }
@@ -1604,12 +1384,9 @@ class TokenCache {
1604
1384
  * Deserializes JSON to in-memory cache. JSON should be in MSAL cache schema format
1605
1385
  * @param cache - blob formatted cache
1606
1386
  */
1607
-
1608
-
1609
1387
  deserialize(cache) {
1610
1388
  this.logger.trace("Deserializing JSON to in-memory cache");
1611
1389
  this.cacheSnapshot = cache;
1612
-
1613
1390
  if (!msalCommon.StringUtils.isEmpty(this.cacheSnapshot)) {
1614
1391
  this.logger.trace("Reading cache snapshot from disk");
1615
1392
  const deserializedCache = Deserializer.deserializeAllCache(this.overlayDefaults(JSON.parse(this.cacheSnapshot)));
@@ -1621,26 +1398,20 @@ class TokenCache {
1621
1398
  /**
1622
1399
  * Fetches the cache key-value map
1623
1400
  */
1624
-
1625
-
1626
1401
  getKVStore() {
1627
1402
  return this.storage.getCache();
1628
1403
  }
1629
1404
  /**
1630
1405
  * API that retrieves all accounts currently in cache to the user
1631
1406
  */
1632
-
1633
-
1634
1407
  async getAllAccounts() {
1635
1408
  this.logger.trace("getAllAccounts called");
1636
1409
  let cacheContext;
1637
-
1638
1410
  try {
1639
1411
  if (this.persistence) {
1640
1412
  cacheContext = new msalCommon.TokenCacheContext(this, false);
1641
1413
  await this.persistence.beforeCacheAccess(cacheContext);
1642
1414
  }
1643
-
1644
1415
  return this.storage.getAllAccounts();
1645
1416
  } finally {
1646
1417
  if (this.persistence && cacheContext) {
@@ -1654,11 +1425,8 @@ class TokenCache {
1654
1425
  * or null when no matching account is found
1655
1426
  * @param homeAccountId - unique identifier for an account (uid.utid)
1656
1427
  */
1657
-
1658
-
1659
1428
  async getAccountByHomeId(homeAccountId) {
1660
1429
  const allAccounts = await this.getAllAccounts();
1661
-
1662
1430
  if (!msalCommon.StringUtils.isEmpty(homeAccountId) && allAccounts && allAccounts.length) {
1663
1431
  return allAccounts.filter(accountObj => accountObj.homeAccountId === homeAccountId)[0] || null;
1664
1432
  } else {
@@ -1671,11 +1439,8 @@ class TokenCache {
1671
1439
  * or null when no matching account is found
1672
1440
  * @param localAccountId - unique identifier of an account (sub/obj when homeAccountId cannot be populated)
1673
1441
  */
1674
-
1675
-
1676
1442
  async getAccountByLocalId(localAccountId) {
1677
1443
  const allAccounts = await this.getAllAccounts();
1678
-
1679
1444
  if (!msalCommon.StringUtils.isEmpty(localAccountId) && allAccounts && allAccounts.length) {
1680
1445
  return allAccounts.filter(accountObj => accountObj.localAccountId === localAccountId)[0] || null;
1681
1446
  } else {
@@ -1686,18 +1451,14 @@ class TokenCache {
1686
1451
  * API to remove a specific account and the relevant data from cache
1687
1452
  * @param account - AccountInfo passed by the user
1688
1453
  */
1689
-
1690
-
1691
1454
  async removeAccount(account) {
1692
1455
  this.logger.trace("removeAccount called");
1693
1456
  let cacheContext;
1694
-
1695
1457
  try {
1696
1458
  if (this.persistence) {
1697
1459
  cacheContext = new msalCommon.TokenCacheContext(this, true);
1698
1460
  await this.persistence.beforeCacheAccess(cacheContext);
1699
1461
  }
1700
-
1701
1462
  await this.storage.removeAccount(msalCommon.AccountEntity.generateAccountCacheKey(account));
1702
1463
  } finally {
1703
1464
  if (this.persistence && cacheContext) {
@@ -1708,8 +1469,6 @@ class TokenCache {
1708
1469
  /**
1709
1470
  * Called when the cache has changed state.
1710
1471
  */
1711
-
1712
-
1713
1472
  handleChangeEvent() {
1714
1473
  this.cacheHasChanged = true;
1715
1474
  }
@@ -1718,8 +1477,6 @@ class TokenCache {
1718
1477
  * @param oldState - cache before changes
1719
1478
  * @param currentState - current cache state in the library
1720
1479
  */
1721
-
1722
-
1723
1480
  mergeState(oldState, currentState) {
1724
1481
  this.logger.trace("Merging in-memory cache with cache snapshot");
1725
1482
  const stateAfterRemoval = this.mergeRemovals(oldState, currentState);
@@ -1730,12 +1487,10 @@ class TokenCache {
1730
1487
  * @param oldState - cache before changes
1731
1488
  * @param newState - updated cache
1732
1489
  */
1733
-
1734
-
1735
1490
  mergeUpdates(oldState, newState) {
1736
1491
  Object.keys(newState).forEach(newKey => {
1737
- const newValue = newState[newKey]; // if oldState does not contain value but newValue does, add it
1738
-
1492
+ const newValue = newState[newKey];
1493
+ // if oldState does not contain value but newValue does, add it
1739
1494
  if (!oldState.hasOwnProperty(newKey)) {
1740
1495
  if (newValue !== null) {
1741
1496
  oldState[newKey] = newValue;
@@ -1746,7 +1501,6 @@ class TokenCache {
1746
1501
  const newValueIsObject = typeof newValue === "object";
1747
1502
  const newValueIsNotArray = !Array.isArray(newValue);
1748
1503
  const oldStateNotUndefinedOrNull = typeof oldState[newKey] !== "undefined" && oldState[newKey] !== null;
1749
-
1750
1504
  if (newValueNotNull && newValueIsObject && newValueIsNotArray && oldStateNotUndefinedOrNull) {
1751
1505
  this.mergeUpdates(oldState[newKey], newValue);
1752
1506
  } else {
@@ -1762,8 +1516,6 @@ class TokenCache {
1762
1516
  * @param oldState - cache before changes
1763
1517
  * @param newState - updated cache
1764
1518
  */
1765
-
1766
-
1767
1519
  mergeRemovals(oldState, newState) {
1768
1520
  this.logger.trace("Remove updated entries in cache");
1769
1521
  const accounts = oldState.Account ? this.mergeRemovalsDict(oldState.Account, newState.Account) : oldState.Account;
@@ -1771,7 +1523,8 @@ class TokenCache {
1771
1523
  const refreshTokens = oldState.RefreshToken ? this.mergeRemovalsDict(oldState.RefreshToken, newState.RefreshToken) : oldState.RefreshToken;
1772
1524
  const idTokens = oldState.IdToken ? this.mergeRemovalsDict(oldState.IdToken, newState.IdToken) : oldState.IdToken;
1773
1525
  const appMetadata = oldState.AppMetadata ? this.mergeRemovalsDict(oldState.AppMetadata, newState.AppMetadata) : oldState.AppMetadata;
1774
- return { ...oldState,
1526
+ return {
1527
+ ...oldState,
1775
1528
  Account: accounts,
1776
1529
  AccessToken: accessTokens,
1777
1530
  RefreshToken: refreshTokens,
@@ -1784,10 +1537,9 @@ class TokenCache {
1784
1537
  * @param oldState - cache before changes
1785
1538
  * @param newState - updated cache
1786
1539
  */
1787
-
1788
-
1789
1540
  mergeRemovalsDict(oldState, newState) {
1790
- const finalState = { ...oldState
1541
+ const finalState = {
1542
+ ...oldState
1791
1543
  };
1792
1544
  Object.keys(oldState).forEach(oldKey => {
1793
1545
  if (!newState || !newState.hasOwnProperty(oldKey)) {
@@ -1800,34 +1552,36 @@ class TokenCache {
1800
1552
  * Helper to overlay as a part of cache merge
1801
1553
  * @param passedInCache - cache read from the blob
1802
1554
  */
1803
-
1804
-
1805
1555
  overlayDefaults(passedInCache) {
1806
1556
  this.logger.trace("Overlaying input cache with the default cache");
1807
1557
  return {
1808
- Account: { ...defaultSerializedCache.Account,
1558
+ Account: {
1559
+ ...defaultSerializedCache.Account,
1809
1560
  ...passedInCache.Account
1810
1561
  },
1811
- IdToken: { ...defaultSerializedCache.IdToken,
1562
+ IdToken: {
1563
+ ...defaultSerializedCache.IdToken,
1812
1564
  ...passedInCache.IdToken
1813
1565
  },
1814
- AccessToken: { ...defaultSerializedCache.AccessToken,
1566
+ AccessToken: {
1567
+ ...defaultSerializedCache.AccessToken,
1815
1568
  ...passedInCache.AccessToken
1816
1569
  },
1817
- RefreshToken: { ...defaultSerializedCache.RefreshToken,
1570
+ RefreshToken: {
1571
+ ...defaultSerializedCache.RefreshToken,
1818
1572
  ...passedInCache.RefreshToken
1819
1573
  },
1820
- AppMetadata: { ...defaultSerializedCache.AppMetadata,
1574
+ AppMetadata: {
1575
+ ...defaultSerializedCache.AppMetadata,
1821
1576
  ...passedInCache.AppMetadata
1822
1577
  }
1823
1578
  };
1824
1579
  }
1825
-
1826
1580
  }
1827
1581
 
1828
1582
  /* eslint-disable header/header */
1829
1583
  const name = "@azure/msal-node";
1830
- const version = "1.14.5";
1584
+ const version = "1.14.6";
1831
1585
 
1832
1586
  /*
1833
1587
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1836,7 +1590,6 @@ const version = "1.14.5";
1836
1590
  /**
1837
1591
  * NodeAuthErrorMessage class containing string constants used by error codes and messages.
1838
1592
  */
1839
-
1840
1593
  const NodeAuthErrorMessage = {
1841
1594
  invalidLoopbackAddressType: {
1842
1595
  code: "invalid_loopback_server_address_type",
@@ -1875,60 +1628,45 @@ class NodeAuthError extends msalCommon.AuthError {
1875
1628
  /**
1876
1629
  * Creates an error thrown if loopback server address is of type string.
1877
1630
  */
1878
-
1879
-
1880
1631
  static createInvalidLoopbackAddressTypeError() {
1881
1632
  return new NodeAuthError(NodeAuthErrorMessage.invalidLoopbackAddressType.code, `${NodeAuthErrorMessage.invalidLoopbackAddressType.desc}`);
1882
1633
  }
1883
1634
  /**
1884
1635
  * Creates an error thrown if the loopback server is unable to get a url.
1885
1636
  */
1886
-
1887
-
1888
1637
  static createUnableToLoadRedirectUrlError() {
1889
1638
  return new NodeAuthError(NodeAuthErrorMessage.unableToLoadRedirectUri.code, `${NodeAuthErrorMessage.unableToLoadRedirectUri.desc}`);
1890
1639
  }
1891
1640
  /**
1892
1641
  * Creates an error thrown if the server response does not contain an auth code.
1893
1642
  */
1894
-
1895
-
1896
1643
  static createNoAuthCodeInResponseError() {
1897
1644
  return new NodeAuthError(NodeAuthErrorMessage.noAuthCodeInResponse.code, `${NodeAuthErrorMessage.noAuthCodeInResponse.desc}`);
1898
1645
  }
1899
1646
  /**
1900
1647
  * Creates an error thrown if the loopback server has not been spun up yet.
1901
1648
  */
1902
-
1903
-
1904
1649
  static createNoLoopbackServerExistsError() {
1905
1650
  return new NodeAuthError(NodeAuthErrorMessage.noLoopbackServerExists.code, `${NodeAuthErrorMessage.noLoopbackServerExists.desc}`);
1906
1651
  }
1907
1652
  /**
1908
1653
  * Creates an error thrown if a loopback server already exists when attempting to create another one.
1909
1654
  */
1910
-
1911
-
1912
1655
  static createLoopbackServerAlreadyExistsError() {
1913
1656
  return new NodeAuthError(NodeAuthErrorMessage.loopbackServerAlreadyExists.code, `${NodeAuthErrorMessage.loopbackServerAlreadyExists.desc}`);
1914
1657
  }
1915
1658
  /**
1916
1659
  * Creates an error thrown if the loopback server times out registering the auth code listener.
1917
1660
  */
1918
-
1919
-
1920
1661
  static createLoopbackServerTimeoutError() {
1921
1662
  return new NodeAuthError(NodeAuthErrorMessage.loopbackServerTimeout.code, `${NodeAuthErrorMessage.loopbackServerTimeout.desc}`);
1922
1663
  }
1923
1664
  /**
1924
1665
  * Creates an error thrown when the state is not present.
1925
1666
  */
1926
-
1927
-
1928
1667
  static createStateNotFoundError() {
1929
1668
  return new NodeAuthError(NodeAuthErrorMessage.stateNotFoundError.code, NodeAuthErrorMessage.stateNotFoundError.desc);
1930
1669
  }
1931
-
1932
1670
  }
1933
1671
 
1934
1672
  /*
@@ -1939,7 +1677,6 @@ class NodeAuthError extends msalCommon.AuthError {
1939
1677
  * Base abstract class for all ClientApplications - public and confidential
1940
1678
  * @public
1941
1679
  */
1942
-
1943
1680
  class ClientApplication {
1944
1681
  /**
1945
1682
  * Constructor for the ClientApplication
@@ -1960,11 +1697,10 @@ class ClientApplication {
1960
1697
  * sent in the request and should contain an authorization code, which can then be used to acquire tokens via
1961
1698
  * `acquireTokenByCode(AuthorizationCodeRequest)`.
1962
1699
  */
1963
-
1964
-
1965
1700
  async getAuthCodeUrl(request) {
1966
1701
  this.logger.info("getAuthCodeUrl called", request.correlationId);
1967
- const validRequest = { ...request,
1702
+ const validRequest = {
1703
+ ...request,
1968
1704
  ...(await this.initializeBaseRequest(request)),
1969
1705
  responseMode: request.responseMode || msalCommon.ResponseMode.QUERY,
1970
1706
  authenticationScheme: msalCommon.AuthenticationScheme.BEARER
@@ -1982,26 +1718,23 @@ class ClientApplication {
1982
1718
  * Authorization Code flow. Ensure that values for redirectUri and scopes in AuthorizationCodeUrlRequest and
1983
1719
  * AuthorizationCodeRequest are the same.
1984
1720
  */
1985
-
1986
-
1987
1721
  async acquireTokenByCode(request, authCodePayLoad) {
1988
1722
  this.logger.info("acquireTokenByCode called");
1989
-
1990
1723
  if (request.state && authCodePayLoad) {
1991
1724
  this.logger.info("acquireTokenByCode - validating state");
1992
- this.validateState(request.state, authCodePayLoad.state || ""); // eslint-disable-next-line no-param-reassign
1993
-
1994
- authCodePayLoad = { ...authCodePayLoad,
1725
+ this.validateState(request.state, authCodePayLoad.state || "");
1726
+ // eslint-disable-next-line no-param-reassign
1727
+ authCodePayLoad = {
1728
+ ...authCodePayLoad,
1995
1729
  state: ""
1996
1730
  };
1997
1731
  }
1998
-
1999
- const validRequest = { ...request,
1732
+ const validRequest = {
1733
+ ...request,
2000
1734
  ...(await this.initializeBaseRequest(request)),
2001
1735
  authenticationScheme: msalCommon.AuthenticationScheme.BEARER
2002
1736
  };
2003
1737
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
2004
-
2005
1738
  try {
2006
1739
  const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
2007
1740
  const authorizationCodeClient = new msalCommon.AuthorizationCodeClient(authClientConfig);
@@ -2011,7 +1744,6 @@ class ClientApplication {
2011
1744
  if (e instanceof msalCommon.AuthError) {
2012
1745
  e.setCorrelationId(validRequest.correlationId);
2013
1746
  }
2014
-
2015
1747
  serverTelemetryManager.cacheFailedRequest(e);
2016
1748
  throw e;
2017
1749
  }
@@ -2023,16 +1755,14 @@ class ClientApplication {
2023
1755
  * recommended that you use `acquireTokenSilent()` for silent scenarios. When using `acquireTokenSilent()`, MSAL will
2024
1756
  * handle the caching and refreshing of tokens automatically.
2025
1757
  */
2026
-
2027
-
2028
1758
  async acquireTokenByRefreshToken(request) {
2029
1759
  this.logger.info("acquireTokenByRefreshToken called", request.correlationId);
2030
- const validRequest = { ...request,
1760
+ const validRequest = {
1761
+ ...request,
2031
1762
  ...(await this.initializeBaseRequest(request)),
2032
1763
  authenticationScheme: msalCommon.AuthenticationScheme.BEARER
2033
1764
  };
2034
1765
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
2035
-
2036
1766
  try {
2037
1767
  const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
2038
1768
  const refreshTokenClient = new msalCommon.RefreshTokenClient(refreshTokenClientConfig);
@@ -2042,7 +1772,6 @@ class ClientApplication {
2042
1772
  if (e instanceof msalCommon.AuthError) {
2043
1773
  e.setCorrelationId(validRequest.correlationId);
2044
1774
  }
2045
-
2046
1775
  serverTelemetryManager.cacheFailedRequest(e);
2047
1776
  throw e;
2048
1777
  }
@@ -2055,15 +1784,13 @@ class ClientApplication {
2055
1784
  * In case the refresh_token is expired or not found, an error is thrown
2056
1785
  * and the guidance is for the user to call any interactive token acquisition API (eg: `acquireTokenByCode()`).
2057
1786
  */
2058
-
2059
-
2060
1787
  async acquireTokenSilent(request) {
2061
- const validRequest = { ...request,
1788
+ const validRequest = {
1789
+ ...request,
2062
1790
  ...(await this.initializeBaseRequest(request)),
2063
1791
  forceRefresh: request.forceRefresh || false
2064
1792
  };
2065
1793
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
2066
-
2067
1794
  try {
2068
1795
  const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
2069
1796
  const silentFlowClient = new msalCommon.SilentFlowClient(silentFlowClientConfig);
@@ -2073,7 +1800,6 @@ class ClientApplication {
2073
1800
  if (e instanceof msalCommon.AuthError) {
2074
1801
  e.setCorrelationId(validRequest.correlationId);
2075
1802
  }
2076
-
2077
1803
  serverTelemetryManager.cacheFailedRequest(e);
2078
1804
  throw e;
2079
1805
  }
@@ -2088,15 +1814,13 @@ class ClientApplication {
2088
1814
  *
2089
1815
  * @param request - UsenamePasswordRequest
2090
1816
  */
2091
-
2092
-
2093
1817
  async acquireTokenByUsernamePassword(request) {
2094
1818
  this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
2095
- const validRequest = { ...request,
1819
+ const validRequest = {
1820
+ ...request,
2096
1821
  ...(await this.initializeBaseRequest(request))
2097
1822
  };
2098
1823
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
2099
-
2100
1824
  try {
2101
1825
  const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
2102
1826
  const usernamePasswordClient = new msalCommon.UsernamePasswordClient(usernamePasswordClientConfig);
@@ -2106,7 +1830,6 @@ class ClientApplication {
2106
1830
  if (e instanceof msalCommon.AuthError) {
2107
1831
  e.setCorrelationId(validRequest.correlationId);
2108
1832
  }
2109
-
2110
1833
  serverTelemetryManager.cacheFailedRequest(e);
2111
1834
  throw e;
2112
1835
  }
@@ -2114,8 +1837,6 @@ class ClientApplication {
2114
1837
  /**
2115
1838
  * Gets the token cache for the application.
2116
1839
  */
2117
-
2118
-
2119
1840
  getTokenCache() {
2120
1841
  this.logger.info("getTokenCache called");
2121
1842
  return this.tokenCache;
@@ -2129,13 +1850,10 @@ class ClientApplication {
2129
1850
  * @param state
2130
1851
  * @param cachedState
2131
1852
  */
2132
-
2133
-
2134
1853
  validateState(state, cachedState) {
2135
1854
  if (!state) {
2136
1855
  throw NodeAuthError.createStateNotFoundError();
2137
1856
  }
2138
-
2139
1857
  if (state !== cachedState) {
2140
1858
  throw msalCommon.ClientAuthError.createStateMismatchError();
2141
1859
  }
@@ -2143,8 +1861,6 @@ class ClientApplication {
2143
1861
  /**
2144
1862
  * Returns the logger instance
2145
1863
  */
2146
-
2147
-
2148
1864
  getLogger() {
2149
1865
  return this.logger;
2150
1866
  }
@@ -2152,8 +1868,6 @@ class ClientApplication {
2152
1868
  * Replaces the default logger set in configurations with new Logger with new configurations
2153
1869
  * @param logger - Logger instance
2154
1870
  */
2155
-
2156
-
2157
1871
  setLogger(logger) {
2158
1872
  this.logger = logger;
2159
1873
  }
@@ -2162,13 +1876,11 @@ class ClientApplication {
2162
1876
  * @param authority - user passed authority in configuration
2163
1877
  * @param serverTelemetryManager - initializes servertelemetry if passed
2164
1878
  */
2165
-
2166
-
2167
1879
  async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration, azureCloudOptions) {
2168
- this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); // precedence - azureCloudInstance + tenant >> authority and request >> config
2169
-
2170
- const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions; // using null assertion operator as we ensure that all config values have default values in buildConfiguration()
2171
-
1880
+ this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId);
1881
+ // precedence - azureCloudInstance + tenant >> authority and request >> config
1882
+ const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions;
1883
+ // using null assertion operator as we ensure that all config values have default values in buildConfiguration()
2172
1884
  this.logger.verbose(`building oauth client configuration with the authority: ${authority}`, requestCorrelationId);
2173
1885
  const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId, userAzureCloudOptions);
2174
1886
  serverTelemetryManager == null ? void 0 : serverTelemetryManager.updateRegionDiscoveryMetadata(discoveredAuthority.regionDiscoveryMetadata);
@@ -2207,7 +1919,6 @@ class ClientApplication {
2207
1919
  };
2208
1920
  return clientConfiguration;
2209
1921
  }
2210
-
2211
1922
  getClientAssertion(authority) {
2212
1923
  return {
2213
1924
  assertion: this.clientAssertion.getJwt(this.cryptoProvider, this.config.auth.clientId, authority.tokenEndpoint),
@@ -2218,22 +1929,19 @@ class ClientApplication {
2218
1929
  * Generates a request with the default scopes & generates a correlationId.
2219
1930
  * @param authRequest - BaseAuthRequest for initialization
2220
1931
  */
2221
-
2222
-
2223
1932
  async initializeBaseRequest(authRequest) {
2224
- this.logger.verbose("initializeRequestScopes called", authRequest.correlationId); // Default authenticationScheme to Bearer, log that POP isn't supported yet
2225
-
1933
+ this.logger.verbose("initializeRequestScopes called", authRequest.correlationId);
1934
+ // Default authenticationScheme to Bearer, log that POP isn't supported yet
2226
1935
  if (authRequest.authenticationScheme && authRequest.authenticationScheme === msalCommon.AuthenticationScheme.POP) {
2227
1936
  this.logger.verbose("Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request", authRequest.correlationId);
2228
1937
  }
2229
-
2230
- authRequest.authenticationScheme = msalCommon.AuthenticationScheme.BEARER; // Set requested claims hash if claims were requested
2231
-
1938
+ authRequest.authenticationScheme = msalCommon.AuthenticationScheme.BEARER;
1939
+ // Set requested claims hash if claims were requested
2232
1940
  if (authRequest.claims && !msalCommon.StringUtils.isEmpty(authRequest.claims)) {
2233
1941
  authRequest.requestedClaimsHash = await this.cryptoProvider.hashString(authRequest.claims);
2234
1942
  }
2235
-
2236
- return { ...authRequest,
1943
+ return {
1944
+ ...authRequest,
2237
1945
  scopes: [...(authRequest && authRequest.scopes || []), ...msalCommon.OIDC_DEFAULT_SCOPES],
2238
1946
  correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
2239
1947
  authority: authRequest.authority || this.config.auth.authority
@@ -2245,8 +1953,6 @@ class ClientApplication {
2245
1953
  * @param correlationId - GUID
2246
1954
  * @param forceRefresh - boolean to indicate network call
2247
1955
  */
2248
-
2249
-
2250
1956
  initializeServerTelemetryManager(apiId, correlationId, forceRefresh) {
2251
1957
  const telemetryPayload = {
2252
1958
  clientId: this.config.auth.clientId,
@@ -2261,11 +1967,9 @@ class ClientApplication {
2261
1967
  * object. If no authority set in application object, then default to common authority.
2262
1968
  * @param authorityString - authority from user configuration
2263
1969
  */
2264
-
2265
-
2266
1970
  async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId, azureCloudOptions) {
2267
- this.logger.verbose("createAuthority called", requestCorrelationId); // build authority string based on auth params - azureCloudInstance is prioritized if provided
2268
-
1971
+ this.logger.verbose("createAuthority called", requestCorrelationId);
1972
+ // build authority string based on auth params - azureCloudInstance is prioritized if provided
2269
1973
  const authorityUrl = msalCommon.Authority.generateAuthority(authorityString, azureCloudOptions);
2270
1974
  const authorityOptions = {
2271
1975
  protocolMode: this.config.auth.protocolMode,
@@ -2280,12 +1984,9 @@ class ClientApplication {
2280
1984
  /**
2281
1985
  * Clear the cache
2282
1986
  */
2283
-
2284
-
2285
1987
  clearCache() {
2286
1988
  this.storage.clear();
2287
1989
  }
2288
-
2289
1990
  }
2290
1991
 
2291
1992
  /*
@@ -2303,11 +2004,9 @@ class LoopbackClient {
2303
2004
  if (!!this.server) {
2304
2005
  throw NodeAuthError.createLoopbackServerAlreadyExistsError();
2305
2006
  }
2306
-
2307
2007
  const authCodeListener = new Promise((resolve, reject) => {
2308
2008
  this.server = http.createServer(async (req, res) => {
2309
2009
  const url = req.url;
2310
-
2311
2010
  if (!url) {
2312
2011
  res.end(errorTemplate || "Error occurred loading redirectUrl");
2313
2012
  reject(NodeAuthError.createUnableToLoadRedirectUrlError());
@@ -2316,35 +2015,29 @@ class LoopbackClient {
2316
2015
  res.end(successTemplate || "Auth code was successfully acquired. You can close this window now.");
2317
2016
  return;
2318
2017
  }
2319
-
2320
2018
  const authCodeResponse = msalCommon.UrlString.getDeserializedQueryString(url);
2321
-
2322
2019
  if (authCodeResponse.code) {
2323
2020
  const redirectUri = await this.getRedirectUri();
2324
2021
  res.writeHead(HttpStatus.REDIRECT, {
2325
2022
  location: redirectUri
2326
2023
  }); // Prevent auth code from being saved in the browser history
2327
-
2328
2024
  res.end();
2329
2025
  }
2330
-
2331
2026
  resolve(authCodeResponse);
2332
2027
  });
2333
2028
  this.server.listen(0); // Listen on any available port
2334
- }); // Wait for server to be listening
2335
-
2029
+ });
2030
+ // Wait for server to be listening
2336
2031
  await new Promise(resolve => {
2337
2032
  let ticks = 0;
2338
2033
  const id = setInterval(() => {
2339
2034
  if (LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS / LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS < ticks) {
2340
2035
  throw NodeAuthError.createLoopbackServerTimeoutError();
2341
2036
  }
2342
-
2343
2037
  if (this.server.listening) {
2344
2038
  clearInterval(id);
2345
2039
  resolve();
2346
2040
  }
2347
-
2348
2041
  ticks++;
2349
2042
  }, LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
2350
2043
  });
@@ -2354,34 +2047,26 @@ class LoopbackClient {
2354
2047
  * Get the port that the loopback server is running on
2355
2048
  * @returns
2356
2049
  */
2357
-
2358
-
2359
2050
  getRedirectUri() {
2360
2051
  if (!this.server) {
2361
2052
  throw NodeAuthError.createNoLoopbackServerExistsError();
2362
2053
  }
2363
-
2364
2054
  const address = this.server.address();
2365
-
2366
2055
  if (!address || typeof address === "string" || !address.port) {
2367
2056
  this.closeServer();
2368
2057
  throw NodeAuthError.createInvalidLoopbackAddressTypeError();
2369
2058
  }
2370
-
2371
2059
  const port = address && address.port;
2372
2060
  return `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}:${port}`;
2373
2061
  }
2374
2062
  /**
2375
2063
  * Close the loopback server
2376
2064
  */
2377
-
2378
-
2379
2065
  closeServer() {
2380
2066
  if (!!this.server) {
2381
2067
  this.server.close();
2382
2068
  }
2383
2069
  }
2384
-
2385
2070
  }
2386
2071
 
2387
2072
  /*
@@ -2393,7 +2078,6 @@ class LoopbackClient {
2393
2078
  * are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
2394
2079
  * @public
2395
2080
  */
2396
-
2397
2081
  class PublicClientApplication extends ClientApplication {
2398
2082
  /**
2399
2083
  * Important attributes in the Configuration object for auth are:
@@ -2424,13 +2108,10 @@ class PublicClientApplication extends ClientApplication {
2424
2108
  * Since the client cannot receive incoming requests, it polls the authorization server repeatedly
2425
2109
  * until the end-user completes input of credentials.
2426
2110
  */
2427
-
2428
-
2429
2111
  async acquireTokenByDeviceCode(request) {
2430
2112
  this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
2431
2113
  const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
2432
2114
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
2433
-
2434
2115
  try {
2435
2116
  const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
2436
2117
  const deviceCodeClient = new msalCommon.DeviceCodeClient(deviceCodeConfig);
@@ -2440,7 +2121,6 @@ class PublicClientApplication extends ClientApplication {
2440
2121
  if (e instanceof msalCommon.AuthError) {
2441
2122
  e.setCorrelationId(validRequest.correlationId);
2442
2123
  }
2443
-
2444
2124
  serverTelemetryManager.cacheFailedRequest(e);
2445
2125
  throw e;
2446
2126
  }
@@ -2448,8 +2128,6 @@ class PublicClientApplication extends ClientApplication {
2448
2128
  /**
2449
2129
  * Acquires a token by requesting an Authorization code then exchanging it for a token.
2450
2130
  */
2451
-
2452
-
2453
2131
  async acquireTokenInteractive(request) {
2454
2132
  const {
2455
2133
  verifier,
@@ -2464,7 +2142,8 @@ class PublicClientApplication extends ClientApplication {
2464
2142
  const loopbackClient = new LoopbackClient();
2465
2143
  const authCodeListener = loopbackClient.listenForAuthCode(successTemplate, errorTemplate);
2466
2144
  const redirectUri = loopbackClient.getRedirectUri();
2467
- const validRequest = { ...remainingProperties,
2145
+ const validRequest = {
2146
+ ...remainingProperties,
2468
2147
  scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
2469
2148
  redirectUri: redirectUri,
2470
2149
  responseMode: msalCommon.ResponseMode.QUERY,
@@ -2476,13 +2155,11 @@ class PublicClientApplication extends ClientApplication {
2476
2155
  const authCodeResponse = await authCodeListener.finally(() => {
2477
2156
  loopbackClient.closeServer();
2478
2157
  });
2479
-
2480
2158
  if (authCodeResponse.error) {
2481
2159
  throw new msalCommon.ServerError(authCodeResponse.error, authCodeResponse.error_description, authCodeResponse.suberror);
2482
2160
  } else if (!authCodeResponse.code) {
2483
2161
  throw NodeAuthError.createNoAuthCodeInResponseError();
2484
2162
  }
2485
-
2486
2163
  const clientInfo = authCodeResponse.client_info;
2487
2164
  const tokenRequest = {
2488
2165
  code: authCodeResponse.code,
@@ -2492,7 +2169,6 @@ class PublicClientApplication extends ClientApplication {
2492
2169
  };
2493
2170
  return this.acquireTokenByCode(tokenRequest);
2494
2171
  }
2495
-
2496
2172
  }
2497
2173
 
2498
2174
  /*
@@ -2503,7 +2179,6 @@ class PublicClientApplication extends ClientApplication {
2503
2179
  * Client assertion of type jwt-bearer used in confidential client flows
2504
2180
  * @public
2505
2181
  */
2506
-
2507
2182
  class ClientAssertion {
2508
2183
  /**
2509
2184
  * Initialize the ClientAssertion class from the clientAssertion passed by the user
@@ -2520,17 +2195,13 @@ class ClientAssertion {
2520
2195
  * @param privateKey - secret key
2521
2196
  * @param publicCertificate - electronic document provided to prove the ownership of the public key
2522
2197
  */
2523
-
2524
-
2525
2198
  static fromCertificate(thumbprint, privateKey, publicCertificate) {
2526
2199
  const clientAssertion = new ClientAssertion();
2527
2200
  clientAssertion.privateKey = privateKey;
2528
2201
  clientAssertion.thumbprint = thumbprint;
2529
-
2530
2202
  if (publicCertificate) {
2531
2203
  clientAssertion.publicCertificate = this.parseCertificate(publicCertificate);
2532
2204
  }
2533
-
2534
2205
  return clientAssertion;
2535
2206
  }
2536
2207
  /**
@@ -2539,34 +2210,26 @@ class ClientAssertion {
2539
2210
  * @param issuer - iss claim
2540
2211
  * @param jwtAudience - aud claim
2541
2212
  */
2542
-
2543
-
2544
2213
  getJwt(cryptoProvider, issuer, jwtAudience) {
2545
2214
  // if assertion was created from certificate, check if jwt is expired and create new one.
2546
2215
  if (this.privateKey && this.thumbprint) {
2547
2216
  if (this.jwt && !this.isExpired() && issuer === this.issuer && jwtAudience === this.jwtAudience) {
2548
2217
  return this.jwt;
2549
2218
  }
2550
-
2551
2219
  return this.createJwt(cryptoProvider, issuer, jwtAudience);
2552
2220
  }
2553
2221
  /*
2554
2222
  * if assertion was created by caller, then we just append it. It is up to the caller to
2555
2223
  * ensure that it contains necessary claims and that it is not expired.
2556
2224
  */
2557
-
2558
-
2559
2225
  if (this.jwt) {
2560
2226
  return this.jwt;
2561
2227
  }
2562
-
2563
2228
  throw msalCommon.ClientAuthError.createInvalidAssertionError();
2564
2229
  }
2565
2230
  /**
2566
2231
  * JWT format and required claims specified: https://tools.ietf.org/html/rfc7523#section-3
2567
2232
  */
2568
-
2569
-
2570
2233
  createJwt(cryptoProvider, issuer, jwtAudience) {
2571
2234
  this.issuer = issuer;
2572
2235
  this.jwtAudience = jwtAudience;
@@ -2576,13 +2239,11 @@ class ClientAssertion {
2576
2239
  alg: JwtConstants.RSA_256,
2577
2240
  x5t: EncodingUtils.base64EncodeUrl(this.thumbprint, "hex")
2578
2241
  };
2579
-
2580
2242
  if (this.publicCertificate) {
2581
2243
  Object.assign(header, {
2582
2244
  x5c: this.publicCertificate
2583
2245
  });
2584
2246
  }
2585
-
2586
2247
  const payload = {
2587
2248
  [JwtConstants.AUDIENCE]: this.jwtAudience,
2588
2249
  [JwtConstants.EXPIRATION_TIME]: this.expirationTime,
@@ -2599,8 +2260,6 @@ class ClientAssertion {
2599
2260
  /**
2600
2261
  * Utility API to check expiration
2601
2262
  */
2602
-
2603
-
2604
2263
  isExpired() {
2605
2264
  return this.expirationTime < msalCommon.TimeUtils.nowSeconds();
2606
2265
  }
@@ -2608,8 +2267,6 @@ class ClientAssertion {
2608
2267
  * Extracts the raw certs from a given certificate string and returns them in an array.
2609
2268
  * @param publicCertificate - electronic document provided to prove the ownership of the public key
2610
2269
  */
2611
-
2612
-
2613
2270
  static parseCertificate(publicCertificate) {
2614
2271
  /**
2615
2272
  * This is regex to identify the certs in a given certificate string.
@@ -2621,15 +2278,12 @@ class ClientAssertion {
2621
2278
  const regexToFindCerts = /-----BEGIN CERTIFICATE-----\r*\n(.+?)\r*\n-----END CERTIFICATE-----/gs;
2622
2279
  const certs = [];
2623
2280
  let matches;
2624
-
2625
2281
  while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
2626
2282
  // matches[1] represents the first parens capture group in the regex.
2627
2283
  certs.push(matches[1].replace(/\r*\n/g, msalCommon.Constants.EMPTY_STRING));
2628
2284
  }
2629
-
2630
2285
  return certs;
2631
2286
  }
2632
-
2633
2287
  }
2634
2288
 
2635
2289
  /*
@@ -2641,7 +2295,6 @@ class ClientAssertion {
2641
2295
  * will configure application secrets, client certificates/assertions as applicable
2642
2296
  * @public
2643
2297
  */
2644
-
2645
2298
  class ConfidentialClientApplication extends ClientApplication {
2646
2299
  /**
2647
2300
  * Constructor for the ConfidentialClientApplication
@@ -2673,34 +2326,30 @@ class ConfidentialClientApplication extends ClientApplication {
2673
2326
  *
2674
2327
  * @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
2675
2328
  */
2676
-
2677
-
2678
2329
  SetAppTokenProvider(provider) {
2679
2330
  this.appTokenProvider = provider;
2680
2331
  }
2681
2332
  /**
2682
2333
  * Acquires tokens from the authority for the application (not for an end user).
2683
2334
  */
2684
-
2685
-
2686
2335
  async acquireTokenByClientCredential(request) {
2687
- this.logger.info("acquireTokenByClientCredential called", request.correlationId); // If there is a client assertion present in the request, it overrides the one present in the client configuration
2688
-
2336
+ this.logger.info("acquireTokenByClientCredential called", request.correlationId);
2337
+ // If there is a client assertion present in the request, it overrides the one present in the client configuration
2689
2338
  let clientAssertion;
2690
-
2691
2339
  if (request.clientAssertion) {
2692
2340
  clientAssertion = {
2693
2341
  assertion: request.clientAssertion,
2694
2342
  assertionType: Constants.JWT_BEARER_ASSERTION_TYPE
2695
2343
  };
2696
2344
  }
2697
-
2698
- const baseRequest = await this.initializeBaseRequest(request); // valid base request should not contain oidc scopes in this grant type
2699
-
2700
- const validBaseRequest = { ...baseRequest,
2345
+ const baseRequest = await this.initializeBaseRequest(request);
2346
+ // valid base request should not contain oidc scopes in this grant type
2347
+ const validBaseRequest = {
2348
+ ...baseRequest,
2701
2349
  scopes: baseRequest.scopes.filter(scope => !msalCommon.OIDC_DEFAULT_SCOPES.includes(scope))
2702
2350
  };
2703
- const validRequest = { ...request,
2351
+ const validRequest = {
2352
+ ...request,
2704
2353
  ...validBaseRequest,
2705
2354
  clientAssertion
2706
2355
  };
@@ -2709,7 +2358,6 @@ class ConfidentialClientApplication extends ClientApplication {
2709
2358
  environmentRegion: process.env[REGION_ENVIRONMENT_VARIABLE]
2710
2359
  };
2711
2360
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
2712
-
2713
2361
  try {
2714
2362
  const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
2715
2363
  const clientCredentialClient = new msalCommon.ClientCredentialClient(clientCredentialConfig, this.appTokenProvider);
@@ -2719,7 +2367,6 @@ class ConfidentialClientApplication extends ClientApplication {
2719
2367
  if (e instanceof msalCommon.AuthError) {
2720
2368
  e.setCorrelationId(validRequest.correlationId);
2721
2369
  }
2722
-
2723
2370
  serverTelemetryManager.cacheFailedRequest(e);
2724
2371
  throw e;
2725
2372
  }
@@ -2735,14 +2382,12 @@ class ConfidentialClientApplication extends ClientApplication {
2735
2382
  * See how to gain consent upfront for your middle-tier app from this article.
2736
2383
  * https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
2737
2384
  */
2738
-
2739
-
2740
2385
  async acquireTokenOnBehalfOf(request) {
2741
2386
  this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
2742
- const validRequest = { ...request,
2387
+ const validRequest = {
2388
+ ...request,
2743
2389
  ...(await this.initializeBaseRequest(request))
2744
2390
  };
2745
-
2746
2391
  try {
2747
2392
  const onBehalfOfConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
2748
2393
  const oboClient = new msalCommon.OnBehalfOfClient(onBehalfOfConfig);
@@ -2752,11 +2397,9 @@ class ConfidentialClientApplication extends ClientApplication {
2752
2397
  if (e instanceof msalCommon.AuthError) {
2753
2398
  e.setCorrelationId(validRequest.correlationId);
2754
2399
  }
2755
-
2756
2400
  throw e;
2757
2401
  }
2758
2402
  }
2759
-
2760
2403
  setClientCredential(configuration) {
2761
2404
  const clientSecretNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientSecret);
2762
2405
  const clientAssertionNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientAssertion);
@@ -2769,35 +2412,28 @@ class ConfidentialClientApplication extends ClientApplication {
2769
2412
  * If app developer configures this callback, they don't need a credential
2770
2413
  * i.e. AzureSDK can get token from Managed Identity without a cert / secret
2771
2414
  */
2772
-
2773
2415
  if (this.appTokenProvider) {
2774
2416
  return;
2775
- } // Check that at most one credential is set on the application
2776
-
2777
-
2417
+ }
2418
+ // Check that at most one credential is set on the application
2778
2419
  if (clientSecretNotEmpty && clientAssertionNotEmpty || clientAssertionNotEmpty && certificateNotEmpty || clientSecretNotEmpty && certificateNotEmpty) {
2779
2420
  throw msalCommon.ClientAuthError.createInvalidCredentialError();
2780
2421
  }
2781
-
2782
2422
  if (configuration.auth.clientSecret) {
2783
2423
  this.clientSecret = configuration.auth.clientSecret;
2784
2424
  return;
2785
2425
  }
2786
-
2787
2426
  if (configuration.auth.clientAssertion) {
2788
2427
  this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
2789
2428
  return;
2790
2429
  }
2791
-
2792
2430
  if (!certificateNotEmpty) {
2793
2431
  throw msalCommon.ClientAuthError.createInvalidCredentialError();
2794
2432
  } else {
2795
2433
  var _configuration$auth$c;
2796
-
2797
2434
  this.clientAssertion = ClientAssertion.fromCertificate(certificate.thumbprint, certificate.privateKey, (_configuration$auth$c = configuration.auth.clientCertificate) == null ? void 0 : _configuration$auth$c.x5c);
2798
2435
  }
2799
2436
  }
2800
-
2801
2437
  }
2802
2438
 
2803
2439
  /*
@@ -2809,18 +2445,15 @@ class DistributedCachePlugin {
2809
2445
  this.client = client;
2810
2446
  this.partitionManager = partitionManager;
2811
2447
  }
2812
-
2813
2448
  async beforeCacheAccess(cacheContext) {
2814
2449
  const partitionKey = await this.partitionManager.getKey();
2815
2450
  const cacheData = await this.client.get(partitionKey);
2816
2451
  cacheContext.tokenCache.deserialize(cacheData);
2817
2452
  }
2818
-
2819
2453
  async afterCacheAccess(cacheContext) {
2820
2454
  if (cacheContext.cacheHasChanged) {
2821
2455
  const kvStore = cacheContext.tokenCache.getKVStore();
2822
2456
  const accountEntities = Object.values(kvStore).filter(value => msalCommon.AccountEntity.isAccountEntity(value));
2823
-
2824
2457
  if (accountEntities.length > 0) {
2825
2458
  const accountEntity = accountEntities[0];
2826
2459
  const partitionKey = await this.partitionManager.extractKey(accountEntity);
@@ -2828,7 +2461,6 @@ class DistributedCachePlugin {
2828
2461
  }
2829
2462
  }
2830
2463
  }
2831
-
2832
2464
  }
2833
2465
 
2834
2466
  Object.defineProperty(exports, 'AuthError', {