@azure/identity 3.2.4 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (39) hide show
  1. package/README.md +20 -56
  2. package/dist/index.js +82 -36
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/src/constants.js +3 -1
  5. package/dist-esm/src/constants.js.map +1 -1
  6. package/dist-esm/src/credentials/azureCliCredential.js +3 -3
  7. package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
  8. package/dist-esm/src/credentials/azurePowerShellCredential.js +4 -4
  9. package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
  10. package/dist-esm/src/credentials/managedIdentityCredential/index.js +1 -0
  11. package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
  12. package/dist-esm/src/msal/browserFlows/msalAuthCode.js +2 -0
  13. package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
  14. package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  15. package/dist-esm/src/msal/credentials.js.map +1 -1
  16. package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js +6 -4
  17. package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js.map +1 -1
  18. package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js +1 -1
  19. package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js.map +1 -1
  20. package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js +1 -1
  21. package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js.map +1 -1
  22. package/dist-esm/src/msal/nodeFlows/msalClientSecret.js +1 -1
  23. package/dist-esm/src/msal/nodeFlows/msalClientSecret.js.map +1 -1
  24. package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js +1 -1
  25. package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js.map +1 -1
  26. package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js +57 -16
  27. package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
  28. package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js +1 -1
  29. package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js.map +1 -1
  30. package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js +4 -4
  31. package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +1 -1
  32. package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js +1 -1
  33. package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js.map +1 -1
  34. package/dist-esm/src/msal/types.js.map +1 -1
  35. package/dist-esm/src/tokenCredentialOptions.js.map +1 -1
  36. package/dist-esm/src/util/scopeUtils.js +1 -1
  37. package/dist-esm/src/util/scopeUtils.js.map +1 -1
  38. package/package.json +5 -5
  39. package/types/identity.d.ts +8 -1
package/README.md CHANGED
@@ -137,6 +137,12 @@ If used from Node.js, the `DefaultAzureCredential` will attempt to authenticate
137
137
  1. **Azure CLI** - If the developer has authenticated an account via the Azure CLI `az login` command, the `DefaultAzureCredential` will authenticate with that account.
138
138
  1. **Azure PowerShell** - If the developer has authenticated using the Azure PowerShell module `Connect-AzAccount` command, the `DefaultAzureCredential` will authenticate with that account.
139
139
 
140
+ #### Continuation policy
141
+
142
+ As of version 3.3.0, `DefaultAzureCredential` will attempt to authenticate with all developer credentials until one succeeds, regardless of any errors previous developer credentials experienced. For example, a developer credential may attempt to get a token and fail, so `DefaultAzureCredential` will continue to the next credential in the flow. Deployed service credentials will stop the flow with a thrown exception if they're able to attempt token retrieval, but don't receive one.
143
+
144
+ This allows for trying all of the developer credentials on your machine while having predictable deployed behavior.
145
+
140
146
  #### Note about `VisualStudioCodeCredential`
141
147
 
