@azure/identity 4.0.2-alpha.20240122.4 → 4.1.0-alpha.20240124.2

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.

Potentially problematic release.


This version of @azure/identity might be problematic. Click here for more details.

Files changed (34) hide show
  1. package/dist/index.js +263 -249
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/src/constants.js +1 -1
  4. package/dist-esm/src/constants.js.map +1 -1
  5. package/dist-esm/src/credentials/azureCliCredential.js +37 -7
  6. package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
  7. package/dist-esm/src/msal/browserFlows/msalAuthCode.js +7 -4
  8. package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
  9. package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js +19 -3
  10. package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  11. package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js +3 -2
  12. package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js.map +1 -1
  13. package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js +3 -2
  14. package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js.map +1 -1
  15. package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js +3 -2
  16. package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js.map +1 -1
  17. package/dist-esm/src/msal/nodeFlows/msalClientSecret.js +3 -2
  18. package/dist-esm/src/msal/nodeFlows/msalClientSecret.js.map +1 -1
  19. package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js +3 -2
  20. package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js.map +1 -1
  21. package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js +26 -8
  22. package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
  23. package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js +3 -2
  24. package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js.map +1 -1
  25. package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js +3 -2
  26. package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +1 -1
  27. package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js +3 -2
  28. package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js.map +1 -1
  29. package/dist-esm/src/msal/utils.browser.js +38 -70
  30. package/dist-esm/src/msal/utils.browser.js.map +1 -1
  31. package/dist-esm/src/msal/utils.js +42 -74
  32. package/dist-esm/src/msal/utils.js.map +1 -1
  33. package/package.json +1 -1
  34. package/types/identity.d.ts +11 -0
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var msalCommon = require('@azure/msal-node');
6
- var logger$o = require('@azure/logger');
6
+ var logger$p = require('@azure/logger');
7
7
  var abortController = require('@azure/abort-controller');
8
8
  var coreUtil = require('@azure/core-util');
9
9
  var coreClient = require('@azure/core-client');
