@azure/msal-node 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/cache/NodeStorage.cjs +1 -1
  2. package/dist/cache/NodeStorage.mjs +1 -1
  3. package/dist/cache/TokenCache.cjs +1 -1
  4. package/dist/cache/TokenCache.mjs +1 -1
  5. package/dist/cache/distributed/DistributedCachePlugin.cjs +1 -1
  6. package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
  7. package/dist/cache/serializer/Deserializer.cjs +1 -1
  8. package/dist/cache/serializer/Deserializer.mjs +1 -1
  9. package/dist/cache/serializer/Serializer.cjs +1 -1
  10. package/dist/cache/serializer/Serializer.mjs +1 -1
  11. package/dist/client/ClientApplication.cjs +2 -2
  12. package/dist/client/ClientApplication.cjs.map +1 -1
  13. package/dist/client/ClientApplication.d.ts.map +1 -1
  14. package/dist/client/ClientApplication.mjs +3 -3
  15. package/dist/client/ClientApplication.mjs.map +1 -1
  16. package/dist/client/ClientAssertion.cjs +2 -2
  17. package/dist/client/ClientAssertion.cjs.map +1 -1
  18. package/dist/client/ClientAssertion.d.ts.map +1 -1
  19. package/dist/client/ClientAssertion.mjs +3 -3
  20. package/dist/client/ClientAssertion.mjs.map +1 -1
  21. package/dist/client/ClientCredentialClient.cjs +22 -23
  22. package/dist/client/ClientCredentialClient.cjs.map +1 -1
  23. package/dist/client/ClientCredentialClient.d.ts +0 -1
  24. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  25. package/dist/client/ClientCredentialClient.mjs +23 -24
  26. package/dist/client/ClientCredentialClient.mjs.map +1 -1
  27. package/dist/client/ConfidentialClientApplication.cjs +4 -4
  28. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  29. package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
  30. package/dist/client/ConfidentialClientApplication.mjs +5 -5
  31. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  32. package/dist/client/DeviceCodeClient.cjs +6 -6
  33. package/dist/client/DeviceCodeClient.cjs.map +1 -1
  34. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  35. package/dist/client/DeviceCodeClient.mjs +7 -7
  36. package/dist/client/DeviceCodeClient.mjs.map +1 -1
  37. package/dist/client/OnBehalfOfClient.cjs +4 -4
  38. package/dist/client/OnBehalfOfClient.cjs.map +1 -1
  39. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  40. package/dist/client/OnBehalfOfClient.mjs +5 -5
  41. package/dist/client/OnBehalfOfClient.mjs.map +1 -1
  42. package/dist/client/PublicClientApplication.cjs +56 -9
  43. package/dist/client/PublicClientApplication.cjs.map +1 -1
  44. package/dist/client/PublicClientApplication.d.ts +6 -0
  45. package/dist/client/PublicClientApplication.d.ts.map +1 -1
  46. package/dist/client/PublicClientApplication.mjs +58 -11
  47. package/dist/client/PublicClientApplication.mjs.map +1 -1
  48. package/dist/client/UsernamePasswordClient.cjs +1 -1
  49. package/dist/client/UsernamePasswordClient.mjs +1 -1
  50. package/dist/config/Configuration.cjs +1 -1
  51. package/dist/config/Configuration.mjs +1 -1
  52. package/dist/crypto/CryptoProvider.cjs +1 -1
  53. package/dist/crypto/CryptoProvider.mjs +1 -1
  54. package/dist/crypto/GuidGenerator.cjs +1 -1
  55. package/dist/crypto/GuidGenerator.mjs +1 -1
  56. package/dist/crypto/HashUtils.cjs +1 -1
  57. package/dist/crypto/HashUtils.mjs +1 -1
  58. package/dist/crypto/PkceGenerator.cjs +1 -1
  59. package/dist/crypto/PkceGenerator.mjs +1 -1
  60. package/dist/error/NodeAuthError.cjs +1 -1
  61. package/dist/error/NodeAuthError.mjs +1 -1
  62. package/dist/index.cjs +17 -1
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.ts +1 -1
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.mjs +2 -2
  67. package/dist/internals.cjs +1 -1
  68. package/dist/internals.mjs +1 -1
  69. package/dist/network/HttpClient.cjs +1 -1
  70. package/dist/network/HttpClient.mjs +1 -1
  71. package/dist/network/LoopbackClient.cjs +16 -24
  72. package/dist/network/LoopbackClient.cjs.map +1 -1
  73. package/dist/network/LoopbackClient.d.ts.map +1 -1
  74. package/dist/network/LoopbackClient.mjs +17 -25
  75. package/dist/network/LoopbackClient.mjs.map +1 -1
  76. package/dist/packageMetadata.cjs +2 -2
  77. package/dist/packageMetadata.d.ts +1 -1
  78. package/dist/packageMetadata.mjs +2 -2
  79. package/dist/utils/Constants.cjs +1 -1
  80. package/dist/utils/Constants.mjs +1 -1
  81. package/dist/utils/EncodingUtils.cjs +1 -1
  82. package/dist/utils/EncodingUtils.mjs +1 -1
  83. package/dist/utils/NetworkUtils.cjs +1 -1
  84. package/dist/utils/NetworkUtils.mjs +1 -1
  85. package/package.json +2 -2
  86. package/src/client/ClientApplication.ts +3 -2
  87. package/src/client/ClientAssertion.ts +7 -2
  88. package/src/client/ClientCredentialClient.ts +32 -34
  89. package/src/client/ConfidentialClientApplication.ts +11 -4
  90. package/src/client/DeviceCodeClient.ts +16 -7
  91. package/src/client/OnBehalfOfClient.ts +11 -4
  92. package/src/client/PublicClientApplication.ts +69 -13
  93. package/src/index.ts +5 -0
  94. package/src/network/LoopbackClient.ts +18 -33
  95. package/src/packageMetadata.ts +1 -1
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -19,11 +19,11 @@ class LoopbackClient {
19
19
  * @returns
20
20
  */
21
21
  async listenForAuthCode(successTemplate, errorTemplate) {
22
- if (!!this.server) {
22
+ if (this.server) {
23
23
  throw NodeAuthError.NodeAuthError.createLoopbackServerAlreadyExistsError();
24
24
  }
25
- const authCodeListener = new Promise((resolve, reject) => {
26
- this.server = http.createServer(async (req, res) => {
25
+ return new Promise((resolve, reject) => {
26
+ this.server = http.createServer((req, res) => {
27
27
  const url = req.url;
28
28
  if (!url) {
29
29
  res.end(errorTemplate ||
@@ -38,7 +38,7 @@ class LoopbackClient {
38
38
  }
39
39
  const authCodeResponse = msalCommon.UrlString.getDeserializedQueryString(url);
40
40
  if (authCodeResponse.code) {
41
- const redirectUri = await this.getRedirectUri();
41
+ const redirectUri = this.getRedirectUri();
42
42
  res.writeHead(msalCommon.HttpStatus.REDIRECT, {
43
43
  location: redirectUri,
44
44
  }); // Prevent auth code from being saved in the browser history
@@ -48,30 +48,13 @@ class LoopbackClient {
48
48
  });
49
49
  this.server.listen(0); // Listen on any available port
50
50
  });
51
- // Wait for server to be listening
52
- await new Promise((resolve) => {
53
- let ticks = 0;
54
- const id = setInterval(() => {
55
- if (Constants.LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS /
56
- Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS <
57
- ticks) {
58
- throw NodeAuthError.NodeAuthError.createLoopbackServerTimeoutError();
59
- }
60
- if (this.server.listening) {
61
- clearInterval(id);
62
- resolve();
63
- }
64
- ticks++;
65
- }, Constants.LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
66
- });
67
- return authCodeListener;
68
51
  }
69
52
  /**
70
53
  * Get the port that the loopback server is running on
71
54
  * @returns
72
55
  */
73
56
  getRedirectUri() {
74
- if (!this.server) {
57
+ if (!this.server || !this.server.listening) {
75
58
  throw NodeAuthError.NodeAuthError.createNoLoopbackServerExistsError();
76
59
  }
77
60
  const address = this.server.address();
@@ -86,8 +69,17 @@ class LoopbackClient {
86
69
  * Close the loopback server
87
70
  */
88
71
  closeServer() {
89
- if (!!this.server) {
72
+ if (this.server) {
73
+ // Only stops accepting new connections, server will close once open/idle connections are closed.
90
74
  this.server.close();
75
+ if (typeof this.server.closeAllConnections === "function") {
76
+ /*
77
+ * Close open/idle connections. This API is available in Node versions 18.2 and higher
78
+ */
79
+ this.server.closeAllConnections();
80
+ }
81
+ this.server.unref();
82
+ this.server = undefined;
91
83
  }
92
84
  }
93
85
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LoopbackClient.cjs","sources":["../../src/network/LoopbackClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAKA;AASA;AAEA;;;AAQO;AACG;AAwEN;;;AAGG;AACH,IAAA,MAAA,iBAAwB,CAAA,eAAA,EAAA,aAAA,EAAA;AAgBxB,QAAA,IAAA,CAAA,CAAA,IAAA,CAAA,MAAA,EAAA;;AAEG,SAAA;AACH,QAAA,MAAA,gBAAmB,GAAA,IAAA,OAAA,CAAA,CAAA,OAAA,EAAA,MAAA,KAAA;AAKtB,YAAA,IAAA,CAAA,MAAA,GAAA,IAAA,CAAA,YAAA,CAAA,OAAA,GAAA,EAAA,GAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"LoopbackClient.cjs","sources":["../../src/network/LoopbackClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAKA;AASA;AAEA;;;AAQO;AACG;AA+CN;;;AAGG;AACH,IAAA,MAAA,iBAAwB,CAAA,eAAA,EAAA,aAAA,EAAA;AAgBxB,QAAA,IAAA,IAAA,CAAA,MAAA,EAAA;;AAEG,SAAA;AACH,QAAA,OAAW,IAAI,OAAI,CAAA,CAAA,OAAA,EAAA,MAAA,KAAA;AAetB,YAAA,IAAA,CAAA,MAAA,GAAA,IAAA,CAAA,YAAA,CAAA,CAAA,GAAA,EAAA,GAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"LoopbackClient.d.ts","sourceRoot":"","sources":["../../src/network/LoopbackClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,+BAA+B,EAGlC,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,qBAAa,cAAe,YAAW,eAAe;IAClD,OAAO,CAAC,MAAM,CAAc;IAE5B;;;;;OAKG;IACG,iBAAiB,CACnB,eAAe,CAAC,EAAE,MAAM,EACxB,aAAa,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,+BAA+B,CAAC;IAqE3C;;;OAGG;IACH,cAAc,IAAI,MAAM;IAgBxB;;OAEG;IACH,WAAW,IAAI,IAAI;CAKtB"}
1
+ {"version":3,"file":"LoopbackClient.d.ts","sourceRoot":"","sources":["../../src/network/LoopbackClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,+BAA+B,EAGlC,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,qBAAa,cAAe,YAAW,eAAe;IAClD,OAAO,CAAC,MAAM,CAA0B;IAExC;;;;;OAKG;IACG,iBAAiB,CACnB,eAAe,CAAC,EAAE,MAAM,EACxB,aAAa,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,+BAA+B,CAAC;IA4C3C;;;OAGG;IACH,cAAc,IAAI,MAAM;IAgBxB;;OAEG;IACH,WAAW,IAAI,IAAI;CAetB"}
@@ -1,9 +1,9 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  import { Constants, UrlString, HttpStatus } from '@azure/msal-common';
4
4
  import http from 'http';
5
5
  import { NodeAuthError } from '../error/NodeAuthError.mjs';
6
- import { LOOPBACK_SERVER_CONSTANTS, Constants as Constants$1 } from '../utils/Constants.mjs';
6
+ import { Constants as Constants$1 } from '../utils/Constants.mjs';
7
7
 
8
8
  /*
9
9
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -17,11 +17,11 @@ class LoopbackClient {
17
17
  * @returns
18
18
  */
19
19
  async listenForAuthCode(successTemplate, errorTemplate) {
20
- if (!!this.server) {
20
+ if (this.server) {
21
21
  throw NodeAuthError.createLoopbackServerAlreadyExistsError();
22
22
  }
23
- const authCodeListener = new Promise((resolve, reject) => {
24
- this.server = http.createServer(async (req, res) => {
23
+ return new Promise((resolve, reject) => {
24
+ this.server = http.createServer((req, res) => {
25
25
  const url = req.url;
26
26
  if (!url) {
27
27
  res.end(errorTemplate ||
@@ -36,7 +36,7 @@ class LoopbackClient {
36
36
  }
37
37
  const authCodeResponse = UrlString.getDeserializedQueryString(url);
38
38
  if (authCodeResponse.code) {
39
- const redirectUri = await this.getRedirectUri();
39
+ const redirectUri = this.getRedirectUri();
40
40
  res.writeHead(HttpStatus.REDIRECT, {
41
41
  location: redirectUri,
42
42
  }); // Prevent auth code from being saved in the browser history
@@ -46,30 +46,13 @@ class LoopbackClient {
46
46
  });
47
47
  this.server.listen(0); // Listen on any available port
48
48
  });
49
- // Wait for server to be listening
50
- await new Promise((resolve) => {
51
- let ticks = 0;
52
- const id = setInterval(() => {
53
- if (LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS /
54
- LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS <
55
- ticks) {
56
- throw NodeAuthError.createLoopbackServerTimeoutError();
57
- }
58
- if (this.server.listening) {
59
- clearInterval(id);
60
- resolve();
61
- }
62
- ticks++;
63
- }, LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
64
- });
65
- return authCodeListener;
66
49
  }
67
50
  /**
68
51
  * Get the port that the loopback server is running on
69
52
  * @returns
70
53
  */
71
54
  getRedirectUri() {
72
- if (!this.server) {
55
+ if (!this.server || !this.server.listening) {
73
56
  throw NodeAuthError.createNoLoopbackServerExistsError();
74
57
  }
75
58
  const address = this.server.address();
@@ -84,8 +67,17 @@ class LoopbackClient {
84
67
  * Close the loopback server
85
68
  */
86
69
  closeServer() {
87
- if (!!this.server) {
70
+ if (this.server) {
71
+ // Only stops accepting new connections, server will close once open/idle connections are closed.
88
72
  this.server.close();
73
+ if (typeof this.server.closeAllConnections === "function") {
74
+ /*
75
+ * Close open/idle connections. This API is available in Node versions 18.2 and higher
76
+ */
77
+ this.server.closeAllConnections();
78
+ }
79
+ this.server.unref();
80
+ this.server = undefined;
89
81
  }
90
82
  }
91
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LoopbackClient.mjs","sources":["../../src/network/LoopbackClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAKA;AASA;AAEA;;;AAQO;AACG;AAwEN;;;AAGG;AACH,IAAA,MAAA,iBAAwB,CAAA,eAAA,EAAA,aAAA,EAAA;AAgBxB,QAAA,IAAA,CAAA,CAAA,IAAA,CAAA,MAAA,EAAA;;AAEG,SAAA;AACH,QAAA,MAAA,gBAAmB,GAAA,IAAA,OAAA,CAAA,CAAA,OAAA,EAAA,MAAA,KAAA;AAKtB,YAAA,IAAA,CAAA,MAAA,GAAA,IAAA,CAAA,YAAA,CAAA,OAAA,GAAA,EAAA,GAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"LoopbackClient.mjs","sources":["../../src/network/LoopbackClient.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAKA;AASA;AAEA;;;AAQO;AACG;AA+CN;;;AAGG;AACH,IAAA,MAAA,iBAAwB,CAAA,eAAA,EAAA,aAAA,EAAA;AAgBxB,QAAA,IAAA,IAAA,CAAA,MAAA,EAAA;;AAEG,SAAA;AACH,QAAA,OAAW,IAAI,OAAI,CAAA,CAAA,OAAA,EAAA,MAAA,KAAA;AAetB,YAAA,IAAA,CAAA,MAAA,GAAA,IAAA,CAAA,YAAA,CAAA,CAAA,GAAA,EAAA,GAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,10 +1,10 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
5
5
  /* eslint-disable header/header */
6
6
  const name = "@azure/msal-node";
7
- const version = "2.1.0";
7
+ const version = "2.2.0";
8
8
 
9
9
  exports.name = name;
10
10
  exports.version = version;
@@ -1,3 +1,3 @@
1
1
  export declare const name = "@azure/msal-node";
2
- export declare const version = "2.1.0";
2
+ export declare const version = "2.2.0";
3
3
  //# sourceMappingURL=packageMetadata.d.ts.map
@@ -1,8 +1,8 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  /* eslint-disable header/header */
4
4
  const name = "@azure/msal-node";
5
- const version = "2.1.0";
5
+ const version = "2.2.0";
6
6
 
7
7
  export { name, version };
8
8
  //# sourceMappingURL=packageMetadata.mjs.map
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  /*
4
4
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  import { Constants } from '@azure/msal-common';
4
4
 
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-node v2.1.0 2023-09-05 */
1
+ /*! @azure/msal-node v2.2.0 2023-10-05 */
2
2
  'use strict';
3
3
  /*
4
4
  * Copyright (c) Microsoft Corporation. All rights reserved.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@azure/msal-node",
4
- "version": "2.1.0",
4
+ "version": "2.2.0",
5
5
  "author": {
6
6
  "name": "Microsoft",
7
7
  "email": "nugetaad@microsoft.com",
@@ -77,7 +77,7 @@
77
77
  "yargs": "^17.3.1"
78
78
  },
79
79
  "dependencies": {
80
- "@azure/msal-common": "14.0.3",
80
+ "@azure/msal-common": "14.1.0",
81
81
  "jsonwebtoken": "^9.0.0",
82
82
  "uuid": "^8.3.0"
83
83
  },
@@ -28,9 +28,10 @@ import {
28
28
  AuthError,
29
29
  AzureCloudOptions,
30
30
  AuthorizationCodePayload,
31
- ClientAuthError,
32
31
  Constants,
33
32
  StringUtils,
33
+ createClientAuthError,
34
+ ClientAuthErrorCodes,
34
35
  } from "@azure/msal-common";
35
36
  import {
36
37
  Configuration,
@@ -367,7 +368,7 @@ export abstract class ClientApplication {
367
368
  }
368
369
 
369
370
  if (state !== cachedState) {
370
- throw ClientAuthError.createStateMismatchError();
371
+ throw createClientAuthError(ClientAuthErrorCodes.stateMismatch);
371
372
  }
372
373
  }
373
374
 
@@ -4,7 +4,12 @@
4
4
  */
5
5
 
6
6
  import jwt from "jsonwebtoken";
7
- import { TimeUtils, ClientAuthError, Constants } from "@azure/msal-common";
7
+ import {
8
+ TimeUtils,
9
+ Constants,
10
+ createClientAuthError,
11
+ ClientAuthErrorCodes,
12
+ } from "@azure/msal-common";
8
13
  import { CryptoProvider } from "../crypto/CryptoProvider.js";
9
14
  import { EncodingUtils } from "../utils/EncodingUtils.js";
10
15
  import { JwtConstants } from "../utils/Constants.js";
@@ -86,7 +91,7 @@ export class ClientAssertion {
86
91
  return this.jwt;
87
92
  }
88
93
 
89
- throw ClientAuthError.createInvalidAssertionError();
94
+ throw createClientAuthError(ClientAuthErrorCodes.invalidAssertion);
90
95
  }
91
96
 
92
97
  /**
@@ -10,7 +10,7 @@ import {
10
10
  Authority,
11
11
  BaseClient,
12
12
  CacheOutcome,
13
- ClientAuthError,
13
+ ClientAuthErrorCodes,
14
14
  ClientConfiguration,
15
15
  CommonClientCredentialRequest,
16
16
  Constants,
@@ -27,6 +27,7 @@ import {
27
27
  TimeUtils,
28
28
  TokenCacheContext,
29
29
  UrlString,
30
+ createClientAuthError,
30
31
  } from "@azure/msal-common";
31
32
 
32
33
  /**
@@ -35,7 +36,6 @@ import {
35
36
  export class ClientCredentialClient extends BaseClient {
36
37
  private scopeSet: ScopeSet;
37
38
  private readonly appTokenProvider?: IAppTokenProvider;
38
- private lastCacheOutcome: CacheOutcome;
39
39
 
40
40
  constructor(
41
41
  configuration: ClientConfiguration,
@@ -58,20 +58,17 @@ export class ClientCredentialClient extends BaseClient {
58
58
  return await this.executeTokenRequest(request, this.authority);
59
59
  }
60
60
 
61
- const cachedAuthenticationResult =
61
+ const [cachedAuthenticationResult, lastCacheOutcome] =
62
62
  await this.getCachedAuthenticationResult(request);
63
63
 
64
64
  if (cachedAuthenticationResult) {
65
65
  // if the token is not expired but must be refreshed; get a new one in the background
66
- if (
67
- this.lastCacheOutcome ===
68
- CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN
69
- ) {
66
+ if (lastCacheOutcome === CacheOutcome.PROACTIVELY_REFRESHED) {
70
67
  this.logger.info(
71
68
  "ClientCredentialClient:getCachedAuthenticationResult - Cached access token's refreshOn property has been exceeded'. It's not expired, but must be refreshed."
72
69
  );
73
70
 
74
- // return the cached token, don't wait for the result of this request
71
+ // refresh the access token in the background
75
72
  const refreshAccessToken = true;
76
73
  await this.executeTokenRequest(
77
74
  request,
@@ -80,10 +77,7 @@ export class ClientCredentialClient extends BaseClient {
80
77
  );
81
78
  }
82
79
 
83
- // reset the last cache outcome
84
- this.lastCacheOutcome = CacheOutcome.NO_CACHE_HIT;
85
-
86
- // otherwise, the token is not expired and does not need to be refreshed
80
+ // return the cached token
87
81
  return cachedAuthenticationResult;
88
82
  } else {
89
83
  return await this.executeTokenRequest(request, this.authority);
@@ -95,7 +89,9 @@ export class ClientCredentialClient extends BaseClient {
95
89
  */
96
90
  private async getCachedAuthenticationResult(
97
91
  request: CommonClientCredentialRequest
98
- ): Promise<AuthenticationResult | null> {
92
+ ): Promise<[AuthenticationResult | null, CacheOutcome]> {
93
+ let lastCacheOutcome: CacheOutcome = CacheOutcome.NOT_APPLICABLE;
94
+
99
95
  // read the user-supplied cache into memory, if applicable
100
96
  let cacheContext;
101
97
  if (this.config.serializableCache && this.config.persistencePlugin) {
@@ -118,11 +114,10 @@ export class ClientCredentialClient extends BaseClient {
118
114
 
119
115
  // must refresh due to non-existent access_token
120
116
  if (!cachedAccessToken) {
121
- this.lastCacheOutcome = CacheOutcome.NO_CACHED_ACCESS_TOKEN;
122
117
  this.serverTelemetryManager?.setCacheOutcome(
123
118
  CacheOutcome.NO_CACHED_ACCESS_TOKEN
124
119
  );
125
- return null;
120
+ return [null, CacheOutcome.NO_CACHED_ACCESS_TOKEN];
126
121
  }
127
122
 
128
123
  // must refresh due to the expires_in value
@@ -132,12 +127,10 @@ export class ClientCredentialClient extends BaseClient {
132
127
  this.config.systemOptions.tokenRenewalOffsetSeconds
133
128
  )
134
129
  ) {
135
- this.lastCacheOutcome = CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED;
136
130
  this.serverTelemetryManager?.setCacheOutcome(
137
131
  CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED
138
132
  );
139
-
140
- return null;
133
+ return [null, CacheOutcome.CACHED_ACCESS_TOKEN_EXPIRED];
141
134
  }
142
135
 
143
136
  // must refresh (in the background) due to the refresh_in value
@@ -145,25 +138,28 @@ export class ClientCredentialClient extends BaseClient {
145
138
  cachedAccessToken.refreshOn &&
146
139
  TimeUtils.isTokenExpired(cachedAccessToken.refreshOn.toString(), 0)
147
140
  ) {
148
- this.lastCacheOutcome = CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN;
141
+ lastCacheOutcome = CacheOutcome.PROACTIVELY_REFRESHED;
149
142
  this.serverTelemetryManager?.setCacheOutcome(
150
- CacheOutcome.REFRESH_CACHED_ACCESS_TOKEN
143
+ CacheOutcome.PROACTIVELY_REFRESHED
151
144
  );
152
145
  }
153
146
 
154
- return await ResponseHandler.generateAuthenticationResult(
155
- this.cryptoUtils,
156
- this.authority,
157
- {
158
- account: null,
159
- idToken: null,
160
- accessToken: cachedAccessToken,
161
- refreshToken: null,
162
- appMetadata: null,
163
- },
164
- true,
165
- request
166
- );
147
+ return [
148
+ await ResponseHandler.generateAuthenticationResult(
149
+ this.cryptoUtils,
150
+ this.authority,
151
+ {
152
+ account: null,
153
+ idToken: null,
154
+ accessToken: cachedAccessToken,
155
+ refreshToken: null,
156
+ appMetadata: null,
157
+ },
158
+ true,
159
+ request
160
+ ),
161
+ lastCacheOutcome,
162
+ ];
167
163
  }
168
164
 
169
165
  /**
@@ -185,7 +181,9 @@ export class ClientCredentialClient extends BaseClient {
185
181
  if (accessTokens.length < 1) {
186
182
  return null;
187
183
  } else if (accessTokens.length > 1) {
188
- throw ClientAuthError.createMultipleMatchingTokensInCacheError();
184
+ throw createClientAuthError(
185
+ ClientAuthErrorCodes.multipleMatchingTokens
186
+ );
189
187
  }
190
188
  return accessTokens[0] as AccessTokenEntity;
191
189
  }
@@ -17,7 +17,6 @@ import {
17
17
  CommonClientCredentialRequest,
18
18
  CommonOnBehalfOfRequest,
19
19
  AuthenticationResult,
20
- ClientAuthError,
21
20
  AzureRegionConfiguration,
22
21
  AuthError,
23
22
  Constants,
@@ -25,6 +24,8 @@ import {
25
24
  OIDC_DEFAULT_SCOPES,
26
25
  UrlString,
27
26
  AADAuthorityConstants,
27
+ createClientAuthError,
28
+ ClientAuthErrorCodes,
28
29
  } from "@azure/msal-common";
29
30
  import { IConfidentialClientApplication } from "./IConfidentialClientApplication.js";
30
31
  import { OnBehalfOfRequest } from "../request/OnBehalfOfRequest.js";
@@ -125,7 +126,9 @@ export class ConfidentialClientApplication
125
126
  tenantId as AADAuthorityConstants
126
127
  )
127
128
  ) {
128
- throw ClientAuthError.createMissingTenantIdError();
129
+ throw createClientAuthError(
130
+ ClientAuthErrorCodes.missingTenantIdError
131
+ );
129
132
  }
130
133
 
131
134
  const azureRegionConfiguration: AzureRegionConfiguration = {
@@ -233,7 +236,9 @@ export class ConfidentialClientApplication
233
236
  (clientAssertionNotEmpty && certificateNotEmpty) ||
234
237
  (clientSecretNotEmpty && certificateNotEmpty)
235
238
  ) {
236
- throw ClientAuthError.createInvalidCredentialError();
239
+ throw createClientAuthError(
240
+ ClientAuthErrorCodes.invalidClientCredential
241
+ );
237
242
  }
238
243
 
239
244
  if (configuration.auth.clientSecret) {
@@ -249,7 +254,9 @@ export class ConfidentialClientApplication
249
254
  }
250
255
 
251
256
  if (!certificateNotEmpty) {
252
- throw ClientAuthError.createInvalidCredentialError();
257
+ throw createClientAuthError(
258
+ ClientAuthErrorCodes.invalidClientCredential
259
+ );
253
260
  } else {
254
261
  this.clientAssertion = ClientAssertion.fromCertificate(
255
262
  certificate.thumbprint,
@@ -4,9 +4,10 @@
4
4
  */
5
5
 
6
6
  import {
7
+ AuthErrorCodes,
7
8
  AuthenticationResult,
8
9
  BaseClient,
9
- ClientAuthError,
10
+ ClientAuthErrorCodes,
10
11
  ClientConfiguration,
11
12
  CommonDeviceCodeRequest,
12
13
  Constants,
@@ -17,10 +18,11 @@ import {
17
18
  ResponseHandler,
18
19
  ServerAuthorizationTokenResponse,
19
20
  ServerDeviceCodeResponse,
20
- ServerError,
21
21
  StringUtils,
22
22
  TimeUtils,
23
23
  UrlString,
24
+ createAuthError,
25
+ createClientAuthError,
24
26
  } from "@azure/msal-common";
25
27
 
26
28
  /**
@@ -200,7 +202,9 @@ export class DeviceCodeClient extends BaseClient {
200
202
  this.logger.error(
201
203
  "Token request cancelled by setting DeviceCodeRequest.cancel = true"
202
204
  );
203
- throw ClientAuthError.createDeviceCodeCancelledError();
205
+ throw createClientAuthError(
206
+ ClientAuthErrorCodes.deviceCodePollingCancelled
207
+ );
204
208
  } else if (
205
209
  userSpecifiedTimeout &&
206
210
  userSpecifiedTimeout < deviceCodeExpirationTime &&
@@ -209,7 +213,9 @@ export class DeviceCodeClient extends BaseClient {
209
213
  this.logger.error(
210
214
  `User defined timeout for device code polling reached. The timeout was set for ${userSpecifiedTimeout}`
211
215
  );
212
- throw ClientAuthError.createUserTimeoutReachedError();
216
+ throw createClientAuthError(
217
+ ClientAuthErrorCodes.userTimeoutReached
218
+ );
213
219
  } else if (TimeUtils.nowSeconds() > deviceCodeExpirationTime) {
214
220
  if (userSpecifiedTimeout) {
215
221
  this.logger.verbose(
@@ -219,7 +225,7 @@ export class DeviceCodeClient extends BaseClient {
219
225
  this.logger.error(
220
226
  `Device code expired. Expiration time of device code was ${deviceCodeExpirationTime}`
221
227
  );
222
- throw ClientAuthError.createDeviceCodeExpiredError();
228
+ throw createClientAuthError(ClientAuthErrorCodes.deviceCodeExpired);
223
229
  }
224
230
  return true;
225
231
  }
@@ -295,7 +301,8 @@ export class DeviceCodeClient extends BaseClient {
295
301
  this.logger.info(
296
302
  "Unexpected error in polling from the server"
297
303
  );
298
- throw ServerError.createPostRequestFailed(
304
+ throw createAuthError(
305
+ AuthErrorCodes.postRequestFailed,
299
306
  response.body.error
300
307
  );
301
308
  }
@@ -312,7 +319,9 @@ export class DeviceCodeClient extends BaseClient {
312
319
  * and in the rare case the conditionals in continuePolling() may not catch everything...
313
320
  */
314
321
  this.logger.error("Polling stopped for unknown reasons.");
315
- throw ClientAuthError.createDeviceCodeUnknownError();
322
+ throw createClientAuthError(
323
+ ClientAuthErrorCodes.deviceCodeUnknownError
324
+ );
316
325
  }
317
326
 
318
327
  /**
@@ -14,10 +14,11 @@ import {
14
14
  AuthToken,
15
15
  BaseClient,
16
16
  CacheOutcome,
17
- ClientAuthError,
17
+ ClientAuthErrorCodes,
18
18
  ClientConfiguration,
19
19
  CommonOnBehalfOfRequest,
20
20
  Constants,
21
+ createClientAuthError,
21
22
  CredentialFilter,
22
23
  CredentialType,
23
24
  GrantType,
@@ -101,7 +102,9 @@ export class OnBehalfOfClient extends BaseClient {
101
102
  this.logger.info(
102
103
  "SilentFlowClient:acquireCachedToken - No access token found in cache for the given properties."
103
104
  );
104
- throw ClientAuthError.createRefreshRequiredError();
105
+ throw createClientAuthError(
106
+ ClientAuthErrorCodes.tokenRefreshRequired
107
+ );
105
108
  } else if (
106
109
  TimeUtils.isTokenExpired(
107
110
  cachedAccessToken.expiresOn,
@@ -115,7 +118,9 @@ export class OnBehalfOfClient extends BaseClient {
115
118
  this.logger.info(
116
119
  `OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within ${this.config.systemOptions.tokenRenewalOffsetSeconds} seconds.`
117
120
  );
118
- throw ClientAuthError.createRefreshRequiredError();
121
+ throw createClientAuthError(
122
+ ClientAuthErrorCodes.tokenRefreshRequired
123
+ );
119
124
  }
120
125
 
121
126
  // fetch the idToken from cache
@@ -229,7 +234,9 @@ export class OnBehalfOfClient extends BaseClient {
229
234
  if (numAccessTokens < 1) {
230
235
  return null;
231
236
  } else if (numAccessTokens > 1) {
232
- throw ClientAuthError.createMultipleMatchingTokensInCacheError();
237
+ throw createClientAuthError(
238
+ ClientAuthErrorCodes.multipleMatchingTokens
239
+ );
233
240
  }
234
241
 
235
242
  return accessTokens[0] as AccessTokenEntity;