@azure/identity 4.5.0-beta.2 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. package/README.md +65 -74
  2. package/dist/index.js +190 -81
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/src/client/identityClient.js +4 -2
  5. package/dist-esm/src/client/identityClient.js.map +1 -1
  6. package/dist-esm/src/constants.js +2 -2
  7. package/dist-esm/src/constants.js.map +1 -1
  8. package/dist-esm/src/credentials/authorityValidationOptions.js +1 -1
  9. package/dist-esm/src/credentials/authorityValidationOptions.js.map +1 -1
  10. package/dist-esm/src/credentials/authorizationCodeCredential.browser.js +1 -1
  11. package/dist-esm/src/credentials/authorizationCodeCredential.browser.js.map +1 -1
  12. package/dist-esm/src/credentials/authorizationCodeCredential.js +1 -1
  13. package/dist-esm/src/credentials/authorizationCodeCredential.js.map +1 -1
  14. package/dist-esm/src/credentials/authorizationCodeCredentialOptions.js +1 -1
  15. package/dist-esm/src/credentials/authorizationCodeCredentialOptions.js.map +1 -1
  16. package/dist-esm/src/credentials/azureApplicationCredential.browser.js +1 -1
  17. package/dist-esm/src/credentials/azureApplicationCredential.browser.js.map +1 -1
  18. package/dist-esm/src/credentials/azureApplicationCredential.js +1 -1
  19. package/dist-esm/src/credentials/azureApplicationCredential.js.map +1 -1
  20. package/dist-esm/src/credentials/azureApplicationCredentialOptions.js +1 -1
  21. package/dist-esm/src/credentials/azureApplicationCredentialOptions.js.map +1 -1
  22. package/dist-esm/src/credentials/azureCliCredential.browser.js +1 -1
  23. package/dist-esm/src/credentials/azureCliCredential.browser.js.map +1 -1
  24. package/dist-esm/src/credentials/azureCliCredential.js +3 -1
  25. package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
  26. package/dist-esm/src/credentials/azureCliCredentialOptions.js +1 -1
  27. package/dist-esm/src/credentials/azureCliCredentialOptions.js.map +1 -1
  28. package/dist-esm/src/credentials/azureDeveloperCliCredential.browser.js +1 -1
  29. package/dist-esm/src/credentials/azureDeveloperCliCredential.browser.js.map +1 -1
  30. package/dist-esm/src/credentials/azureDeveloperCliCredential.js +2 -1
  31. package/dist-esm/src/credentials/azureDeveloperCliCredential.js.map +1 -1
  32. package/dist-esm/src/credentials/azureDeveloperCliCredentialOptions.js +1 -1
  33. package/dist-esm/src/credentials/azureDeveloperCliCredentialOptions.js.map +1 -1
  34. package/dist-esm/src/credentials/azurePipelinesCredential.browser.js +1 -1
  35. package/dist-esm/src/credentials/azurePipelinesCredential.browser.js.map +1 -1
  36. package/dist-esm/src/credentials/azurePipelinesCredential.js +16 -5
  37. package/dist-esm/src/credentials/azurePipelinesCredential.js.map +1 -1
  38. package/dist-esm/src/credentials/azurePipelinesCredentialOptions.js +1 -1
  39. package/dist-esm/src/credentials/azurePipelinesCredentialOptions.js.map +1 -1
  40. package/dist-esm/src/credentials/azurePowerShellCredential.browser.js +1 -1
  41. package/dist-esm/src/credentials/azurePowerShellCredential.browser.js.map +1 -1
  42. package/dist-esm/src/credentials/azurePowerShellCredential.js +2 -1
  43. package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
  44. package/dist-esm/src/credentials/azurePowerShellCredentialOptions.js +1 -1
  45. package/dist-esm/src/credentials/azurePowerShellCredentialOptions.js.map +1 -1
  46. package/dist-esm/src/credentials/brokerAuthOptions.js.map +1 -1
  47. package/dist-esm/src/credentials/browserCustomizationOptions.js +1 -1
  48. package/dist-esm/src/credentials/browserCustomizationOptions.js.map +1 -1
  49. package/dist-esm/src/credentials/chainedTokenCredential.js +9 -2
  50. package/dist-esm/src/credentials/chainedTokenCredential.js.map +1 -1
  51. package/dist-esm/src/credentials/clientAssertionCredential.browser.js +1 -1
  52. package/dist-esm/src/credentials/clientAssertionCredential.browser.js.map +1 -1
  53. package/dist-esm/src/credentials/clientAssertionCredential.js +1 -1
  54. package/dist-esm/src/credentials/clientAssertionCredential.js.map +1 -1
  55. package/dist-esm/src/credentials/clientAssertionCredentialOptions.js +1 -1
  56. package/dist-esm/src/credentials/clientAssertionCredentialOptions.js.map +1 -1
  57. package/dist-esm/src/credentials/clientCertificateCredential.browser.js +1 -1
  58. package/dist-esm/src/credentials/clientCertificateCredential.browser.js.map +1 -1
  59. package/dist-esm/src/credentials/clientCertificateCredential.js +1 -1
  60. package/dist-esm/src/credentials/clientCertificateCredential.js.map +1 -1
  61. package/dist-esm/src/credentials/clientCertificateCredentialOptions.js +1 -1
  62. package/dist-esm/src/credentials/clientCertificateCredentialOptions.js.map +1 -1
  63. package/dist-esm/src/credentials/clientSecretCredential.browser.js +1 -1
  64. package/dist-esm/src/credentials/clientSecretCredential.browser.js.map +1 -1
  65. package/dist-esm/src/credentials/clientSecretCredential.js +1 -1
  66. package/dist-esm/src/credentials/clientSecretCredential.js.map +1 -1
  67. package/dist-esm/src/credentials/clientSecretCredentialOptions.js +1 -1
  68. package/dist-esm/src/credentials/clientSecretCredentialOptions.js.map +1 -1
  69. package/dist-esm/src/credentials/credentialPersistenceOptions.js +1 -1
  70. package/dist-esm/src/credentials/credentialPersistenceOptions.js.map +1 -1
  71. package/dist-esm/src/credentials/defaultAzureCredential.browser.js +1 -1
  72. package/dist-esm/src/credentials/defaultAzureCredential.browser.js.map +1 -1
  73. package/dist-esm/src/credentials/defaultAzureCredential.js +1 -1
  74. package/dist-esm/src/credentials/defaultAzureCredential.js.map +1 -1
  75. package/dist-esm/src/credentials/defaultAzureCredentialOptions.js +1 -1
  76. package/dist-esm/src/credentials/defaultAzureCredentialOptions.js.map +1 -1
  77. package/dist-esm/src/credentials/deviceCodeCredential.browser.js +1 -1
  78. package/dist-esm/src/credentials/deviceCodeCredential.browser.js.map +1 -1
  79. package/dist-esm/src/credentials/deviceCodeCredential.js +7 -5
  80. package/dist-esm/src/credentials/deviceCodeCredential.js.map +1 -1
  81. package/dist-esm/src/credentials/deviceCodeCredentialOptions.js +1 -1
  82. package/dist-esm/src/credentials/deviceCodeCredentialOptions.js.map +1 -1
  83. package/dist-esm/src/credentials/environmentCredential.browser.js +1 -1
  84. package/dist-esm/src/credentials/environmentCredential.browser.js.map +1 -1
  85. package/dist-esm/src/credentials/environmentCredential.js +1 -1
  86. package/dist-esm/src/credentials/environmentCredential.js.map +1 -1
  87. package/dist-esm/src/credentials/environmentCredentialOptions.js +1 -1
  88. package/dist-esm/src/credentials/environmentCredentialOptions.js.map +1 -1
  89. package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js +1 -1
  90. package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js.map +1 -1
  91. package/dist-esm/src/credentials/interactiveBrowserCredential.js +1 -1
  92. package/dist-esm/src/credentials/interactiveBrowserCredential.js.map +1 -1
  93. package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js +1 -1
  94. package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js.map +1 -1
  95. package/dist-esm/src/credentials/interactiveCredentialOptions.js +1 -1
  96. package/dist-esm/src/credentials/interactiveCredentialOptions.js.map +1 -1
  97. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js +1 -1
  98. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js.map +1 -1
  99. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js +1 -1
  100. package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js.map +1 -1
  101. package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js +1 -1
  102. package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js.map +1 -1
  103. package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js +1 -1
  104. package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js.map +1 -1
  105. package/dist-esm/src/credentials/managedIdentityCredential/constants.js +1 -1
  106. package/dist-esm/src/credentials/managedIdentityCredential/constants.js.map +1 -1
  107. package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js +1 -1
  108. package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js.map +1 -1
  109. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +1 -1
  110. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  111. package/dist-esm/src/credentials/managedIdentityCredential/imdsRetryPolicy.js +6 -10
  112. package/dist-esm/src/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
  113. package/dist-esm/src/credentials/managedIdentityCredential/index.browser.js +1 -1
  114. package/dist-esm/src/credentials/managedIdentityCredential/index.browser.js.map +1 -1
  115. package/dist-esm/src/credentials/managedIdentityCredential/index.js +1 -1
  116. package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
  117. package/dist-esm/src/credentials/managedIdentityCredential/legacyMsiProvider.js +8 -1
  118. package/dist-esm/src/credentials/managedIdentityCredential/legacyMsiProvider.js.map +1 -1
  119. package/dist-esm/src/credentials/managedIdentityCredential/models.js +1 -1
  120. package/dist-esm/src/credentials/managedIdentityCredential/models.js.map +1 -1
  121. package/dist-esm/src/credentials/managedIdentityCredential/msalMsiProvider.js +21 -4
  122. package/dist-esm/src/credentials/managedIdentityCredential/msalMsiProvider.js.map +1 -1
  123. package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js +1 -1
  124. package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  125. package/dist-esm/src/credentials/managedIdentityCredential/utils.js +26 -1
  126. package/dist-esm/src/credentials/managedIdentityCredential/utils.js.map +1 -1
  127. package/dist-esm/src/credentials/multiTenantTokenCredentialOptions.js +1 -1
  128. package/dist-esm/src/credentials/multiTenantTokenCredentialOptions.js.map +1 -1
  129. package/dist-esm/src/credentials/onBehalfOfCredential.browser.js +1 -1
  130. package/dist-esm/src/credentials/onBehalfOfCredential.browser.js.map +1 -1
  131. package/dist-esm/src/credentials/onBehalfOfCredential.js +1 -1
  132. package/dist-esm/src/credentials/onBehalfOfCredential.js.map +1 -1
  133. package/dist-esm/src/credentials/onBehalfOfCredentialOptions.js +1 -1
  134. package/dist-esm/src/credentials/onBehalfOfCredentialOptions.js.map +1 -1
  135. package/dist-esm/src/credentials/usernamePasswordCredential.browser.js +1 -1
  136. package/dist-esm/src/credentials/usernamePasswordCredential.browser.js.map +1 -1
  137. package/dist-esm/src/credentials/usernamePasswordCredential.js +1 -1
  138. package/dist-esm/src/credentials/usernamePasswordCredential.js.map +1 -1
  139. package/dist-esm/src/credentials/usernamePasswordCredentialOptions.js +1 -1
  140. package/dist-esm/src/credentials/usernamePasswordCredentialOptions.js.map +1 -1
  141. package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js +1 -1
  142. package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js.map +1 -1
  143. package/dist-esm/src/credentials/visualStudioCodeCredential.js +1 -1
  144. package/dist-esm/src/credentials/visualStudioCodeCredential.js.map +1 -1
  145. package/dist-esm/src/credentials/visualStudioCodeCredentialOptions.js +1 -1
  146. package/dist-esm/src/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
  147. package/dist-esm/src/credentials/visualStudioCodeCredentialPlugin.js +1 -1
  148. package/dist-esm/src/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
  149. package/dist-esm/src/credentials/workloadIdentityCredential.browser.js +1 -1
  150. package/dist-esm/src/credentials/workloadIdentityCredential.browser.js.map +1 -1
  151. package/dist-esm/src/credentials/workloadIdentityCredential.js +1 -1
  152. package/dist-esm/src/credentials/workloadIdentityCredential.js.map +1 -1
  153. package/dist-esm/src/credentials/workloadIdentityCredentialOptions.js +1 -1
  154. package/dist-esm/src/credentials/workloadIdentityCredentialOptions.js.map +1 -1
  155. package/dist-esm/src/errors.js +1 -2
  156. package/dist-esm/src/errors.js.map +1 -1
  157. package/dist-esm/src/index.js +1 -1
  158. package/dist-esm/src/index.js.map +1 -1
  159. package/dist-esm/src/msal/browserFlows/flows.js +1 -1
  160. package/dist-esm/src/msal/browserFlows/flows.js.map +1 -1
  161. package/dist-esm/src/msal/browserFlows/msalAuthCode.js +2 -2
  162. package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
  163. package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js +4 -1
  164. package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  165. package/dist-esm/src/msal/credentials.js +1 -1
  166. package/dist-esm/src/msal/credentials.js.map +1 -1
  167. package/dist-esm/src/msal/msal.browser.js +1 -1
  168. package/dist-esm/src/msal/msal.browser.js.map +1 -1
  169. package/dist-esm/src/msal/msal.js +1 -1
  170. package/dist-esm/src/msal/msal.js.map +1 -1
  171. package/dist-esm/src/msal/nodeFlows/brokerOptions.js.map +1 -1
  172. package/dist-esm/src/msal/nodeFlows/msalClient.js +42 -8
  173. package/dist-esm/src/msal/nodeFlows/msalClient.js.map +1 -1
  174. package/dist-esm/src/msal/nodeFlows/msalPlugins.js +1 -1
  175. package/dist-esm/src/msal/nodeFlows/msalPlugins.js.map +1 -1
  176. package/dist-esm/src/msal/nodeFlows/tokenCachePersistenceOptions.js +1 -1
  177. package/dist-esm/src/msal/nodeFlows/tokenCachePersistenceOptions.js.map +1 -1
  178. package/dist-esm/src/msal/types.js +1 -1
  179. package/dist-esm/src/msal/types.js.map +1 -1
  180. package/dist-esm/src/msal/utils.js +17 -3
  181. package/dist-esm/src/msal/utils.js.map +1 -1
  182. package/dist-esm/src/plugins/consumer.browser.js +1 -1
  183. package/dist-esm/src/plugins/consumer.browser.js.map +1 -1
  184. package/dist-esm/src/plugins/consumer.js +7 -9
  185. package/dist-esm/src/plugins/consumer.js.map +1 -1
  186. package/dist-esm/src/plugins/provider.js +1 -1
  187. package/dist-esm/src/plugins/provider.js.map +1 -1
  188. package/dist-esm/src/regionalAuthority.js +1 -1
  189. package/dist-esm/src/regionalAuthority.js.map +1 -1
  190. package/dist-esm/src/tokenCredentialOptions.js +1 -1
  191. package/dist-esm/src/tokenCredentialOptions.js.map +1 -1
  192. package/dist-esm/src/tokenProvider.js +4 -4
  193. package/dist-esm/src/tokenProvider.js.map +1 -1
  194. package/dist-esm/src/util/authHostEnv.browser.js +1 -1
  195. package/dist-esm/src/util/authHostEnv.browser.js.map +1 -1
  196. package/dist-esm/src/util/identityTokenEndpoint.js +1 -1
  197. package/dist-esm/src/util/identityTokenEndpoint.js.map +1 -1
  198. package/dist-esm/src/util/logging.js +1 -1
  199. package/dist-esm/src/util/logging.js.map +1 -1
  200. package/dist-esm/src/util/processMultiTenantRequest.browser.js +1 -1
  201. package/dist-esm/src/util/processMultiTenantRequest.browser.js.map +1 -1
  202. package/dist-esm/src/util/processMultiTenantRequest.js +1 -1
  203. package/dist-esm/src/util/processMultiTenantRequest.js.map +1 -1
  204. package/dist-esm/src/util/processUtils.js +1 -1
  205. package/dist-esm/src/util/processUtils.js.map +1 -1
  206. package/dist-esm/src/util/scopeUtils.js +1 -1
  207. package/dist-esm/src/util/scopeUtils.js.map +1 -1
  208. package/dist-esm/src/util/tenantIdUtils.js +1 -1
  209. package/dist-esm/src/util/tenantIdUtils.js.map +1 -1
  210. package/dist-esm/src/util/tracing.js +1 -1
  211. package/dist-esm/src/util/tracing.js.map +1 -1
  212. package/package.json +20 -19
  213. package/types/identity.d.ts +74 -50