@@ -39,6 +39,145 @@ function _interopNamespaceDefault(e) {
39
39
  var msalCommon__namespace = /*#__PURE__*/_interopNamespaceDefault(msalCommon);
40
40
  var child_process__namespace = /*#__PURE__*/_interopNamespaceDefault(child_process);
41
41
 
42
+ // Copyright (c) Microsoft Corporation.
43
+ // Licensed under the MIT license.
44
+ /**
45
+ * Current version of the `@azure/identity` package.
46
+ */
47
+ const SDK_VERSION = `4.1.0-beta.1`;
48
+ /**
49
+ * The default client ID for authentication
50
+ * @internal
51
+ */
52
+ // TODO: temporary - this is the Azure CLI clientID - we'll replace it when
53
+ // Developer Sign On application is available
54
+ // https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/Constants.cs#L9
55
+ const DeveloperSignOnClientId = "04b07795-8ddb-461a-bbee-02f9e1bf7b46";
56
+ /**
57
+ * The default tenant for authentication
58
+ * @internal
59
+ */
60
+ const DefaultTenantId = "common";
61
+ /**
62
+ * A list of known Azure authority hosts
63
+ */
64
+ exports.AzureAuthorityHosts = void 0;
65
+ (function (AzureAuthorityHosts) {
66
+ /**
67
+ * China-based Azure Authority Host
68
+ */
69
+ AzureAuthorityHosts["AzureChina"] = "https://login.chinacloudapi.cn";
70
+ /**
71
+ * Germany-based Azure Authority Host
72
+ */
73
+ AzureAuthorityHosts["AzureGermany"] = "https://login.microsoftonline.de";
74
+ /**
75
+ * US Government Azure Authority Host
76
+ */
77
+ AzureAuthorityHosts["AzureGovernment"] = "https://login.microsoftonline.us";
78
+ /**
79
+ * Public Cloud Azure Authority Host
80
+ */
81
+ AzureAuthorityHosts["AzurePublicCloud"] = "https://login.microsoftonline.com";
82
+ })(exports.AzureAuthorityHosts || (exports.AzureAuthorityHosts = {}));
83
+ /**
84
+ * @internal
85
+ * The default authority host.
86
+ */
87
+ const DefaultAuthorityHost = exports.AzureAuthorityHosts.AzurePublicCloud;
88
+ /**
89
+ * @internal
90
+ * Allow acquiring tokens for any tenant for multi-tentant auth.
91
+ */
92
+ const ALL_TENANTS = ["*"];
93
+ /**
94
+ * @internal
95
+ */
96
+ const CACHE_CAE_SUFFIX = ".cae";
97
+ /**
98
+ * @internal
99
+ */
100
+ const CACHE_NON_CAE_SUFFIX = ".nocae";
101
+
102
+ // Copyright (c) Microsoft Corporation.
103
+ // Licensed under the MIT license.
104
+ /**
105
+ * The AzureLogger used for all clients within the identity package
106
+ */
107
+ const logger$o = logger$p.createClientLogger("identity");
108
+ /**
109
+ * Separates a list of environment variable names into a plain object with two arrays: an array of missing environment variables and another array with assigned environment variables.
110
+ * @param supportedEnvVars - List of environment variable names
111
+ */
112
+ function processEnvVars(supportedEnvVars) {
113
+ return supportedEnvVars.reduce((acc, envVariable) => {
114
+ if (process.env[envVariable]) {
115
+ acc.assigned.push(envVariable);
116
+ }
117
+ else {
118
+ acc.missing.push(envVariable);
119
+ }
120
+ return acc;
121
+ }, { missing: [], assigned: [] });
122
+ }
123
+ /**
124
+ * Formatting the success event on the credentials
125
+ */
126
+ function formatSuccess(scope) {
127
+ return `SUCCESS. Scopes: ${Array.isArray(scope) ? scope.join(", ") : scope}.`;
128
+ }
129
+ /**
130
+ * Formatting the success event on the credentials
131
+ */
132
+ function formatError(scope, error) {
133
+ let message = "ERROR.";
134
+ if (scope === null || scope === void 0 ? void 0 : scope.length) {
135
+ message += ` Scopes: ${Array.isArray(scope) ? scope.join(", ") : scope}.`;
136
+ }
137
+ return `${message} Error message: ${typeof error === "string" ? error : error.message}.`;
138
+ }
139
+ /**
140
+ * Generates a CredentialLoggerInstance.
141
+ *
142
+ * It logs with the format:
143
+ *
144
+ * `[title] => [message]`
145
+ *
146
+ */
147
+ function credentialLoggerInstance(title, parent, log = logger$o) {
148
+ const fullTitle = parent ? `${parent.fullTitle} ${title}` : title;
149
+ function info(message) {
150
+ log.info(`${fullTitle} =>`, message);
151
+ }
152
+ function warning(message) {
153
+ log.warning(`${fullTitle} =>`, message);
154
+ }
155
+ function verbose(message) {
156
+ log.verbose(`${fullTitle} =>`, message);
157
+ }
158
+ return {
159
+ title,
160
+ fullTitle,
161
+ info,
162
+ warning,
163
+ verbose,
164
+ };
165
+ }
166
+ /**
167
+ * Generates a CredentialLogger, which is a logger declared at the credential's constructor, and used at any point in the credential.
168
+ * It has all the properties of a CredentialLoggerInstance, plus other logger instances, one per method.
169
+ *
170
+ * It logs with the format:
171
+ *
172
+ * `[title] => [message]`
173
+ * `[title] => getToken() => [message]`
174
+ *
175
+ */
176
+ function credentialLogger(title, log = logger$o) {
177
+ const credLogger = credentialLoggerInstance(title, undefined, log);
178
+ return Object.assign(Object.assign({}, credLogger), { parent: log, getToken: credentialLoggerInstance("=> getToken()", credLogger, log) });
179
+ }
180
+
42
181
  // Copyright (c) Microsoft Corporation.
43
182
  // Licensed under the MIT license.
44
183
  function isErrorResponse(errorResponse) {
@@ -161,144 +300,9 @@ class AuthenticationRequiredError extends Error {
161
300
  // Copyright (c) Microsoft Corporation.
162
301
  // Licensed under the MIT license.
163
302
  /**
164
- * The AzureLogger used for all clients within the identity package
165
- */
166
- const logger$n = logger$o.createClientLogger("identity");
167
- /**
168
- * Separates a list of environment variable names into a plain object with two arrays: an array of missing environment variables and another array with assigned environment variables.
169
- * @param supportedEnvVars - List of environment variable names
170
- */
171
- function processEnvVars(supportedEnvVars) {
172
- return supportedEnvVars.reduce((acc, envVariable) => {
173
- if (process.env[envVariable]) {
174
- acc.assigned.push(envVariable);
175
- }
176
- else {
177
- acc.missing.push(envVariable);
178
- }
179
- return acc;
180
- }, { missing: [], assigned: [] });
181
- }
182
- /**
183
- * Formatting the success event on the credentials
184
- */
185
- function formatSuccess(scope) {
186
- return `SUCCESS. Scopes: ${Array.isArray(scope) ? scope.join(", ") : scope}.`;
187
- }
188
- /**
189
- * Formatting the success event on the credentials
190
- */
191
- function formatError(scope, error) {
192
- let message = "ERROR.";
193
- if (scope === null || scope === void 0 ? void 0 : scope.length) {
194
- message += ` Scopes: ${Array.isArray(scope) ? scope.join(", ") : scope}.`;
195
- }
196
- return `${message} Error message: ${typeof error === "string" ? error : error.message}.`;
197
- }
198
- /**
199
- * Generates a CredentialLoggerInstance.
200
- *
201
- * It logs with the format:
202
- *
203
- * `[title] => [message]`
204
- *
205
- */
206
- function credentialLoggerInstance(title, parent, log = logger$n) {
207
- const fullTitle = parent ? `${parent.fullTitle} ${title}` : title;
208
- function info(message) {
209
- log.info(`${fullTitle} =>`, message);
210
- }
211
- function warning(message) {
212
- log.warning(`${fullTitle} =>`, message);
213
- }
214
- function verbose(message) {
215
- log.verbose(`${fullTitle} =>`, message);
216
- }
217
- return {
218
- title,
219
- fullTitle,
220
- info,
221
- warning,
222
- verbose,
223
- };
224
- }
225
- /**
226
- * Generates a CredentialLogger, which is a logger declared at the credential's constructor, and used at any point in the credential.
227
- * It has all the properties of a CredentialLoggerInstance, plus other logger instances, one per method.
228
- *
229
- * It logs with the format:
230
- *
231
- * `[title] => [message]`
232
- * `[title] => getToken() => [message]`
233
- *
234
- */
235
- function credentialLogger(title, log = logger$n) {
236
- const credLogger = credentialLoggerInstance(title, undefined, log);
237
- return Object.assign(Object.assign({}, credLogger), { parent: log, getToken: credentialLoggerInstance("=> getToken()", credLogger, log) });
238
- }
239
-
240
- // Copyright (c) Microsoft Corporation.
241
- // Licensed under the MIT license.
242
- /**
243
- * Current version of the `@azure/identity` package.
244
- */
245
- const SDK_VERSION = `4.0.2`;
246
- /**
247
- * The default client ID for authentication
248
- * @internal
249
- */
250
- // TODO: temporary - this is the Azure CLI clientID - we'll replace it when
251
- // Developer Sign On application is available
252
- // https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/Constants.cs#L9
253
- const DeveloperSignOnClientId = "04b07795-8ddb-461a-bbee-02f9e1bf7b46";
254
- /**
255
- * The default tenant for authentication
256
303
  * @internal
257
304
  */
258
- const DefaultTenantId = "common";
259
- /**
260
- * A list of known Azure authority hosts
261
- */
262
- exports.AzureAuthorityHosts = void 0;
263
- (function (AzureAuthorityHosts) {
264
- /**
265
- * China-based Azure Authority Host
266
- */
267
- AzureAuthorityHosts["AzureChina"] = "https://login.chinacloudapi.cn";
268
- /**
269
- * Germany-based Azure Authority Host
270
- */
271
- AzureAuthorityHosts["AzureGermany"] = "https://login.microsoftonline.de";
272
- /**
273
- * US Government Azure Authority Host
274
- */
275
- AzureAuthorityHosts["AzureGovernment"] = "https://login.microsoftonline.us";
276
- /**
277
- * Public Cloud Azure Authority Host
278
- */
279
- AzureAuthorityHosts["AzurePublicCloud"] = "https://login.microsoftonline.com";
280
- })(exports.AzureAuthorityHosts || (exports.AzureAuthorityHosts = {}));
281
- /**
282
- * @internal
283
- * The default authority host.
284
- */
285
- const DefaultAuthorityHost = exports.AzureAuthorityHosts.AzurePublicCloud;
286
- /**
287
- * @internal
288
- * Allow acquiring tokens for any tenant for multi-tentant auth.
289
- */
290
- const ALL_TENANTS = ["*"];
291
- /**
292
- * @internal
293
- */
294
- const CACHE_CAE_SUFFIX = ".cae";
295
- /**
296
- * @internal
297
- */
298
- const CACHE_NON_CAE_SUFFIX = ".nocae";
299
-
300
- // Copyright (c) Microsoft Corporation.
301
- // Licensed under the MIT license.
305
+ const logger$n = credentialLogger("IdentityUtils");
302
306
  /**
303
307
  * Latest AuthenticationRecord version
304
308
  * @internal
@@ -308,9 +312,9 @@ const LatestAuthenticationRecordVersion = "1.0";
308
312
  * Ensures the validity of the MSAL token
309
313
  * @internal
310
314
  */
311
- function ensureValidMsalToken(scopes, logger, msalToken, getTokenOptions) {
315
+ function ensureValidMsalToken(scopes, msalToken, getTokenOptions) {
312
316
  const error = (message) => {
313
- logger.getToken.info(message);
317
+ logger$n.getToken.info(message);
314
318
  return new AuthenticationRequiredError({
315
319
  scopes: Array.isArray(scopes) ? scopes : [scopes],
316
320
  getTokenOptions,
@@ -360,25 +364,25 @@ function getKnownAuthorities(tenantId, authorityHost, disableInstanceDiscovery)
360
364
  }
361
365
  /**
362
366
  * Generates a logger that can be passed to the MSAL clients.
363
- * @param logger - The logger of the credential.
367
+ * @param credLogger - The logger of the credential.
364
368
  * @internal
365
369
  */
366
- const defaultLoggerCallback = (logger, platform = coreUtil.isNode ? "Node" : "Browser") => (level, message, containsPii) => {
370
+ const defaultLoggerCallback = (credLogger, platform = coreUtil.isNode ? "Node" : "Browser") => (level, message, containsPii) => {
367
371
  if (containsPii) {
368
372
  return;
369
373
  }
370
374
  switch (level) {
371
375
  case msalCommon__namespace.LogLevel.Error:
372
- logger.info(`MSAL ${platform} V2 error: ${message}`);
376
+ credLogger.info(`MSAL ${platform} V2 error: ${message}`);
373
377
  return;
374
378
  case msalCommon__namespace.LogLevel.Info:
375
- logger.info(`MSAL ${platform} V2 info message: ${message}`);
379
+ credLogger.info(`MSAL ${platform} V2 info message: ${message}`);
376
380
  return;
377
381
  case msalCommon__namespace.LogLevel.Verbose:
378
- logger.info(`MSAL ${platform} V2 verbose message: ${message}`);
382
+ credLogger.info(`MSAL ${platform} V2 verbose message: ${message}`);
379
383
  return;
380
384
  case msalCommon__namespace.LogLevel.Warning:
381
- logger.info(`MSAL ${platform} V2 warning: ${message}`);
385
+ credLogger.info(`MSAL ${platform} V2 warning: ${message}`);
382
386
  return;
383
387
  }
384
388
  };
@@ -401,75 +405,39 @@ function getMSALLogLevel(logLevel) {
401
405
  }
402
406
  }
403
407
  /**
404
- * The common utility functions for the MSAL clients.
405
- * Defined as a class so that the classes extending this one can have access to its methods and protected properties.
406
- *
407
- * It keeps track of a logger and an in-memory copy of the AuthenticationRecord.
408
- *
409
- * @internal
408
+ * Handles MSAL errors.
410
409
  */
411
- class MsalBaseUtilities {
412
- constructor(options) {
413
- this.logger = options.logger;
414
- this.account = options.authenticationRecord;
415
- }
416
- /**
417
- * Generates a UUID
418
- */
419
- generateUuid() {
420
- return coreUtil.randomUUID();
421
- }
422
- /**
423
- * Handles the MSAL authentication result.
424
- * If the result has an account, we update the local account reference.
425
- * If the token received is invalid, an error will be thrown depending on what's missing.
426
- */
427
- handleResult(scopes, clientId, result, getTokenOptions) {
428
- if (result === null || result === void 0 ? void 0 : result.account) {
429
- this.account = msalToPublic(clientId, result.account);
410
+ function handleMsalError(scopes, error, getTokenOptions) {
411
+ if (error.name === "AuthError" ||
412
+ error.name === "ClientAuthError" ||
413
+ error.name === "BrowserAuthError") {
414
+ const msalError = error;
415
+ switch (msalError.errorCode) {
416
+ case "endpoints_resolution_error":
417
+ logger$n.info(formatError(scopes, error.message));
418
+ return new CredentialUnavailableError(error.message);
419
+ case "device_code_polling_cancelled":
420
+ return new abortController.AbortError("The authentication has been aborted by the caller.");
421
+ case "consent_required":
422
+ case "interaction_required":
423
+ case "login_required":
424
+ logger$n.info(formatError(scopes, `Authentication returned errorCode ${msalError.errorCode}`));
425
+ break;
426
+ default:
427
+ logger$n.info(formatError(scopes, `Failed to acquire token: ${error.message}`));
428
+ break;
430
429
  }
431
- ensureValidMsalToken(scopes, this.logger, result, getTokenOptions);
432
- this.logger.getToken.info(formatSuccess(scopes));
433
- return {
434
- token: result.accessToken,
435
- expiresOnTimestamp: result.expiresOn.getTime(),
436
- };
437
430
  }
438
- /**
439
- * Handles MSAL errors.
440
- */
441
- handleError(scopes, error, getTokenOptions) {
442
- if (error.name === "AuthError" ||
443
- error.name === "ClientAuthError" ||
444
- error.name === "BrowserAuthError") {
445
- const msalError = error;
446
- switch (msalError.errorCode) {
447
- case "endpoints_resolution_error":
448
- this.logger.info(formatError(scopes, error.message));
449
- return new CredentialUnavailableError(error.message);
450
- case "device_code_polling_cancelled":
451
- return new abortController.AbortError("The authentication has been aborted by the caller.");
452
- case "consent_required":
453
- case "interaction_required":
454
- case "login_required":
455
- this.logger.info(formatError(scopes, `Authentication returned errorCode ${msalError.errorCode}`));
456
- break;
457
- default:
458
- this.logger.info(formatError(scopes, `Failed to acquire token: ${error.message}`));
459
- break;
460
- }
461
- }
462
- if (error.name === "ClientConfigurationError" ||
463
- error.name === "BrowserConfigurationAuthError" ||
464
- error.name === "AbortError") {
465
- return error;
466
- }
467
- if (error.name === "NativeAuthError") {
468
- this.logger.info(formatError(scopes, `Error from the native broker: ${error.message} with status code: ${error.statusCode}`));
469
- return error;
470
- }
471
- return new AuthenticationRequiredError({ scopes, getTokenOptions, message: error.message });
431
+ if (error.name === "ClientConfigurationError" ||
432
+ error.name === "BrowserConfigurationAuthError" ||
433
+ error.name === "AbortError") {
434
+ return error;
435
+ }
436
+ if (error.name === "NativeAuthError") {
437
+ logger$n.info(formatError(scopes, `Error from the native broker: ${error.message} with status code: ${error.statusCode}`));
438
+ return error;
472
439
  }
440
+ return new AuthenticationRequiredError({ scopes, getTokenOptions, message: error.message });
473
441
  }
474
442
  // transformations.ts
475
443
  function publicToMsal(account) {
@@ -735,7 +703,7 @@ class IdentityClient extends coreClient.ServiceClient {
735
703
  this.tokenCredentialOptions = Object.assign({}, options);
736
704
  }
737
705
  async sendTokenRequest(request) {
738
- logger$n.info(`IdentityClient: sending token request to [${request.url}]`);
706
+ logger$o.info(`IdentityClient: sending token request to [${request.url}]`);
739
707
  const response = await this.sendRequest(request);
740
708
  if (response.bodyAsText && (response.status === 200 || response.status === 201)) {
741
709
  const parsedBody = JSON.parse(response.bodyAsText);
@@ -750,12 +718,12 @@ class IdentityClient extends coreClient.ServiceClient {
750
718
  },
751
719
  refreshToken: parsedBody.refresh_token,
752
720
  };
753
- logger$n.info(`IdentityClient: [${request.url}] token acquired, expires on ${token.accessToken.expiresOnTimestamp}`);
721
+ logger$o.info(`IdentityClient: [${request.url}] token acquired, expires on ${token.accessToken.expiresOnTimestamp}`);
754
722
  return token;
755
723
  }
756
724
  else {
757
725
  const error = new AuthenticationError(response.status, response.bodyAsText);
758
- logger$n.warning(`IdentityClient: authentication error. HTTP status: ${response.status}, ${error.errorResponse.errorDescription}`);
726
+ logger$o.warning(`IdentityClient: authentication error. HTTP status: ${response.status}, ${error.errorResponse.errorDescription}`);
759
727
  throw error;
760
728
  }
761
729
  }
@@ -763,7 +731,7 @@ class IdentityClient extends coreClient.ServiceClient {
763
731
  if (refreshToken === undefined) {
764
732
  return null;
765
733
  }
766
- logger$n.info(`IdentityClient: refreshing access token with client ID: ${clientId}, scopes: ${scopes} started`);
734
+ logger$o.info(`IdentityClient: refreshing access token with client ID: ${clientId}, scopes: ${scopes} started`);
767
735
  const refreshParams = {
768
736
  grant_type: "refresh_token",
769
737
  client_id: clientId,
@@ -789,7 +757,7 @@ class IdentityClient extends coreClient.ServiceClient {
789
757
  tracingOptions: updatedOptions.tracingOptions,
790
758
  });
791
759
  const response = await this.sendTokenRequest(request);
792
- logger$n.info(`IdentityClient: refreshed token for client ID: ${clientId}`);
760
+ logger$o.info(`IdentityClient: refreshed token for client ID: ${clientId}`);
793
761
  return response;
794
762
  }
795
763
  catch (err) {
@@ -798,11 +766,11 @@ class IdentityClient extends coreClient.ServiceClient {
798
766
  // It's likely that the refresh token has expired, so
799
767
  // return null so that the credential implementation will
800
768
  // initiate the authentication flow again.
801
- logger$n.info(`IdentityClient: interaction required for client ID: ${clientId}`);
769
+ logger$o.info(`IdentityClient: interaction required for client ID: ${clientId}`);
802
770
  return null;
803
771
  }
804
772
  else {
805
- logger$n.warning(`IdentityClient: failed refreshing token for client ID: ${clientId}: ${err}`);
773
+ logger$o.warning(`IdentityClient: failed refreshing token for client ID: ${clientId}: ${err}`);
806
774
  throw err;
807
775
  }
808
776
  }
@@ -911,10 +879,10 @@ class IdentityClient extends coreClient.ServiceClient {
911
879
  }
912
880
  const base64Metadata = accessToken.split(".")[1];
913
881
  const { appid, upn, tid, oid } = JSON.parse(Buffer.from(base64Metadata, "base64").toString("utf8"));
914
- logger$n.info(`[Authenticated account] Client ID: ${appid}. Tenant ID: ${tid}. User Principal Name: ${upn || unavailableUpn}. Object ID (user): ${oid}`);
882
+ logger$o.info(`[Authenticated account] Client ID: ${appid}. Tenant ID: ${tid}. User Principal Name: ${upn || unavailableUpn}. Object ID (user): ${oid}`);
915
883
  }
916
884
  catch (e) {
917
- logger$n.warning("allowLoggingAccountIdentifiers was set, but we couldn't log the account information. Error:", e.message);
885
+ logger$o.warning("allowLoggingAccountIdentifiers was set, but we couldn't log the account information. Error:", e.message);
918
886
  }
919
887
  }
920
888
  }
@@ -1078,13 +1046,13 @@ const msalNodeFlowNativeBrokerControl = {
1078
1046
  *
1079
1047
  * @internal
1080
1048
  */
1081
- class MsalNode extends MsalBaseUtilities {
1049
+ class MsalNode {
1082
1050
  constructor(options) {
1083
1051
  var _a, _b, _c, _d, _e, _f, _g;
1084
- super(options);
1085
1052
  this.app = {};
1086
1053
  this.caeApp = {};
1087
1054
  this.requiresConfidential = false;
1055
+ this.logger = options.logger;
1088
1056
  this.msalConfig = this.defaultNodeMsalConfig(options);
1089
1057
  this.tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
1090
1058
  this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds((_a = options === null || options === void 0 ? void 0 : options.tokenCredentialOptions) === null || _a === void 0 ? void 0 : _a.additionallyAllowedTenants);
@@ -1147,7 +1115,7 @@ class MsalNode extends MsalBaseUtilities {
1147
1115
  networkClient: this.identityClient,
1148
1116
  loggerOptions: {
1149
1117
  loggerCallback: defaultLoggerCallback(options.logger),
1150
- logLevel: getMSALLogLevel(logger$o.getLogLevel()),
1118
+ logLevel: getMSALLogLevel(logger$p.getLogLevel()),
1151
1119
  piiLoggingEnabled: (_a = options.loggingOptions) === null || _a === void 0 ? void 0 : _a.enableUnsafeSupportLogging,
1152
1120
  },
1153
1121
  },
@@ -1317,10 +1285,10 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1317
1285
  */
1318
1286
  await ((_a = this.getApp("publicFirst", options === null || options === void 0 ? void 0 : options.enableCae)) === null || _a === void 0 ? void 0 : _a.getTokenCache().getAllAccounts());
1319
1287
  const response = (_c = (await ((_b = this.getApp("confidential", options === null || options === void 0 ? void 0 : options.enableCae)) === null || _b === void 0 ? void 0 : _b.acquireTokenSilent(silentRequest)))) !== null && _c !== void 0 ? _c : (await this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).acquireTokenSilent(silentRequest));
1320
- return this.handleResult(scopes, this.clientId, response || undefined);
1288
+ return this.handleResult(scopes, response || undefined);
1321
1289
  }
1322
1290
  catch (err) {
1323
- throw this.handleError(scopes, err, options);
1291
+ throw handleMsalError(scopes, err, options);
1324
1292
  }
1325
1293
  }
1326
1294
  /**
@@ -1331,7 +1299,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1331
1299
  const tenantId = processMultiTenantRequest(this.tenantId, options, this.additionallyAllowedTenantIds) ||
1332
1300
  this.tenantId;
1333
1301
  options.authority = getAuthority(tenantId, this.authorityHost);
1334
- options.correlationId = (options === null || options === void 0 ? void 0 : options.correlationId) || this.generateUuid();
1302
+ options.correlationId = (options === null || options === void 0 ? void 0 : options.correlationId) || coreUtil.randomUUID();
1335
1303
  await this.init(options);
1336
1304
  try {
1337
1305
  // MSAL now caches tokens based on their claims,
@@ -1362,6 +1330,22 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1362
1330
  return this.doGetToken(scopes, options);
1363
1331
  }
1364
1332
  }
1333
+ /**
1334
+ * Handles the MSAL authentication result.
1335
+ * If the result has an account, we update the local account reference.
1336
+ * If the token received is invalid, an error will be thrown depending on what's missing.
1337
+ */
1338
+ handleResult(scopes, result, getTokenOptions) {
1339
+ if (result === null || result === void 0 ? void 0 : result.account) {
1340
+ this.account = msalToPublic(this.clientId, result.account);
1341
+ }
1342
+ ensureValidMsalToken(scopes, result, getTokenOptions);
1343
+ this.logger.getToken.info(formatSuccess(scopes));
1344
+ return {
1345
+ token: result.accessToken,
1346
+ expiresOnTimestamp: result.expiresOn.getTime(),
1347
+ };
1348
+ }
1365
1349
  }
1366
1350
 
1367
1351
  // Copyright (c) Microsoft Corporation.
@@ -2007,7 +1991,7 @@ class MsalClientAssertion extends MsalNode {
2007
1991
  });
2008
1992
  // The Client Credential flow does not return an account,
2009
1993
  // so each time getToken gets called, we will have to acquire a new token through the service.
2010
- return this.handleResult(scopes, this.clientId, result || undefined);
1994
+ return this.handleResult(scopes, result || undefined);
2011
1995
  }
2012
1996
  catch (err) {
2013
1997
  let err2 = err;
@@ -2017,7 +2001,7 @@ class MsalClientAssertion extends MsalNode {
2017
2001
  else {
2018
2002
  err2 = coreUtil.isError(err) ? err : new Error(String(err));
2019
2003
  }
2020
- throw this.handleError(scopes, err2, options);
2004
+ throw handleMsalError(scopes, err2, options);
2021
2005
  }
2022
2006
  }
2023
2007
  }
@@ -2405,7 +2389,7 @@ class ManagedIdentityCredential {
2405
2389
  },
2406
2390
  system: {
2407
2391
  loggerOptions: {
2408
- logLevel: getMSALLogLevel(logger$o.getLogLevel()),
2392
+ logLevel: getMSALLogLevel(logger$p.getLogLevel()),
2409
2393
  },
2410
2394
  },
2411
2395
  });
@@ -2783,13 +2767,9 @@ class AzureCliCredential {
2783
2767
  }
2784
2768
  try {
2785
2769
  const responseData = obj.stdout;
2786
- const response = JSON.parse(responseData);
2770
+ const response = this.parseRawResponse(responseData);
2787
2771
  logger$b.getToken.info(formatSuccess(scopes));
2788
- const returnValue = {
2789
- token: response.accessToken,
2790
- expiresOnTimestamp: new Date(response.expiresOn).getTime(),
2791
- };
2792
- return returnValue;
2772
+ return response;
2793
2773
  }
2794
2774
  catch (e) {
2795
2775
  if (obj.stderr) {
@@ -2807,6 +2787,40 @@ class AzureCliCredential {
2807
2787
  }
2808
2788
  });
2809
2789
  }
2790
+ /**
2791
+ * Parses the raw JSON response from the Azure CLI into a usable AccessToken object
2792
+ *
2793
+ * @param rawResponse - The raw JSON response from the Azure CLI
2794
+ * @returns An access token with the expiry time parsed from the raw response
2795
+ *
2796
+ * The expiryTime of the credential's access token, in milliseconds, is calculated as follows:
2797
+ *
2798
+ * When available, expires_on (introduced in Azure CLI v2.54.0) will be preferred. Otherwise falls back to expiresOn.
2799
+ */
2800
+ parseRawResponse(rawResponse) {
2801
+ const response = JSON.parse(rawResponse);
2802
+ const token = response.accessToken;
2803
+ // if available, expires_on will be a number representing seconds since epoch.
2804
+ // ensure it's a number or NaN
2805
+ let expiresOnTimestamp = Number.parseInt(response.expires_on, 10) * 1000;
2806
+ if (!isNaN(expiresOnTimestamp)) {
2807
+ logger$b.getToken.info("expires_on is available and is valid, using it");
2808
+ return {
2809
+ token,
2810
+ expiresOnTimestamp,
2811
+ };
2812
+ }
2813
+ // fallback to the older expiresOn - an RFC3339 date string
2814
+ expiresOnTimestamp = new Date(response.expiresOn).getTime();
2815
+ // ensure expiresOn is well-formatted
2816
+ if (isNaN(expiresOnTimestamp)) {
2817
+ throw new CredentialUnavailableError(`Unexpected response from Azure CLI when getting token. Expected "expiresOn" to be a RFC3339 date string. Got: "${response.expiresOn}"`);
2818
+ }
2819
+ return {
2820
+ token,
2821
+ expiresOnTimestamp,
2822
+ };
2823
+ }
2810
2824
  }
2811
2825
 
2812
2826
  // Copyright (c) Microsoft Corporation.
@@ -3195,10 +3209,10 @@ class MsalClientCertificate extends MsalNode {
3195
3209
  // Even though we're providing the same default in memory persistence cache that we use for DeviceCodeCredential,
3196
3210
  // The Client Credential flow does not return the account information from the authentication service,
3197
3211
  // so each time getToken gets called, we will have to acquire a new token through the service.
3198
- return this.handleResult(scopes, this.clientId, result || undefined);
3212
+ return this.handleResult(scopes, result || undefined);
3199
3213
  }
3200
3214
  catch (err) {
3201
- throw this.handleError(scopes, err, options);
3215
+ throw handleMsalError(scopes, err, options);
3202
3216
  }
3203
3217
  }