142
148
  Due to a [known issue](https://github.com/Azure/azure-sdk-for-js/issues/20500), `VisualStudioCodeCredential` has been removed from the `DefaultAzureCredential` token chain. When the issue is resolved in a future release, this change will be reverted.
@@ -161,10 +167,10 @@ This example demonstrates authenticating the `KeyClient` from the [@azure/keyvau
161
167
  // If environment configuration is incomplete, it will try managed identity.
162
168
 
163
169
  // Azure Key Vault service to use
164
- const { KeyClient } = require("@azure/keyvault-keys");
170
+ import { KeyClient } from "@azure/keyvault-keys";
165
171
 
166
172
  // Azure authentication library to access Azure Key Vault
167
- const { DefaultAzureCredential } = require("@azure/identity");
173
+ import { DefaultAzureCredential } from "@azure/identity";
168
174
 
169
175
  // Azure SDK clients accept the credential as a parameter
170
176
  const credential = new DefaultAzureCredential();
@@ -181,8 +187,8 @@ A relatively common scenario involves authenticating using a user-assigned manag
181
187
 
182
188
  While the `DefaultAzureCredential` is generally the quickest way to get started developing applications for Azure, more advanced users may want to customize the credentials considered when authenticating. The `ChainedTokenCredential` enables users to combine multiple credential instances to define a customized chain of credentials. This example demonstrates creating a `ChainedTokenCredential` which will attempt to authenticate using two differently configured instances of `ClientSecretCredential`, to then authenticate the `KeyClient` from the [@azure/keyvault-keys](https://www.npmjs.com/package/@azure/keyvault-keys):
183
189
 
184
- ```javascript
185
- const { ClientSecretCredential, ChainedTokenCredential } = require("@azure/identity");
190
+ ```typescript
191
+ import { ClientSecretCredential, ChainedTokenCredential } from "@azure/identity";
186
192
 
187
193
  // When an access token is requested, the chain will try each
188
194
  // credential in order, stopping when one provides a token
@@ -191,7 +197,7 @@ const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, a
191
197
  const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);
192
198
 
193
199
  // The chain can be used anywhere a credential is required
194
- const { KeyClient } = require("@azure/keyvault-keys");
200
+ import { KeyClient } from "@azure/keyvault-keys";
195
201
  const client = new KeyClient(vaultUrl, credentialChain);
196
202
  ```
197
203
 
@@ -213,7 +219,7 @@ For examples of how to use managed identity for authentication, see [the example
213
219
 
214
220
  Credentials default to authenticating to the Azure AD endpoint for Azure Public Cloud. To access resources in other clouds, such as Azure Government or a private cloud, configure credentials with the `authorityHost` argument in the constructor. The `AzureAuthorityHosts` interface defines authorities for well-known clouds. For the US Government cloud, you could instantiate a credential this way:
215
221
 
216
- ```ts
222
+ ```typescript
217
223
  import { AzureAuthorityHosts, ClientSecretCredential } from "@azure/identity";
218
224
  const credential = new ClientSecretCredential(
219
225
  "<YOUR_TENANT_ID>",
@@ -237,7 +243,7 @@ Not all credentials require this configuration. Credentials that authenticate th
237
243
  | [`ChainedTokenCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/chainedtokencredential?view=azure-node-latest) | Allows users to define custom authentication flows composing multiple credentials. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#chaining-credentials) |
238
244
  | [`EnvironmentCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/environmentcredential?view=azure-node-latest) | Authenticates a service principal or user via credential information specified in environment variables. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-a-service-principal-with-environment-credentials) |
239
245
  | [`ManagedIdentityCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/managedidentitycredential?view=azure-node-latest) | Authenticates the managed identity of an Azure resource. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-in-azure-with-managed-identity) |