package/dist/index.js CHANGED
@@ -40,11 +40,11 @@ var msalCommon__namespace = /*#__PURE__*/_interopNamespaceDefault(msalCommon);
40
40
  var child_process__namespace = /*#__PURE__*/_interopNamespaceDefault(child_process);
41
41
 
42
42
  // Copyright (c) Microsoft Corporation.
43
- // Licensed under the MIT license.
43
+ // Licensed under the MIT License.
44
44
  /**
45
45
  * Current version of the `@azure/identity` package.
46
46
  */
47
- const SDK_VERSION = `4.5.0-beta.2`;
47
+ const SDK_VERSION = `4.5.0`;
48
48
  /**
49
49
  * The default client ID for authentication
50
50
  * @internal
@@ -107,7 +107,7 @@ const CACHE_NON_CAE_SUFFIX = "nocae";
107
107
  const DEFAULT_TOKEN_CACHE_NAME = "msal.cache";
108
108
 
109
109
  // Copyright (c) Microsoft Corporation.
110
- // Licensed under the MIT license.
110
+ // Licensed under the MIT License.
111
111
  /**
112
112
  * The current persistence provider, undefined by default.
113
113
  * @internal
@@ -190,7 +190,7 @@ const msalPlugins = {
190
190
  };
191
191
 
192
192
  // Copyright (c) Microsoft Corporation.
193
- // Licensed under the MIT license.
193
+ // Licensed under the MIT License.
194
194
  /**
195
195
  * The AzureLogger used for all clients within the identity package
196
196
  */