3204
3218
  }
@@ -3281,10 +3295,10 @@ class MsalClientSecret extends MsalNode {
3281
3295
  });
3282
3296
  // The Client Credential flow does not return an account,
3283
3297
  // so each time getToken gets called, we will have to acquire a new token through the service.
3284
- return this.handleResult(scopes, this.clientId, result || undefined);
3298
+ return this.handleResult(scopes, result || undefined);
3285
3299
  }
3286
3300
  catch (err) {
3287
- throw this.handleError(scopes, err, options);
3301
+ throw handleMsalError(scopes, err, options);
3288
3302
  }
3289
3303
  }
3290
3304
  }
@@ -3362,10 +3376,10 @@ class MsalUsernamePassword extends MsalNode {
3362
3376
  claims: options === null || options === void 0 ? void 0 : options.claims,
3363
3377
  };
3364
3378
  const result = await this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).acquireTokenByUsernamePassword(requestOptions);
3365
- return this.handleResult(scopes, this.clientId, result || undefined);
3379
+ return this.handleResult(scopes, result || undefined);
3366
3380
  }
3367
3381
  catch (error) {
3368
- throw this.handleError(scopes, error, options);
3382
+ throw handleMsalError(scopes, error, options);
3369
3383
  }
3370
3384
  }
3371
3385
  }