240
- |`WorkloadIdentityCredential`| Supports [Azure AD workload identity](https://learn.microsoft.com/azure/aks/workload-identity-overview) on Kubernetes. | |
246
+ | [`WorkloadIdentityCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/workloadidentitycredential?view=azure-node-latest)| Supports [Azure AD workload identity](https://learn.microsoft.com/azure/aks/workload-identity-overview) on Kubernetes. | |
241
247
 
242
248
  ### Authenticate service principals
243
249
 
@@ -261,8 +267,8 @@ Not all credentials require this configuration. Credentials that authenticate th
261
267
 
262
268
  | Credential | Usage | Example | Reference |
263
269
  | ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
264
- | `AzureDeveloperCliCredential` | Authenticate in a development environment with the enabled user or service principal in Azure Developer CLI. | | [Azure Developer CLI Reference](https://learn.microsoft.com/azure/developer/azure-developer-cli/reference) |
265
270
  | [`AzureCliCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/azureclicredential?view=azure-node-latest) | Authenticate in a development environment with the Azure CLI. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-a-user-account-with-azure-cli) | [Azure CLI authentication](https://learn.microsoft.com/cli/azure/authenticate-azure-cli) |
271
+ | [`AzureDeveloperCliCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/azuredeveloperclicredential?view=azure-node-latest) | Authenticate in a development environment with the enabled user or service principal in Azure Developer CLI. | | [Azure Developer CLI Reference](https://learn.microsoft.com/azure/developer/azure-developer-cli/reference) |
266
272
  | [`AzurePowerShellCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/azurepowershellcredential?view=azure-node-latest) | Authenticate in a development environment using Azure PowerShell. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-a-user-account-with-azure-powershell) | [Azure PowerShell authentication](https://learn.microsoft.com/powershell/azure/authenticate-azureps) |
267
273
  | [`VisualStudioCodeCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/visualstudiocodecredential?view=azure-node-latest) | Authenticates as the user signed in to the Visual Studio Code Azure Account extension.| | [VS Code Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account)
268
274
 
@@ -298,8 +304,14 @@ Not all credentials require this configuration. Credentials that authenticate th
298
304
 
299
305
  Configuration is attempted in the above order. For example, if values for a client secret and certificate are both present, the client secret will be used.
300
306
 
307
+ ## Continuous Access Evaluation
308
+
309
+ As of version 3.3.0, accessing resources protected by [Continuous Access Evaluation](https://learn.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) (CAE) is possible on a per-request basis. This can be enabled using the [`GetTokenOptions.enableCae(boolean)` API](https://learn.microsoft.com/javascript/api/@azure/core-auth/gettokenoptions?view=azure-node-latest#@azure-core-auth-gettokenoptions-enablecae). CAE isn't supported for developer credentials.
310
+
301
311
  ## Token caching
312
+
302
313
  Token caching is a feature provided by the Azure Identity library that allows apps to:
314
+
303
315
  - Cache tokens in memory (default) and on disk (opt-in).
304
316
  - Improve resilience and performance.
305
317
  - Reduce the number of requests made to Azure AD to obtain access tokens.
@@ -308,54 +320,6 @@ The Azure Identity library offers both in-memory and persistent disk caching. Fo
308
320
 
309
321
  ## Troubleshooting
310
322
 
311
- ### Error handling
312
-
313
- Credentials raise `AuthenticationError` when they fail to authenticate. This class has a `message` field which describes why authentication failed. An `AggregateAuthenticationError` will be raised by `ChainedTokenCredential` with an `errors` field containing an array of errors from each credential in the chain.
314
-
315
- ### Logging
316
-
317
- Enabling logging may help uncover useful information about failures.
318
-
319
- To see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`.
320
- You can read this environment variable from the _.env_ file by explicitly specifying a file path:
321
-
322
- ```javascript
323
- require("dotenv").config({ path: ".env" });
324
- ```
325
-
326
- Alternatively, logging can be enabled at runtime by calling `setLogLevel` from the `@azure/logger` package:
327
-
328
- ```javascript
329
- import { setLogLevel } from "@azure/logger";
330
-
331
- setLogLevel("info");
332
- ```
333
-
334
- In cases where the authenticate code might be running in an environment with more than one credential available,
335
- the `@azure/identity` package offers a unique form of logging. On the optional parameters for every credential,
336
- developers can set `allowLoggingAccountIdentifiers` to true in the
337
- `loggingOptions` to log information specific to the authenticated account after
338
- each successful authentication, including the Client ID, the Tenant ID, the
339
- Object ID of the authenticated user, and if possible the User Principal Name.
340
-
341
- For example, using the `DefaultAzureCredential`:
342
-
343
- ```js
344
- import { setLogLevel } from "@azure/logger";
345
-
346
- setLogLevel("info");
347
-
348
- const credential = new DefaultAzureCredential({
349
- loggingOptions: { allowLoggingAccountIdentifiers: true },
350
- });
351
- ```
352
-
353
- Once that credential authenticates, the following message will appear in the logs (with the real information instead of `HIDDEN`):
354
-
355
- ```
356
- azure:identity:info [Authenticated account] Client ID: HIDDEN. Tenant ID: HIDDEN. User Principal Name: HIDDEN. Object ID (user): HIDDEN
357
- ```
358
-
359
323
  For assistance with troubleshooting, see the [troubleshooting guide](https://aka.ms/azsdk/js/identity/troubleshoot).
360
324
 
361
325
  ## Next steps
package/dist/index.js CHANGED
@@ -257,7 +257,7 @@ function credentialLogger(title, log = logger$n) {
257
257
  /**
258
258
  * Current version of the `@azure/identity` package.
259
259
  */
260
- const SDK_VERSION = `3.2.4`;
260
+ const SDK_VERSION = `3.3.0`;
261
261
  /**
262
262
  * The default client ID for authentication
263
263
  * @internal
@@ -301,6 +301,8 @@ const DefaultAuthorityHost = exports.AzureAuthorityHosts.AzurePublicCloud;
301
301
  * Allow acquiring tokens for any tenant for multi-tentant auth.
302
302
  */
303
303
  const ALL_TENANTS = ["*"];
304
+ const CACHE_CAE_SUFFIX = ".cae";
305
+ const CACHE_NON_CAE_SUFFIX = ".nocae";
304
306
 
305
307
  // Copyright (c) Microsoft Corporation.
306
308
  /**
@@ -1057,6 +1059,12 @@ class MsalNode extends MsalBaseUtilities {
1057
1059
  constructor(options) {
1058
1060
  var _a, _b, _c, _d;
1059
1061
  super(options);
1062
+ // protected publicApp: msalNode.PublicClientApplication | undefined;
1063
+ // protected publicAppCae: msalNode.PublicClientApplication | undefined;
1064
+ // protected confidentialApp: msalNode.ConfidentialClientApplication | undefined;
1065
+ // protected confidentialAppCae: msalNode.ConfidentialClientApplication | undefined;
1066
+ this.app = {};
1067
+ this.caeApp = {};
1060
1068
  this.requiresConfidential = false;
1061
1069
  this.msalConfig = this.defaultNodeMsalConfig(options);
1062
1070
  this.tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
@@ -1067,7 +1075,10 @@ class MsalNode extends MsalBaseUtilities {
1067
1075
  }
1068
1076
  // If persistence has been configured
1069
1077
  if (persistenceProvider !== undefined && ((_b = options.tokenCachePersistenceOptions) === null || _b === void 0 ? void 0 : _b.enabled)) {
1070
- this.createCachePlugin = () => persistenceProvider(options.tokenCachePersistenceOptions);
1078
+ const nonCaeOptions = Object.assign({ name: `${options.tokenCachePersistenceOptions.name}.${CACHE_NON_CAE_SUFFIX}` }, options.tokenCachePersistenceOptions);
1079
+ const caeOptions = Object.assign({ name: `${options.tokenCachePersistenceOptions.name}.${CACHE_CAE_SUFFIX}` }, options.tokenCachePersistenceOptions);
1080
+ this.createCachePlugin = () => persistenceProvider(nonCaeOptions);
1081
+ this.createCachePluginCae = () => persistenceProvider(caeOptions);
1071
1082
  }
1072
1083
  else if ((_c = options.tokenCachePersistenceOptions) === null || _c === void 0 ? void 0 : _c.enabled) {
1073
1084
  throw new Error([
@@ -1086,15 +1097,13 @@ class MsalNode extends MsalBaseUtilities {
1086
1097
  * Generates a MSAL configuration that generally works for Node.js
1087
1098
  */
1088
1099
  defaultNodeMsalConfig(options) {
1100
+ var _a;
1089
1101
  const clientId = options.clientId || DeveloperSignOnClientId;
1090
1102
  const tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
1091
1103
  this.authorityHost = options.authorityHost || process.env.AZURE_AUTHORITY_HOST;
1092
1104
  const authority = getAuthority(tenantId, this.authorityHost);
1093
1105
  this.identityClient = new IdentityClient(Object.assign(Object.assign({}, options.tokenCredentialOptions), { authorityHost: authority, loggingOptions: options.loggingOptions }));
1094
- let clientCapabilities = ["cp1"];
1095
- if (process.env.AZURE_IDENTITY_DISABLE_CP1) {
1096
- clientCapabilities = [];
1097
- }
1106
+ const clientCapabilities = [];
1098
1107
  return {
1099
1108
  auth: {
1100
1109
  clientId,
@@ -1108,10 +1117,26 @@ class MsalNode extends MsalBaseUtilities {
1108
1117
  loggerOptions: {
1109
1118
  loggerCallback: defaultLoggerCallback(options.logger),
1110
1119
  logLevel: getMSALLogLevel(logger$o.getLogLevel()),
1120
+ piiLoggingEnabled: (_a = options.loggingOptions) === null || _a === void 0 ? void 0 : _a.enableUnsafeSupportLogging,
1111
1121
  },
1112
1122
  },
1113
1123
  };
1114
1124
  }
1125
+ getApp(appType, enableCae) {
1126
+ const app = enableCae ? this.caeApp : this.app;
1127
+ if (appType === "publicFirst") {
1128
+ return (app.public || app.confidential);
1129
+ }
1130
+ else if (appType === "confidentialFirst") {
1131
+ return (app.confidential || app.public);
1132
+ }
1133
+ else if (appType === "confidential") {
1134
+ return app.confidential;
1135
+ }
1136
+ else {
1137
+ return app.public;
1138
+ }
1139
+ }
1115
1140
  /**
1116
1141
  * Prepares the MSAL applications.
1117
1142
  */
@@ -1123,15 +1148,29 @@ class MsalNode extends MsalBaseUtilities {
1123
1148
  this.identityClient.abortRequests(options.correlationId);
1124
1149
  });
1125
1150
  }
1126
- if (this.publicApp || this.confidentialApp) {
1151
+ const app = (options === null || options === void 0 ? void 0 : options.enableCae) ? this.caeApp : this.app;
1152
+ if (options === null || options === void 0 ? void 0 : options.enableCae) {
1153
+ this.msalConfig.auth.clientCapabilities = ["cp1"];
1154
+ }
1155
+ if (app.public || app.confidential) {
1127
1156
  return;
1128
1157
  }
1158
+ if ((options === null || options === void 0 ? void 0 : options.enableCae) && this.createCachePluginCae !== undefined) {
1159
+ this.msalConfig.cache = {
1160
+ cachePlugin: await this.createCachePluginCae(),
1161
+ };
1162
+ }
1129
1163
  if (this.createCachePlugin !== undefined) {
1130
1164
  this.msalConfig.cache = {
1131
1165
  cachePlugin: await this.createCachePlugin(),
1132
1166
  };
1133
1167
  }
1134
- this.publicApp = new msalNode__namespace.PublicClientApplication(this.msalConfig);
1168
+ if (options === null || options === void 0 ? void 0 : options.enableCae) {
1169
+ this.caeApp.public = new msalNode__namespace.PublicClientApplication(this.msalConfig);
1170
+ }
1171
+ else {
1172
+ this.app.public = new msalNode__namespace.PublicClientApplication(this.msalConfig);
1173
+ }
1135
1174
  if (this.getAssertion) {
1136
1175
  this.msalConfig.auth.clientAssertion = await this.getAssertion();
1137
1176
  }
@@ -1139,7 +1178,12 @@ class MsalNode extends MsalBaseUtilities {
1139
1178
  if (this.msalConfig.auth.clientSecret ||
1140
1179
  this.msalConfig.auth.clientAssertion ||
1141
1180
  this.msalConfig.auth.clientCertificate) {
1142
- this.confidentialApp = new msalNode__namespace.ConfidentialClientApplication(this.msalConfig);
1181
+ if (options === null || options === void 0 ? void 0 : options.enableCae) {
1182
+ this.caeApp.confidential = new msalNode__namespace.ConfidentialClientApplication(this.msalConfig);
1183
+ }
1184
+ else {
1185
+ this.app.confidential = new msalNode__namespace.ConfidentialClientApplication(this.msalConfig);
1186
+ }
1143
1187
  }
1144
1188
  else {
1145
1189
  if (this.requiresConfidential) {
@@ -1167,12 +1211,11 @@ class MsalNode extends MsalBaseUtilities {
1167
1211
  /**
1168
1212
  * Returns the existing account, attempts to load the account from MSAL.
1169
1213
  */
1170
- async getActiveAccount() {
1171
- var _a, _b, _c;
1214
+ async getActiveAccount(enableCae = false) {
1172
1215
  if (this.account) {
1173
1216
  return this.account;
1174
1217
  }
1175
- const cache = (_b = (_a = this.confidentialApp) === null || _a === void 0 ? void 0 : _a.getTokenCache()) !== null && _b !== void 0 ? _b : (_c = this.publicApp) === null || _c === void 0 ? void 0 : _c.getTokenCache();
1218
+ const cache = this.getApp("confidentialFirst", enableCae).getTokenCache();
1176
1219
  const accountsByTenant = await (cache === null || cache === void 0 ? void 0 : cache.getAllAccounts());
1177
1220
  if (!accountsByTenant) {
1178
1221
  return;
@@ -1196,7 +1239,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1196
1239
  */
1197
1240
  async getTokenSilent(scopes, options) {
1198
1241
  var _a, _b, _c;
1199
- await this.getActiveAccount();
1242
+ await this.getActiveAccount(options === null || options === void 0 ? void 0 : options.enableCae);
1200
1243
  if (!this.account) {
1201
1244
  throw new AuthenticationRequiredError({
1202
1245
  scopes,
@@ -1218,10 +1261,10 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1218
1261
  * The following code to retrieve all accounts is done as a workaround in an attempt to force the
1219
1262
  * refresh of the token cache with the token and the account passed in through the
1220
1263
  * `authenticationRecord` parameter. See issue - https://github.com/Azure/azure-sdk-for-js/issues/24349#issuecomment-1496715651
1221
- * This workaround serves as a workoaround for silent authentication not happening when authenticationRecord is passed.
1264
+ * This workaround serves as a workaround for silent authentication not happening when authenticationRecord is passed.
1222
1265
  */
1223
- await ((_a = (this.publicApp || this.confidentialApp)) === null || _a === void 0 ? void 0 : _a.getTokenCache().getAllAccounts());
1224
- const response = (_c = (await ((_b = this.confidentialApp) === null || _b === void 0 ? void 0 : _b.acquireTokenSilent(silentRequest)))) !== null && _c !== void 0 ? _c : (await this.publicApp.acquireTokenSilent(silentRequest));
1266
+ await ((_a = this.getApp("publicFirst", options === null || options === void 0 ? void 0 : options.enableCae)) === null || _a === void 0 ? void 0 : _a.getTokenCache().getAllAccounts());
1267
+ 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));
1225
1268
  return this.handleResult(scopes, this.clientId, response || undefined);
1226
1269
  }
1227
1270
  catch (err) {
@@ -1884,7 +1927,7 @@ class MsalClientAssertion extends MsalNode {
1884
1927
  async doGetToken(scopes, options = {}) {
1885
1928
  try {
1886
1929
  const assertion = await this.getAssertion();
1887
- const result = await this.confidentialApp.acquireTokenByClientCredential({
1930
+ const result = await this.getApp("confidential", options.enableCae).acquireTokenByClientCredential({
1888
1931
  scopes,
1889
1932
  correlationId: options.correlationId,
1890
1933
  azureRegion: this.azureRegion,
@@ -2281,6 +2324,7 @@ class ManagedIdentityCredential {
2281
2324
  clientSecret: "dummy-secret",
2282
2325
  cloudDiscoveryMetadata: '{"tenant_discovery_endpoint":"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration","api-version":"1.1","metadata":[{"preferred_network":"login.microsoftonline.com","preferred_cache":"login.windows.net","aliases":["login.microsoftonline.com","login.windows.net","login.microsoft.com","sts.windows.net"]},{"preferred_network":"login.partner.microsoftonline.cn","preferred_cache":"login.partner.microsoftonline.cn","aliases":["login.partner.microsoftonline.cn","login.chinacloudapi.cn"]},{"preferred_network":"login.microsoftonline.de","preferred_cache":"login.microsoftonline.de","aliases":["login.microsoftonline.de"]},{"preferred_network":"login.microsoftonline.us","preferred_cache":"login.microsoftonline.us","aliases":["login.microsoftonline.us","login.usgovcloudapi.net"]},{"preferred_network":"login-us.microsoftonline.com","preferred_cache":"login-us.microsoftonline.com","aliases":["login-us.microsoftonline.com"]}]}',
2283
2326
  authorityMetadata: '{"token_endpoint":"https://login.microsoftonline.com/common/oauth2/v2.0/token","token_endpoint_auth_methods_supported":["client_secret_post","private_key_jwt","client_secret_basic"],"jwks_uri":"https://login.microsoftonline.com/common/discovery/v2.0/keys","response_modes_supported":["query","fragment","form_post"],"subject_types_supported":["pairwise"],"id_token_signing_alg_values_supported":["RS256"],"response_types_supported":["code","id_token","code id_token","id_token token"],"scopes_supported":["openid","profile","email","offline_access"],"issuer":"https://login.microsoftonline.com/{tenantid}/v2.0","request_uri_parameter_supported":false,"userinfo_endpoint":"https://graph.microsoft.com/oidc/userinfo","authorization_endpoint":"https://login.microsoftonline.com/common/oauth2/v2.0/authorize","device_authorization_endpoint":"https://login.microsoftonline.com/common/oauth2/v2.0/devicecode","http_logout_supported":true,"frontchannel_logout_supported":true,"end_session_endpoint":"https://login.microsoftonline.com/common/oauth2/v2.0/logout","claims_supported":["sub","iss","cloud_instance_name","cloud_instance_host_name","cloud_graph_host_name","msgraph_host","aud","exp","iat","auth_time","acr","nonce","preferred_username","name","tid","ver","at_hash","c_hash","email"],"kerberos_endpoint":"https://login.microsoftonline.com/common/kerberos","tenant_region_scope":null,"cloud_instance_name":"microsoftonline.com","cloud_graph_host_name":"graph.windows.net","msgraph_host":"graph.microsoft.com","rbac_url":"https://pas.windows.net"}',
2327
+ clientCapabilities: [],
2284
2328
  },
2285
2329
  system: {
2286
2330
  loggerOptions: {
@@ -2526,7 +2570,7 @@ function ensureScopes(scopes) {
2526
2570
  * Throws if the received scope is not valid.
2527
2571
  * @internal
2528
2572
  */
2529
- function ensureValidScope(scope, logger) {
2573
+ function ensureValidScopeForDevTimeCreds(scope, logger) {
2530
2574
  if (!scope.match(/^[0-9a-zA-Z-.:/]+$/)) {
2531
2575
  const error = new Error("Invalid scope was specified by the user or calling client");
2532
2576
  logger.getToken.info(formatError(scope, error));
@@ -2624,11 +2668,11 @@ class AzureCliCredential {
2624
2668
  const tenantId = processMultiTenantRequest(this.tenantId, options, this.additionallyAllowedTenantIds);
2625
2669
  const scope = typeof scopes === "string" ? scopes : scopes[0];
2626
2670
  logger$b.getToken.info(`Using the scope ${scope}`);
2627
- ensureValidScope(scope, logger$b);
2628
- const resource = getScopeResource(scope);
2629
2671
  return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async () => {
2630
2672
  var _a, _b, _c, _d;
2631
2673
  try {
2674
+ ensureValidScopeForDevTimeCreds(scope, logger$b);
2675
+ const resource = getScopeResource(scope);
2632
2676
  const obj = await cliCredentialInternals.getAzureCliAccessToken(resource, tenantId, this.timeout);
2633
2677
  const specificScope = (_a = obj.stderr) === null || _a === void 0 ? void 0 : _a.match("(.*)az login --scope(.*)");
2634
2678
  const isLoginError = ((_b = obj.stderr) === null || _b === void 0 ? void 0 : _b.match("(.*)az login(.*)")) && !specificScope;
@@ -2838,10 +2882,10 @@ class AzurePowerShellCredential {
2838
2882
  return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async () => {
2839
2883
  const tenantId = processMultiTenantRequest(this.tenantId, options, this.additionallyAllowedTenantIds);
2840
2884
  const scope = typeof scopes === "string" ? scopes : scopes[0];
2841
- ensureValidScope(scope, logger$a);
2842
- logger$a.getToken.info(`Using the scope ${scope}`);
2843
- const resource = getScopeResource(scope);
2844
2885
  try {
2886
+ ensureValidScopeForDevTimeCreds(scope, logger$a);
2887
+ logger$a.getToken.info(`Using the scope ${scope}`);
2888
+ const resource = getScopeResource(scope);
2845
2889
  const response = await this.getAzurePowerShellAccessToken(resource, tenantId, this.timeout);
2846
2890
  logger$a.getToken.info(formatSuccess(scopes));
2847
2891
  return {
@@ -3039,7 +3083,7 @@ class MsalClientCertificate extends MsalNode {
3039
3083
  authority: options.authority,
3040
3084
  claims: options.claims,
3041
3085
  };
3042
- const result = await this.confidentialApp.acquireTokenByClientCredential(clientCredReq);
3086
+ const result = await this.getApp("confidential", options.enableCae).acquireTokenByClientCredential(clientCredReq);
3043
3087
  // Even though we're providing the same default in memory persistence cache that we use for DeviceCodeCredential,
3044
3088
  // The Client Credential flow does not return the account information from the authentication service,
3045
3089
  // so each time getToken gets called, we will have to acquire a new token through the service.
@@ -3118,7 +3162,7 @@ class MsalClientSecret extends MsalNode {
3118
3162
  }
3119
3163
  async doGetToken(scopes, options = {}) {
3120
3164
  try {
3121
- const result = await this.confidentialApp.acquireTokenByClientCredential({
3165
+ const result = await this.getApp("confidential", options.enableCae).acquireTokenByClientCredential({
3122
3166
  scopes,
3123
3167
  correlationId: options.correlationId,
3124
3168
  azureRegion: this.azureRegion,
@@ -3205,7 +3249,7 @@ class MsalUsernamePassword extends MsalNode {
3205
3249
  authority: options === null || options === void 0 ? void 0 : options.authority,
3206
3250
  claims: options === null || options === void 0 ? void 0 : options.claims,
3207
3251
  };
3208
- const result = await this.publicApp.acquireTokenByUsernamePassword(requestOptions);
3252
+ const result = await this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).acquireTokenByUsernamePassword(requestOptions);
3209
3253
  return this.handleResult(scopes, this.clientId, result || undefined);
3210
3254
  }
3211
3255
  catch (error) {
@@ -3656,8 +3700,8 @@ class MsalOpenBrowser extends MsalNode {
3656
3700
  }
3657
3701
  this.hostname = url.hostname;
3658
3702
  }
3659
- async acquireTokenByCode(request) {
3660
- return this.publicApp.acquireTokenByCode(request);
3703
+ async acquireTokenByCode(request, enableCae) {
3704
+ return this.getApp("public", enableCae).acquireTokenByCode(request);
3661
3705
  }
3662
3706
  doGetToken(scopes, options) {
3663
3707
  return new Promise((resolve, reject) => {
@@ -3683,7 +3727,7 @@ class MsalOpenBrowser extends MsalNode {
3683
3727
  authority: options === null || options === void 0 ? void 0 : options.authority,
3684
3728
  codeVerifier: (_a = this.pkceCodes) === null || _a === void 0 ? void 0 : _a.verifier,
3685
3729
  };
3686
- this.acquireTokenByCode(tokenRequest)
3730
+ this.acquireTokenByCode(tokenRequest, options === null || options === void 0 ? void 0 : options.enableCae)
3687
3731
  .then((authResponse) => {
3688
3732
  if (authResponse === null || authResponse === void 0 ? void 0 : authResponse.account) {
3689
3733
  this.account = msalToPublic(this.clientId, authResponse.account);
@@ -3779,7 +3823,7 @@ class MsalOpenBrowser extends MsalNode {
3779
3823
  codeChallenge: this.pkceCodes.challenge,
3780
3824
  codeChallengeMethod: "S256", // Use SHA256 Algorithm
3781
3825
  };
3782
- const response = await this.publicApp.getAuthCodeUrl(authCodeUrlParameters);
3826
+ const response = await this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).getAuthCodeUrl(authCodeUrlParameters);
3783
3827
  try {
3784
3828
  // A new instance on macOS only which allows it to not hang, does not fix the issue on linux
3785
3829
  await interactiveBrowserMockable.open(response, { wait: true, newInstance: true });
@@ -3880,7 +3924,7 @@ class MsalDeviceCode extends MsalNode {
3880
3924
  authority: options === null || options === void 0 ? void 0 : options.authority,
3881
3925
  claims: options === null || options === void 0 ? void 0 : options.claims,
3882
3926
  };
3883
- const promise = this.publicApp.acquireTokenByDeviceCode(requestOptions);
3927
+ const promise = this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).acquireTokenByDeviceCode(requestOptions);
3884
3928
  const deviceResponse = await this.withCancellation(promise, options === null || options === void 0 ? void 0 : options.abortSignal, () => {
3885
3929
  requestOptions.cancel = true;
3886
3930
  });
@@ -3988,19 +4032,21 @@ class MsalAuthorizationCode extends MsalNode {
3988
4032
  }
3989
4033
  async getAuthCodeUrl(options) {
3990
4034
  await this.init();
3991
- return (this.confidentialApp || this.publicApp).getAuthCodeUrl(options);
4035
+ return this.getApp("confidentialFirst", options.enableCae).getAuthCodeUrl({
4036
+ scopes: options.scopes,
4037
+ redirectUri: options.redirectUri,
4038
+ });
3992
4039
  }
3993
4040
  async doGetToken(scopes, options) {
3994
- var _a;
3995
4041
  try {
3996
- const result = await ((_a = (this.confidentialApp || this.publicApp)) === null || _a === void 0 ? void 0 : _a.acquireTokenByCode({
4042
+ const result = await this.getApp("confidentialFirst", options === null || options === void 0 ? void 0 : options.enableCae).acquireTokenByCode({
3997
4043
  scopes,
3998
4044
  redirectUri: this.redirectUri,
3999
4045
  code: this.authorizationCode,
4000
4046
  correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
4001
4047
  authority: options === null || options === void 0 ? void 0 : options.authority,
4002
4048
  claims: options === null || options === void 0 ? void 0 : options.claims,
4003
- }));
4049
+ });
4004
4050
  // The Client Credential flow does not return an account,
4005
4051
  // so each time getToken gets called, we will have to acquire a new token through the service.
4006
4052
  return this.handleResult(scopes, this.clientId, result || undefined);
@@ -4104,7 +4150,7 @@ class MsalOnBehalfOf extends MsalNode {
4104
4150
  }
4105
4151
  async doGetToken(scopes, options = {}) {
4106
4152
  try {
4107
- const result = await this.confidentialApp.acquireTokenOnBehalfOf({
4153
+ const result = await this.getApp("confidential", options.enableCae).acquireTokenOnBehalfOf({
4108
4154
  scopes,
4109
4155
  correlationId: options.correlationId,
4110
4156
  authority: options.authority,