@@ -273,7 +273,7 @@ function credentialLogger(title, log = logger$l) {
273
273
  }
274
274
 
275
275
  // Copyright (c) Microsoft Corporation.
276
- // Licensed under the MIT license.
276
+ // Licensed under the MIT License.
277
277
  function isErrorResponse(errorResponse) {
278
278
  return (errorResponse &&
279
279
  typeof errorResponse.error === "string" &&
@@ -305,7 +305,6 @@ const AuthenticationErrorName = "AuthenticationError";
305
305
  * the specific failure.
306
306
  */
307
307
  class AuthenticationError extends Error {
308
- // eslint-disable-next-line @typescript-eslint/ban-types
309
308
  constructor(statusCode, errorBody, options) {
310
309
  let errorResponse = {
311
310
  error: "unknown",
@@ -397,7 +396,7 @@ class AuthenticationRequiredError extends Error {
397
396
  }
398
397
 
399
398
  // Copyright (c) Microsoft Corporation.
400
- // Licensed under the MIT license.
399
+ // Licensed under the MIT License.
401
400
  function createConfigurationErrorMessage(tenantId) {
402
401
  return `The current credential is not configured to acquire tokens for tenant ${tenantId}. To enable acquiring tokens for this tenant add it to the AdditionallyAllowedTenants on the credential options, or add "*" to AdditionallyAllowedTenants to allow acquiring tokens for any tenant.`;
403
402
  }
@@ -431,7 +430,7 @@ function processMultiTenantRequest(tenantId, getTokenOptions, additionallyAllowe
431
430
  }
432
431
 
433
432
  // Copyright (c) Microsoft Corporation.
434
- // Licensed under the MIT license.
433
+ // Licensed under the MIT License.
435
434
  /**
436
435
  * @internal
437
436
  */
@@ -472,7 +471,7 @@ function resolveAdditionallyAllowedTenantIds(additionallyAllowedTenants) {
472
471
  }
473
472
 
474
473
  // Copyright (c) Microsoft Corporation.
475
- // Licensed under the MIT license.
474
+ // Licensed under the MIT License.
476
475
  function getIdentityTokenEndpointSuffix(tenantId) {
477
476
  if (tenantId === "adfs") {
478
477
  return "oauth2/token";
@@ -483,7 +482,7 @@ function getIdentityTokenEndpointSuffix(tenantId) {
483
482
  }
484
483
 
485
484
  // Copyright (c) Microsoft Corporation.
486
- // Licensed under the MIT license.
485
+ // Licensed under the MIT License.
487
486
  /**
488
487
  * Creates a span using the global tracer.
489
488
  * @internal
@@ -495,14 +494,14 @@ const tracingClient = coreTracing.createTracingClient({
495
494
  });
496
495
 
497
496
  // Copyright (c) Microsoft Corporation.
498
- // Licensed under the MIT license.
497
+ // Licensed under the MIT License.
499
498
  const DefaultScopeSuffix = "/.default";
500
499
  const imdsHost = "http://169.254.169.254";
501
500
  const imdsEndpointPath = "/metadata/identity/oauth2/token";
502
501
  const imdsApiVersion = "2018-02-01";
503
502
 
504
503
  // Copyright (c) Microsoft Corporation.
505
- // Licensed under the MIT license.
504
+ // Licensed under the MIT License.
506
505
  /**
507
506
  * Most MSIs send requests to the IMDS endpoint, or a similar endpoint.
508
507
  * These are GET requests that require sending a `resource` parameter on the query.
@@ -551,9 +550,34 @@ function parseExpirationTimestamp(body) {
551
550
  }
552
551
  throw new Error(`Failed to parse token expiration from body. expires_in="${body.expires_in}", expires_on="${body.expires_on}"`);
553
552
  }
553
+ /**
554
+ * Given a token response, return the expiration timestamp as the number of milliseconds from the Unix epoch.
555
+ * @param body - A parsed response body from the authentication endpoint.
556
+ */
557
+ function parseRefreshTimestamp(body) {
558
+ if (body.refresh_on) {
559
+ if (typeof body.refresh_on === "number") {
560
+ return body.refresh_on * 1000;
561
+ }
562
+ if (typeof body.refresh_on === "string") {
563
+ const asNumber = +body.refresh_on;
564
+ if (!isNaN(asNumber)) {
565
+ return asNumber * 1000;
566
+ }
567
+ const asDate = Date.parse(body.refresh_on);
568
+ if (!isNaN(asDate)) {
569
+ return asDate;
570
+ }
571
+ }
572
+ throw new Error(`Failed to parse refresh_on from body. refresh_on="${body.refresh_on}"`);
573
+ }
574
+ else {
575
+ return undefined;
576
+ }
577
+ }
554
578
 
555
579
  // Copyright (c) Microsoft Corporation.
556
- // Licensed under the MIT license.
580
+ // Licensed under the MIT License.
557
581
  const noCorrelationId = "noCorrelationId";
558
582
  /**
559
583
  * @internal
@@ -615,6 +639,8 @@ class IdentityClient extends coreClient.ServiceClient {
615
639
  accessToken: {
616
640
  token: parsedBody.access_token,
617
641
  expiresOnTimestamp: parseExpirationTimestamp(parsedBody),
642
+ refreshAfterTimestamp: parseRefreshTimestamp(parsedBody),
643
+ tokenType: "Bearer",
618
644
  },
619
645
  refreshToken: parsedBody.refresh_token,
620
646
  };
@@ -790,7 +816,7 @@ class IdentityClient extends coreClient.ServiceClient {
790
816
  }
791
817
 
792
818
  // Copyright (c) Microsoft Corporation.
793
- // Licensed under the MIT license.
819
+ // Licensed under the MIT License.
794
820
  const CommonTenantId = "common";
795
821
  const AzureAccountClientId = "aebc6443-996d-45c2-90f0-388ff96faa56"; // VSC: 'aebc6443-996d-45c2-90f0-388ff96faa56'
796
822
  const logger$k = credentialLogger("VisualStudioCodeCredential");
@@ -971,7 +997,7 @@ class VisualStudioCodeCredential {
971
997
  }
972
998
 
973
999
  // Copyright (c) Microsoft Corporation.
974
- // Licensed under the MIT license.
1000
+ // Licensed under the MIT License.
975
1001
  /**
976
1002
  * The context passed to an Identity plugin. This contains objects that
977
1003
  * plugins can use to set backend implementations.
@@ -992,18 +1018,16 @@ const pluginContext = {
992
1018
  *
993
1019
  * Example:
994
1020
  *
995
- * ```javascript
996
- * import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
1021
+ * ```ts snippet:consumer_example
1022
+ * import { useIdentityPlugin, DeviceCodeCredential } from "@azure/identity";
997
1023
  *
998
- * import { useIdentityPlugin, DefaultAzureCredential } from "@azure/identity";
999
1024
  * useIdentityPlugin(cachePersistencePlugin);
1000
- *
1001
- * // The plugin has the capability to extend `DefaultAzureCredential` and to
1025
+ * // The plugin has the capability to extend `DeviceCodeCredential` and to
1002
1026
  * // add middleware to the underlying credentials, such as persistence.
1003
- * const credential = new DefaultAzureCredential({
1027
+ * const credential = new DeviceCodeCredential({
1004
1028
  * tokenCachePersistenceOptions: {
1005
- * enabled: true
1006
- * }
1029
+ * enabled: true,
1030
+ * },
1007
1031
  * });
1008
1032
  * ```
1009
1033
  *
@@ -1014,7 +1038,7 @@ function useIdentityPlugin(plugin) {
1014
1038
  }
1015
1039
 
1016
1040
  // Copyright (c) Microsoft Corporation.
1017
- // Licensed under the MIT license.
1041
+ // Licensed under the MIT License.
1018
1042
  /**
1019
1043
  * @internal
1020
1044
  */
@@ -1047,6 +1071,19 @@ function ensureValidMsalToken(scopes, msalToken, getTokenOptions) {
1047
1071
  throw error(`Response had no "accessToken" property.`);
1048
1072
  }
1049
1073
  }
1074
+ /**
1075
+ * Returns the authority host from either the options bag or the AZURE_AUTHORITY_HOST environment variable.
1076
+ *
1077
+ * Defaults to {@link DefaultAuthorityHost}.
1078
+ * @internal
1079
+ */
1080
+ function getAuthorityHost(options) {
1081
+ let authorityHost = options === null || options === void 0 ? void 0 : options.authorityHost;
1082
+ if (!authorityHost && coreUtil.isNodeLike) {
1083
+ authorityHost = process.env.AZURE_AUTHORITY_HOST;
1084
+ }
1085
+ return authorityHost !== null && authorityHost !== void 0 ? authorityHost : DefaultAuthorityHost;
1086
+ }
1050
1087
  /**
1051
1088
  * Generates a valid authority by combining a host with a tenantId.
1052
1089
  * @internal
@@ -1146,7 +1183,8 @@ function handleMsalError(scopes, error, getTokenOptions) {
1146
1183
  }
1147
1184
  if (error.name === "ClientConfigurationError" ||
1148
1185
  error.name === "BrowserConfigurationAuthError" ||
1149
- error.name === "AbortError") {
1186
+ error.name === "AbortError" ||
1187
+ error.name === "AuthenticationError") {
1150
1188
  return error;
1151
1189
  }
1152
1190
  if (error.name === "NativeAuthError") {
@@ -1216,7 +1254,7 @@ function deserializeAuthenticationRecord(serializedRecord) {
1216
1254
  }
1217
1255
 
1218
1256
  // Copyright (c) Microsoft Corporation.
1219
- // Licensed under the MIT license.
1257
+ // Licensed under the MIT License.
1220
1258
  const msiName$1 = "ManagedIdentityCredential - IMDS";
1221
1259
  const logger$i = credentialLogger(msiName$1);
1222
1260
  /**
@@ -1353,7 +1391,7 @@ const imdsMsi = {
1353
1391
  };
1354
1392
 
1355
1393
  // Copyright (c) Microsoft Corporation.
1356
- // Licensed under the MIT license.
1394
+ // Licensed under the MIT License.
1357
1395
  // Matches the default retry configuration in expontentialRetryStrategy.ts
1358
1396
  const DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 64;
1359
1397
  /**
@@ -1372,14 +1410,10 @@ function imdsRetryPolicy(msiRetryConfig) {
1372
1410
  if ((response === null || response === void 0 ? void 0 : response.status) !== 404) {
1373
1411
  return { skipStrategy: true };
1374
1412
  }
1375
- // Exponentially increase the delay each time
1376
- const exponentialDelay = msiRetryConfig.startDelayInMs * Math.pow(2, retryCount);
1377
- // Don't let the delay exceed the maximum
1378
- const clampedExponentialDelay = Math.min(DEFAULT_CLIENT_MAX_RETRY_INTERVAL, exponentialDelay);
1379
- // Allow the final value to have some "jitter" (within 50% of the delay size) so
1380
- // that retries across multiple clients don't occur simultaneously.
1381
- const retryAfterInMs = clampedExponentialDelay / 2 + coreUtil.getRandomIntegerInclusive(0, clampedExponentialDelay / 2);
1382
- return { retryAfterInMs };
1413
+ return coreUtil.calculateRetryDelay(retryCount, {
1414
+ retryDelayInMs: msiRetryConfig.startDelayInMs,
1415
+ maxRetryDelayInMs: DEFAULT_CLIENT_MAX_RETRY_INTERVAL,
1416
+ });
1383
1417
  },
1384
1418
  },
1385
1419
  ], {
@@ -1388,7 +1422,7 @@ function imdsRetryPolicy(msiRetryConfig) {
1388
1422
  }
1389
1423
 
1390
1424
  // Copyright (c) Microsoft Corporation.
1391
- // Licensed under the MIT license.
1425
+ // Licensed under the MIT License.
1392
1426
  /**
1393
1427
  * Helps specify a regional authority, or "AutoDiscoverRegion" to auto-detect the region.
1394
1428
  */
@@ -1528,7 +1562,7 @@ function calculateRegionalAuthority(regionalAuthority) {
1528
1562
  }
1529
1563
 
1530
1564
  // Copyright (c) Microsoft Corporation.
1531
- // Licensed under the MIT license.
1565
+ // Licensed under the MIT License.
1532
1566
  /**
1533
1567
  * The default logger used if no logger was passed in by the credential.
1534
1568
  */
@@ -1549,10 +1583,10 @@ const interactiveBrowserMockable = {
1549
1583
  * @returns The MSAL configuration object.
1550
1584
  */
1551
1585
  function generateMsalConfiguration(clientId, tenantId, msalClientOptions = {}) {
1552
- var _a, _b, _c, _d;
1586
+ var _a, _b, _c;
1553
1587
  const resolvedTenant = resolveTenantId((_a = msalClientOptions.logger) !== null && _a !== void 0 ? _a : msalLogger, tenantId, clientId);
1554
1588
  // TODO: move and reuse getIdentityClientAuthorityHost
1555
- const authority = getAuthority(resolvedTenant, (_b = msalClientOptions.authorityHost) !== null && _b !== void 0 ? _b : process.env.AZURE_AUTHORITY_HOST);
1589
+ const authority = getAuthority(resolvedTenant, getAuthorityHost(msalClientOptions));
1556
1590
  const httpClient = new IdentityClient(Object.assign(Object.assign({}, msalClientOptions.tokenCredentialOptions), { authorityHost: authority, loggingOptions: msalClientOptions.loggingOptions }));
1557
1591
  const msalConfig = {
1558
1592
  auth: {
@@ -1563,9 +1597,9 @@ function generateMsalConfiguration(clientId, tenantId, msalClientOptions = {}) {
1563
1597
  system: {
1564
1598
  networkClient: httpClient,
1565
1599
  loggerOptions: {
1566
- loggerCallback: defaultLoggerCallback((_c = msalClientOptions.logger) !== null && _c !== void 0 ? _c : msalLogger),
1600
+ loggerCallback: defaultLoggerCallback((_b = msalClientOptions.logger) !== null && _b !== void 0 ? _b : msalLogger),
1567
1601
  logLevel: getMSALLogLevel(logger$m.getLogLevel()),
1568
- piiLoggingEnabled: (_d = msalClientOptions.loggingOptions) === null || _d === void 0 ? void 0 : _d.enableUnsafeSupportLogging,
1602
+ piiLoggingEnabled: (_c = msalClientOptions.loggingOptions) === null || _c === void 0 ? void 0 : _c.enableUnsafeSupportLogging,
1569
1603
  },
1570
1604
  },
1571
1605
  };
@@ -1661,6 +1695,12 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1661
1695
  silentRequest.tokenQueryParameters["msal_request_type"] = "consumer_passthrough";
1662
1696
  }
1663
1697
  }
1698
+ if (options.proofOfPossessionOptions) {
1699
+ silentRequest.shrNonce = options.proofOfPossessionOptions.nonce;
1700
+ silentRequest.authenticationScheme = "pop";
1701
+ silentRequest.resourceRequestMethod = options.proofOfPossessionOptions.resourceRequestMethod;
1702
+ silentRequest.resourceRequestUri = options.proofOfPossessionOptions.resourceRequestUrl;
1703
+ }
1664
1704
  state.logger.getToken.info("Attempting to acquire token silently");
1665
1705
  return app.acquireTokenSilent(silentRequest);
1666
1706
  }
@@ -1670,7 +1710,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1670
1710
  */
1671
1711
  function calculateRequestAuthority(options) {
1672
1712
  if (options === null || options === void 0 ? void 0 : options.tenantId) {
1673
- return getAuthority(options.tenantId, createMsalClientOptions.authorityHost);
1713
+ return getAuthority(options.tenantId, getAuthorityHost(createMsalClientOptions));
1674
1714
  }
1675
1715
  return state.msalConfig.auth.authority;
1676
1716
  }
@@ -1685,7 +1725,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1685
1725
  * @returns A promise that resolves to an AccessToken object containing the access token and its expiration timestamp.
1686
1726
  */
1687
1727
  async function withSilentAuthentication(msalApp, scopes, options, onAuthenticationRequired) {
1688
- var _a;
1728
+ var _a, _b;
1689
1729
  let response = null;
1690
1730
  try {
1691
1731
  response = await getTokenSilent(msalApp, scopes, options);
@@ -1718,9 +1758,12 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1718
1758
  return {
1719
1759
  token: response.accessToken,
1720
1760
  expiresOnTimestamp: response.expiresOn.getTime(),
1761
+ refreshAfterTimestamp: (_b = response.refreshOn) === null || _b === void 0 ? void 0 : _b.getTime(),
1762
+ tokenType: response.tokenType,
1721
1763
  };
1722
1764
  }
1723
1765
  async function getTokenByClientSecret(scopes, clientSecret, options = {}) {
1766
+ var _a;
1724
1767
  state.logger.getToken.info(`Attempting to acquire token using client secret`);
1725
1768
  state.msalConfig.auth.clientSecret = clientSecret;
1726
1769
  const msalApp = await getConfidentialApp(options);
@@ -1736,6 +1779,8 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1736
1779
  return {
1737
1780
  token: response.accessToken,
1738
1781
  expiresOnTimestamp: response.expiresOn.getTime(),
1782
+ refreshAfterTimestamp: (_a = response.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
1783
+ tokenType: response.tokenType,
1739
1784
  };
1740
1785
  }
1741
1786
  catch (err) {
@@ -1743,6 +1788,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1743
1788
  }
1744
1789
  }
1745
1790
  async function getTokenByClientAssertion(scopes, clientAssertion, options = {}) {
1791
+ var _a;
1746
1792
  state.logger.getToken.info(`Attempting to acquire token using client assertion`);
1747
1793
  state.msalConfig.auth.clientAssertion = clientAssertion;
1748
1794
  const msalApp = await getConfidentialApp(options);
@@ -1759,6 +1805,8 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1759
1805
  return {
1760
1806
  token: response.accessToken,
1761
1807
  expiresOnTimestamp: response.expiresOn.getTime(),
1808
+ refreshAfterTimestamp: (_a = response.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
1809
+ tokenType: response.tokenType,
1762
1810
  };
1763
1811
  }
1764
1812
  catch (err) {
@@ -1766,6 +1814,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1766
1814
  }
1767
1815
  }
1768
1816
  async function getTokenByClientCertificate(scopes, certificate, options = {}) {
1817
+ var _a;
1769
1818
  state.logger.getToken.info(`Attempting to acquire token using client certificate`);
1770
1819
  state.msalConfig.auth.clientCertificate = certificate;
1771
1820
  const msalApp = await getConfidentialApp(options);
@@ -1781,6 +1830,8 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1781
1830
  return {
1782
1831
  token: response.accessToken,
1783
1832
  expiresOnTimestamp: response.expiresOn.getTime(),
1833
+ refreshAfterTimestamp: (_a = response.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
1834
+ tokenType: response.tokenType,
1784
1835
  };
1785
1836
  }
1786
1837
  catch (err) {
@@ -1851,6 +1902,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1851
1902
  });
1852
1903
  }
1853
1904
  async function getTokenOnBehalfOf(scopes, userAssertionToken, clientCredentials, options = {}) {
1905
+ var _a;
1854
1906
  msalLogger.getToken.info(`Attempting to acquire token on behalf of another user`);
1855
1907
  if (typeof clientCredentials === "string") {
1856
1908
  // Client secret
@@ -1880,6 +1932,8 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1880
1932
  return {
1881
1933
  token: response.accessToken,
1882
1934
  expiresOnTimestamp: response.expiresOn.getTime(),
1935
+ refreshAfterTimestamp: (_a = response.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
1936
+ tokenType: response.tokenType,
1883
1937
  };
1884
1938
  }
1885
1939
  catch (err) {
@@ -1917,6 +1971,13 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1917
1971
  else {
1918
1972
  msalLogger.verbose("Attempting broker authentication without the default broker account");
1919
1973
  }
1974
+ if (options.proofOfPossessionOptions) {
1975
+ interactiveRequest.shrNonce = options.proofOfPossessionOptions.nonce;
1976
+ interactiveRequest.authenticationScheme = "pop";
1977
+ interactiveRequest.resourceRequestMethod =
1978
+ options.proofOfPossessionOptions.resourceRequestMethod;
1979
+ interactiveRequest.resourceRequestUri = options.proofOfPossessionOptions.resourceRequestUrl;
1980
+ }
1920
1981
  try {
1921
1982
  return await app.acquireTokenInteractive(interactiveRequest);
1922
1983
  }
@@ -1951,6 +2012,13 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1951
2012
  if (state.pluginConfiguration.broker.isEnabled) {
1952
2013
  return getBrokeredToken((_a = state.pluginConfiguration.broker.useDefaultBrokerAccount) !== null && _a !== void 0 ? _a : false);
1953
2014
  }
2015
+ if (options.proofOfPossessionOptions) {
2016
+ interactiveRequest.shrNonce = options.proofOfPossessionOptions.nonce;
2017
+ interactiveRequest.authenticationScheme = "pop";
2018
+ interactiveRequest.resourceRequestMethod =
2019
+ options.proofOfPossessionOptions.resourceRequestMethod;
2020
+ interactiveRequest.resourceRequestUri = options.proofOfPossessionOptions.resourceRequestUrl;
2021
+ }
1954
2022
  return app.acquireTokenInteractive(interactiveRequest);
1955
2023
  });
1956
2024
  }
@@ -1968,7 +2036,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1968
2036
  }
1969
2037
 
1970
2038
  // Copyright (c) Microsoft Corporation.
1971
- // Licensed under the MIT license.
2039
+ // Licensed under the MIT License.
1972
2040
  const logger$h = credentialLogger("ClientAssertionCredential");
1973
2041
  /**
1974
2042
  * Authenticates a service principal with a JWT assertion.
@@ -2018,7 +2086,7 @@ class ClientAssertionCredential {
2018
2086
  }
2019
2087
 
2020
2088
  // Copyright (c) Microsoft Corporation.
2021
- // Licensed under the MIT license.
2089
+ // Licensed under the MIT License.
2022
2090
  const credentialName$4 = "WorkloadIdentityCredential";
2023
2091
  /**
2024
2092
  * Contains the list of all supported environment variable names so that an
@@ -2127,7 +2195,7 @@ class WorkloadIdentityCredential {
2127
2195
  }
2128
2196
 
2129
2197
  // Copyright (c) Microsoft Corporation.
2130
- // Licensed under the MIT license.
2198
+ // Licensed under the MIT License.
2131
2199
  const msiName = "ManagedIdentityCredential - Token Exchange";
2132
2200
  const logger$f = credentialLogger(msiName);
2133
2201
  /**
@@ -2154,7 +2222,7 @@ const tokenExchangeMsi = {
2154
2222
  };
2155
2223
 
2156
2224
  // Copyright (c) Microsoft Corporation.
2157
- // Licensed under the MIT license.
2225
+ // Licensed under the MIT License.
2158
2226
  const logger$e = credentialLogger("ManagedIdentityCredential(MSAL)");
2159
2227
  class MsalMsiProvider {
2160
2228
  constructor(clientIdOrOptions, options = {}) {
@@ -2174,9 +2242,11 @@ class MsalMsiProvider {
2174
2242
  _options = clientIdOrOptions !== null && clientIdOrOptions !== void 0 ? clientIdOrOptions : {};
2175
2243
  }
2176
2244
  this.resourceId = _options === null || _options === void 0 ? void 0 : _options.resourceId;
2245
+ this.objectId = _options === null || _options === void 0 ? void 0 : _options.objectId;
2177
2246
  // For JavaScript users.
2178
- if (this.clientId && this.resourceId) {
2179
- throw new Error(`ManagedIdentityCredential - Client Id and Resource Id can't be provided at the same time.`);
2247
+ const providedIds = [this.clientId, this.resourceId, this.objectId].filter(Boolean);
2248
+ if (providedIds.length > 1) {
2249
+ throw new Error(`ManagedIdentityCredential: only one of 'clientId', 'resourceId', or 'objectId' can be provided. Received values: ${JSON.stringify({ clientId: this.clientId, resourceId: this.resourceId, objectId: this.objectId })}`);
2180
2250
  }
2181
2251
  // ManagedIdentity uses http for local requests
2182
2252
  _options.allowInsecureConnection = true;
@@ -2188,6 +2258,7 @@ class MsalMsiProvider {
2188
2258
  managedIdentityIdParams: {
2189
2259
  userAssignedClientId: this.clientId,
2190
2260
  userAssignedResourceId: this.resourceId,
2261
+ userAssignedObjectId: this.objectId,
2191
2262
  },
2192
2263
  system: {
2193
2264
  // todo: proxyUrl?
@@ -2203,6 +2274,17 @@ class MsalMsiProvider {
2203
2274
  this.isAvailableIdentityClient = new IdentityClient(Object.assign(Object.assign({}, _options), { retryOptions: {
2204
2275
  maxRetries: 0,
2205
2276
  } }));
2277
+ // CloudShell MSI will ignore any user-assigned identity passed as parameters. To avoid confusion, we prevent this from happening as early as possible.
2278
+ if (this.managedIdentityApp.getManagedIdentitySource() === "CloudShell") {
2279
+ if (this.clientId || this.resourceId || this.objectId) {
2280
+ logger$e.warning(`CloudShell MSI detected with user-provided IDs - throwing. Received values: ${JSON.stringify({
2281
+ clientId: this.clientId,
2282
+ resourceId: this.resourceId,
2283
+ objectId: this.objectId,
2284
+ })}.`);
2285
+ throw new CredentialUnavailableError("ManagedIdentityCredential: Specifying a user-assigned managed identity is not supported for CloudShell at runtime. When using Managed Identity in CloudShell, omit the clientId, resourceId, and objectId parameters.");
2286
+ }
2287
+ }
2206
2288
  }
2207
2289
  /**
2208
2290
  * Authenticates with Microsoft Entra ID and returns an access token if successful.
@@ -2220,6 +2302,7 @@ class MsalMsiProvider {
2220
2302
  throw new CredentialUnavailableError(`ManagedIdentityCredential: Multiple scopes are not supported. Scopes: ${JSON.stringify(scopes)}`);
2221
2303
  }
2222
2304
  return tracingClient.withSpan("ManagedIdentityCredential.getToken", options, async () => {
2305
+ var _a;
2223
2306
  try {
2224
2307
  const isTokenExchangeMsi = await tokenExchangeMsi.isAvailable({
2225
2308
  scopes,
@@ -2263,7 +2346,7 @@ class MsalMsiProvider {
2263
2346
  resourceId: this.resourceId,
2264
2347
  });
2265
2348
  if (!isAvailable) {
2266
- throw new CredentialUnavailableError(`ManagedIdentityCredential: Attempted to use the IMDS endpoint, but it is not available.`);
2349
+ throw new CredentialUnavailableError(`Attempted to use the IMDS endpoint, but it is not available.`);
2267
2350
  }
2268
2351
  }
2269
2352
  // If we got this far, it means:
@@ -2279,6 +2362,8 @@ class MsalMsiProvider {
2279
2362
  return {
2280
2363
  expiresOnTimestamp: token.expiresOn.getTime(),
2281
2364
  token: token.accessToken,
2365
+ refreshAfterTimestamp: (_a = token.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
2366
+ tokenType: "Bearer",
2282
2367
  };
2283
2368
  }
2284
2369
  catch (err) {
@@ -2338,7 +2423,7 @@ function isNetworkError(err) {
2338
2423
  }
2339
2424
 
2340
2425
  // Copyright (c) Microsoft Corporation.
2341
- // Licensed under the MIT license.
2426
+ // Licensed under the MIT License.
2342
2427
  /**
2343
2428
  * Attempts authentication using a managed identity available at the deployment environment.
2344
2429
  * This authentication type works in Azure VMs, App Service instances, Azure Functions applications,
@@ -2374,7 +2459,7 @@ class ManagedIdentityCredential {
2374
2459
  }
2375
2460
 
2376
2461
  // Copyright (c) Microsoft Corporation.
2377
- // Licensed under the MIT license.
2462
+ // Licensed under the MIT License.
2378
2463
  /**
2379
2464
  * Ensures the scopes value is an array.
2380
2465
  * @internal
@@ -2402,7 +2487,7 @@ function getScopeResource(scope) {
2402
2487
  }
2403
2488
 
2404
2489
  // Copyright (c) Microsoft Corporation.
2405
- // Licensed under the MIT license.
2490
+ // Licensed under the MIT License.
2406
2491
  /**
2407
2492
  * Mockable reference to the CLI credential cliCredentialFunctions
2408
2493
  * @internal
@@ -2553,6 +2638,7 @@ class AzureCliCredential {
2553
2638
  return {
2554
2639
  token,
2555
2640
  expiresOnTimestamp,
2641
+ tokenType: "Bearer",
2556
2642
  };
2557
2643
  }
2558
2644
  // fallback to the older expiresOn - an RFC3339 date string
@@ -2564,12 +2650,13 @@ class AzureCliCredential {
2564
2650
  return {
2565
2651
  token,
2566
2652
  expiresOnTimestamp,
2653
+ tokenType: "Bearer",
2567
2654
  };
2568
2655
  }
2569
2656
  }
2570
2657
 
2571
2658
  // Copyright (c) Microsoft Corporation.
2572
- // Licensed under the MIT license.
2659
+ // Licensed under the MIT License.
2573
2660
  /**
2574
2661
  * Mockable reference to the Developer CLI credential cliCredentialFunctions
2575
2662
  * @internal
@@ -2712,6 +2799,7 @@ class AzureDeveloperCliCredential {
2712
2799
  return {
2713
2800
  token: resp.token,
2714
2801
  expiresOnTimestamp: new Date(resp.expiresOn).getTime(),
2802
+ tokenType: "Bearer",
2715
2803
  };
2716
2804
  }
2717
2805
  catch (e) {
@@ -2733,7 +2821,7 @@ class AzureDeveloperCliCredential {
2733
2821
  }
2734
2822
 
2735
2823
  // Copyright (c) Microsoft Corporation.
2736
- // Licensed under the MIT license.
2824
+ // Licensed under the MIT License.
2737
2825
  /**
2738
2826
  * Easy to mock childProcess utils.
2739
2827
  * @internal
@@ -2764,7 +2852,7 @@ const processUtils = {
2764
2852
  };
2765
2853
 
2766
2854
  // Copyright (c) Microsoft Corporation.
2767
- // Licensed under the MIT license.
2855
+ // Licensed under the MIT License.
2768
2856
  const logger$b = credentialLogger("AzurePowerShellCredential");
2769
2857
  const isWindows = process.platform === "win32";
2770
2858
  /**
@@ -2932,6 +3020,7 @@ class AzurePowerShellCredential {
2932
3020
  return {
2933
3021
  token: response.Token,
2934
3022
  expiresOnTimestamp: new Date(response.ExpiresOn).getTime(),
3023
+ tokenType: "Bearer",
2935
3024
  };
2936
3025
  }
2937
3026
  catch (err) {
@@ -2986,7 +3075,7 @@ async function parseJsonToken(result) {
2986
3075
  }
2987
3076
 
2988
3077
  // Copyright (c) Microsoft Corporation.
2989
- // Licensed under the MIT license.
3078
+ // Licensed under the MIT License.
2990
3079
  /**
2991
3080
  * @internal
2992
3081
  */
@@ -3002,7 +3091,14 @@ class ChainedTokenCredential {
3002
3091
  * @param sources - `TokenCredential` implementations to be tried in order.
3003
3092
  *
3004
3093
  * Example usage:
3005
- * ```javascript
3094
+ * ```ts snippet:chained_token_credential_example
3095
+ * import { ClientSecretCredential, ChainedTokenCredential } from "@azure/identity";
3096
+ *
3097
+ * const tenantId = "<tenant-id>";
3098
+ * const clientId = "<client-id>";
3099
+ * const clientSecret = "<client-secret>";
3100
+ * const anotherClientId = "<another-client-id>";
3101
+ * const anotherSecret = "<another-client-secret>";
3006
3102
  * const firstCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
3007
3103
  * const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, anotherSecret);
3008
3104
  * const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);
@@ -3065,7 +3161,7 @@ class ChainedTokenCredential {
3065
3161
  }
3066
3162
 
3067
3163
  // Copyright (c) Microsoft Corporation.
3068
- // Licensed under the MIT license.
3164
+ // Licensed under the MIT License.
3069
3165
  const credentialName$3 = "ClientCertificateCredential";
3070
3166
  const logger$9 = credentialLogger(credentialName$3);
3071
3167
  /**
@@ -3178,7 +3274,7 @@ async function parseCertificate(certificateConfiguration, sendCertificateChain)
3178
3274
  }
3179
3275
 
3180
3276
  // Copyright (c) Microsoft Corporation.
3181
- // Licensed under the MIT license.
3277
+ // Licensed under the MIT License.
3182
3278
  const logger$8 = credentialLogger("ClientSecretCredential");
3183
3279
  /**
3184
3280
  * Enables authentication to Microsoft Entra ID using a client secret
@@ -3232,7 +3328,7 @@ class ClientSecretCredential {
3232
3328
  }
3233
3329
 
3234
3330
  // Copyright (c) Microsoft Corporation.
3235
- // Licensed under the MIT license.
3331
+ // Licensed under the MIT License.
3236
3332
  const logger$7 = credentialLogger("UsernamePasswordCredential");
3237
3333
  /**
3238
3334
  * Enables authentication to Microsoft Entra ID with a user's
@@ -3293,7 +3389,7 @@ class UsernamePasswordCredential {
3293
3389
  }
3294
3390
 
3295
3391
  // Copyright (c) Microsoft Corporation.
3296
- // Licensed under the MIT license.
3392
+ // Licensed under the MIT License.
3297
3393
  /**
3298
3394
  * Contains the list of all supported environment variable names so that an
3299
3395
  * appropriate error message can be generated when no credentials can be
@@ -3416,7 +3512,7 @@ class EnvironmentCredential {
3416
3512
  }
3417
3513
 
3418
3514
  // Copyright (c) Microsoft Corporation.
3419
- // Licensed under the MIT license.
3515
+ // Licensed under the MIT License.
3420
3516
  const logger$5 = credentialLogger("DefaultAzureCredential");
3421
3517
  /**
3422
3518
  * Creates a {@link ManagedIdentityCredential} from the provided options.
@@ -3559,7 +3655,7 @@ class DefaultAzureCredential extends ChainedTokenCredential {
3559
3655
  }
3560
3656
 
3561
3657
  // Copyright (c) Microsoft Corporation.
3562
- // Licensed under the MIT license.
3658
+ // Licensed under the MIT License.
3563
3659
  const logger$4 = credentialLogger("InteractiveBrowserCredential");
3564
3660
  /**
3565
3661
  * Enables authentication to Microsoft Entra ID inside of the web browser
@@ -3644,7 +3740,7 @@ class InteractiveBrowserCredential {
3644
3740
  }
3645
3741
 
3646
3742
  // Copyright (c) Microsoft Corporation.
3647
- // Licensed under the MIT license.
3743
+ // Licensed under the MIT License.
3648
3744
  const logger$3 = credentialLogger("DeviceCodeCredential");
3649
3745
  /**
3650
3746
  * Method that logs the user code from the DeviceCodeCredential.
@@ -3666,13 +3762,15 @@ class DeviceCodeCredential {
3666
3762
  *
3667
3763
  * Developers can configure how this message is shown by passing a custom `userPromptCallback`:
3668
3764
  *
3669
- * ```js
3765
+ * ```ts snippet:device_code_credential_example
3766
+ * import { DeviceCodeCredential } from "@azure/identity";
3767
+ *
3670
3768
  * const credential = new DeviceCodeCredential({
3671
- * tenantId: env.AZURE_TENANT_ID,
3672
- * clientId: env.AZURE_CLIENT_ID,
3769
+ * tenantId: process.env.AZURE_TENANT_ID,
3770
+ * clientId: process.env.AZURE_CLIENT_ID,
3673
3771
  * userPromptCallback: (info) => {
3674
3772
  * console.log("CUSTOMIZED PROMPT CALLBACK", info.message);
3675
- * }
3773
+ * },
3676
3774
  * });
3677
3775
  * ```
3678
3776
  *
@@ -3727,7 +3825,7 @@ class DeviceCodeCredential {
3727
3825
  }
3728
3826
 
3729
3827
  // Copyright (c) Microsoft Corporation.
3730
- // Licensed under the MIT license.
3828
+ // Licensed under the MIT License.
3731
3829
  const credentialName$1 = "AzurePipelinesCredential";
3732
3830
  const logger$2 = credentialLogger(credentialName$1);
3733
3831
  const OIDC_API_VERSION = "7.1";
@@ -3744,7 +3842,8 @@ class AzurePipelinesCredential {
3744
3842
  * @param systemAccessToken - The pipeline's <see href="https://learn.microsoft.com/azure/devops/pipelines/build/variables?view=azure-devops%26tabs=yaml#systemaccesstoken">System.AccessToken</see> value.
3745
3843
  * @param options - The identity client options to use for authentication.
3746
3844
  */
3747
- constructor(tenantId, clientId, serviceConnectionId, systemAccessToken, options) {
3845
+ constructor(tenantId, clientId, serviceConnectionId, systemAccessToken, options = {}) {
3846
+ var _a, _b;
3748
3847
  if (!clientId) {
3749
3848
  throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. clientId is a required parameter.`);
3750
3849
  }
@@ -3757,6 +3856,12 @@ class AzurePipelinesCredential {
3757
3856
  if (!systemAccessToken) {
3758
3857
  throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. systemAccessToken is a required parameter.`);
3759
3858
  }
3859
+ // Allow these headers to be logged for troubleshooting by AzurePipelines.
3860
+ options.loggingOptions = Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.loggingOptions), { additionalAllowedHeaderNames: [
3861
+ ...((_b = (_a = options.loggingOptions) === null || _a === void 0 ? void 0 : _a.additionalAllowedHeaderNames) !== null && _b !== void 0 ? _b : []),
3862
+ "x-vss-e2eid",
3863
+ "x-msedge-ref",
3864
+ ] });
3760
3865
  this.identityClient = new IdentityClient(options);
3761
3866
  checkTenantId(logger$2, tenantId);
3762
3867
  logger$2.info(`Invoking AzurePipelinesCredential with tenant ID: ${tenantId}, client ID: ${clientId}, and service connection ID: ${serviceConnectionId}`);
@@ -3805,6 +3910,8 @@ class AzurePipelinesCredential {
3805
3910
  headers: coreRestPipeline.createHttpHeaders({
3806
3911
  "Content-Type": "application/json",
3807
3912
  Authorization: `Bearer ${systemAccessToken}`,
3913
+ // Prevents the service from responding with a redirect HTTP status code (useful for automation).
3914
+ "X-TFS-FedAuthRedirect": "Suppress",
3808
3915
  }),
3809
3916
  });
3810
3917
  const response = await this.identityClient.sendRequest(request);
@@ -3812,6 +3919,7 @@ class AzurePipelinesCredential {
3812
3919
  }
3813
3920
  }
3814
3921
  function handleOidcResponse(response) {
3922
+ // OIDC token is present in `bodyAsText` field
3815
3923
  const text = response.bodyAsText;
3816
3924
  if (!text) {
3817
3925
  logger$2.error(`${credentialName$1}: Authentication Failed. Received null token from OIDC request. Response status- ${response.status}. Complete response - ${JSON.stringify(response)}`);
@@ -3829,7 +3937,7 @@ function handleOidcResponse(response) {
3829
3937
  const errorMessage = `${credentialName$1}: Authentication Failed. oidcToken field not detected in the response.`;
3830
3938
  let errorDescription = ``;
3831
3939
  if (response.status !== 200) {
3832
- errorDescription = `Complete response - ${JSON.stringify(result)}. See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/azurepipelinescredential/troubleshoot`;
3940
+ errorDescription = `Response body = ${text}. Response Headers ["x-vss-e2eid"] = ${response.headers.get("x-vss-e2eid")} and ["x-msedge-ref"] = ${response.headers.get("x-msedge-ref")}. See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/azurepipelinescredential/troubleshoot`;
3833
3941
  }
3834
3942
  logger$2.error(errorMessage);
3835
3943
  logger$2.error(errorDescription);
@@ -3841,17 +3949,18 @@ function handleOidcResponse(response) {
3841
3949
  }
3842
3950
  catch (e) {
3843
3951
  const errorDetails = `${credentialName$1}: Authentication Failed. oidcToken field not detected in the response.`;
3844
- logger$2.error(`Response from service = ${text} and error message = ${e.message}`);
3952
+ logger$2.error(`Response from service = ${text}, Response Headers ["x-vss-e2eid"] = ${response.headers.get("x-vss-e2eid")}
3953
+ and ["x-msedge-ref"] = ${response.headers.get("x-msedge-ref")}, error message = ${e.message}`);
3845
3954
  logger$2.error(errorDetails);
3846
3955
  throw new AuthenticationError(response.status, {
3847
3956
  error: errorDetails,
3848
- error_description: `Response = ${text}. See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/azurepipelinescredential/troubleshoot`,
3957
+ error_description: `Response = ${text}. Response headers ["x-vss-e2eid"] = ${response.headers.get("x-vss-e2eid")} and ["x-msedge-ref"] = ${response.headers.get("x-msedge-ref")}. See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/azurepipelinescredential/troubleshoot`,
3849
3958
  });
3850
3959
  }
3851
3960
  }
3852
3961
 
3853
3962
  // Copyright (c) Microsoft Corporation.
3854
- // Licensed under the MIT license.
3963
+ // Licensed under the MIT License.
3855
3964
  const logger$1 = credentialLogger("AuthorizationCodeCredential");
3856
3965
  /**
3857
3966
  * Enables authentication to Microsoft Entra ID using an authorization code
@@ -3905,7 +4014,7 @@ class AuthorizationCodeCredential {
3905
4014
  }
3906
4015
 
3907
4016
  // Copyright (c) Microsoft Corporation.
3908
- // Licensed under the MIT license.
4017
+ // Licensed under the MIT License.
3909
4018
  const credentialName = "OnBehalfOfCredential";
3910
4019
  const logger = credentialLogger(credentialName);
3911
4020
  /**
@@ -4009,18 +4118,18 @@ class OnBehalfOfCredential {
4009
4118
  }
4010
4119
 
4011
4120
  // Copyright (c) Microsoft Corporation.
4012
- // Licensed under the MIT license.
4121
+ // Licensed under the MIT License.
4013
4122
  /**
4014
4123
  * Returns a callback that provides a bearer token.
4015
4124
  * For example, the bearer token can be used to authenticate a request as follows:
4016
- * ```js
4017
- * import { DefaultAzureCredential } from "@azure/identity";
4125
+ * ```ts snippet:token_provider_example
4126
+ * import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity";
4127
+ * import { createPipelineRequest } from "@azure/core-rest-pipeline";
4018
4128
  *
4019
4129
  * const credential = new DefaultAzureCredential();
4020
4130
  * const scope = "https://cognitiveservices.azure.com/.default";
4021
4131
  * const getAccessToken = getBearerTokenProvider(credential, scope);
4022
4132
  * const token = await getAccessToken();
4023
- *
4024
4133
  * // usage
4025
4134
  * const request = createPipelineRequest({ url: "https://example.com" });
4026
4135
  * request.headers.set("Authorization", `Bearer ${token}`);
@@ -4060,7 +4169,7 @@ function getBearerTokenProvider(credential, scopes, options) {
4060
4169
  }
4061
4170
 
4062
4171
  // Copyright (c) Microsoft Corporation.
4063
- // Licensed under the MIT license.
4172
+ // Licensed under the MIT License.
4064
4173
  /**
4065
4174
  * Returns a new instance of the {@link DefaultAzureCredential}.
4066
4175
  */