@@ -3857,10 +3871,10 @@ class MsalOpenBrowser extends MsalNode {
3857
3871
  if (result.fromNativeBroker) {
3858
3872
  this.logger.verbose(`This result is returned from native broker`);
3859
3873
  }
3860
- return this.handleResult(scopes, this.clientId, result || undefined);
3874
+ return this.handleResult(scopes, result || undefined);
3861
3875
  }
3862
3876
  catch (err) {
3863
- throw this.handleError(scopes, err, options);
3877
+ throw handleMsalError(scopes, err, options);
3864
3878
  }
3865
3879
  }
3866
3880
  }
@@ -3978,10 +3992,10 @@ class MsalDeviceCode extends MsalNode {
3978
3992
  const deviceResponse = await this.withCancellation(promise, options === null || options === void 0 ? void 0 : options.abortSignal, () => {
3979
3993
  requestOptions.cancel = true;
3980
3994
  });
3981
- return this.handleResult(scopes, this.clientId, deviceResponse || undefined);
3995
+ return this.handleResult(scopes, deviceResponse || undefined);
3982
3996
  }
3983
3997
  catch (error) {
3984
- throw this.handleError(scopes, error, options);
3998
+ throw handleMsalError(scopes, error, options);
3985
3999
  }
3986
4000
  }
3987
4001
  }
@@ -4101,10 +4115,10 @@ class MsalAuthorizationCode extends MsalNode {
4101
4115
  });
4102
4116
  // The Client Credential flow does not return an account,
4103
4117
  // so each time getToken gets called, we will have to acquire a new token through the service.
4104
- return this.handleResult(scopes, this.clientId, result || undefined);
4118
+ return this.handleResult(scopes, result || undefined);
4105
4119
  }
4106
4120
  catch (err) {
4107
- throw this.handleError(scopes, err, options);
4121
+ throw handleMsalError(scopes, err, options);
4108
4122
  }
4109
4123
  }
4110
4124
  }
@@ -4211,10 +4225,10 @@ class MsalOnBehalfOf extends MsalNode {
4211
4225
  claims: options.claims,
4212
4226
  oboAssertion: this.userAssertionToken,
4213
4227
  });
4214
- return this.handleResult(scopes, this.clientId, result || undefined);
4228
+ return this.handleResult(scopes, result || undefined);
4215
4229
  }
4216
4230
  catch (err) {
4217
- throw this.handleError(scopes, err, options);
4231
+ throw handleMsalError(scopes, err, options);
4218
4232
  }
4219
4233
  }
4220
4234
  }
@@ -4290,7 +4304,7 @@ exports.VisualStudioCodeCredential = VisualStudioCodeCredential;
4290
4304
  exports.WorkloadIdentityCredential = WorkloadIdentityCredential;
4291
4305
  exports.deserializeAuthenticationRecord = deserializeAuthenticationRecord;
4292
4306
  exports.getDefaultAzureCredential = getDefaultAzureCredential;
4293
- exports.logger = logger$n;
4307
+ exports.logger = logger$o;
4294
4308
  exports.serializeAuthenticationRecord = serializeAuthenticationRecord;
4295
4309
  exports.useIdentityPlugin = useIdentityPlugin;
4296
4310
  //# sourceMappingURL=index.js.map