@azure/identity 3.2.4 → 3.3.0-alpha.20230811.1
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.
- package/README.md +27 -10
- package/dist/index.js +82 -36
- package/dist/index.js.map +1 -1
- package/dist-esm/src/constants.js +3 -1
- package/dist-esm/src/constants.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredential.js +3 -3
- package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.js +4 -4
- package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js +1 -0
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js +2 -0
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist-esm/src/msal/credentials.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js +6 -4
- package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientSecret.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientSecret.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js +57 -16
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js +4 -4
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js.map +1 -1
- package/dist-esm/src/msal/types.js.map +1 -1
- package/dist-esm/src/tokenCredentialOptions.js.map +1 -1
- package/dist-esm/src/util/scopeUtils.js +1 -1
- package/dist-esm/src/util/scopeUtils.js.map +1 -1
- package/package.json +8 -8
- package/types/identity.d.ts +8 -1
package/README.md
CHANGED
|
@@ -161,10 +161,10 @@ This example demonstrates authenticating the `KeyClient` from the [@azure/keyvau
|
|
|
161
161
|
// If environment configuration is incomplete, it will try managed identity.
|
|
162
162
|
|
|
163
163
|
// Azure Key Vault service to use
|
|
164
|
-
|
|
164
|
+
import { KeyClient } from "@azure/keyvault-keys";
|
|
165
165
|
|
|
166
166
|
// Azure authentication library to access Azure Key Vault
|
|
167
|
-
|
|
167
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
168
168
|
|
|
169
169
|
// Azure SDK clients accept the credential as a parameter
|
|
170
170
|
const credential = new DefaultAzureCredential();
|
|
@@ -181,8 +181,8 @@ A relatively common scenario involves authenticating using a user-assigned manag
|
|
|
181
181
|
|
|
182
182
|
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
183
|
|
|
184
|
-
```
|
|
185
|
-
|
|
184
|
+
```typescript
|
|
185
|
+
import { ClientSecretCredential, ChainedTokenCredential } from "@azure/identity";
|
|
186
186
|
|
|
187
187
|
// When an access token is requested, the chain will try each
|
|
188
188
|
// credential in order, stopping when one provides a token
|
|
@@ -191,7 +191,7 @@ const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, a
|
|
|
191
191
|
const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);
|
|
192
192
|
|
|
193
193
|
// The chain can be used anywhere a credential is required
|
|
194
|
-
|
|
194
|
+
import { KeyClient } from "@azure/keyvault-keys";
|
|
195
195
|
const client = new KeyClient(vaultUrl, credentialChain);
|
|
196
196
|
```
|
|
197
197
|
|
|
@@ -213,7 +213,7 @@ For examples of how to use managed identity for authentication, see [the example
|
|
|
213
213
|
|
|
214
214
|
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
215
|
|
|
216
|
-
```
|
|
216
|
+
```typescript
|
|
217
217
|
import { AzureAuthorityHosts, ClientSecretCredential } from "@azure/identity";
|
|
218
218
|
const credential = new ClientSecretCredential(
|
|
219
219
|
"<YOUR_TENANT_ID>",
|
|
@@ -237,7 +237,7 @@ Not all credentials require this configuration. Credentials that authenticate th
|
|
|
237
237
|
| [`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
238
|
| [`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
239
|
| [`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
|
-
|
|
240
|
+
| [`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
241
|
|
|
242
242
|
### Authenticate service principals
|
|
243
243
|
|
|
@@ -261,8 +261,8 @@ Not all credentials require this configuration. Credentials that authenticate th
|
|
|
261
261
|
|
|
262
262
|
| Credential | Usage | Example | Reference |
|
|
263
263
|
| ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
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
264
|
| [`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) |
|
|
265
|
+
| [`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
266
|
| [`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
267
|
| [`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
268
|
|
|
@@ -299,7 +299,9 @@ Not all credentials require this configuration. Credentials that authenticate th
|
|
|
299
299
|
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
300
|
|
|
301
301
|
## Token caching
|
|
302
|
+
|
|
302
303
|
Token caching is a feature provided by the Azure Identity library that allows apps to:
|
|
304
|
+
|
|
303
305
|
- Cache tokens in memory (default) and on disk (opt-in).
|
|
304
306
|
- Improve resilience and performance.
|
|
305
307
|
- Reduce the number of requests made to Azure AD to obtain access tokens.
|
|
@@ -325,7 +327,7 @@ require("dotenv").config({ path: ".env" });
|
|
|
325
327
|
|
|
326
328
|
Alternatively, logging can be enabled at runtime by calling `setLogLevel` from the `@azure/logger` package:
|
|
327
329
|
|
|
328
|
-
```
|
|
330
|
+
```typescript
|
|
329
331
|
import { setLogLevel } from "@azure/logger";
|
|
330
332
|
|
|
331
333
|
setLogLevel("info");
|
|
@@ -340,7 +342,7 @@ Object ID of the authenticated user, and if possible the User Principal Name.
|
|
|
340
342
|
|
|
341
343
|
For example, using the `DefaultAzureCredential`:
|
|
342
344
|
|
|
343
|
-
```
|
|
345
|
+
```ts
|
|
344
346
|
import { setLogLevel } from "@azure/logger";
|
|
345
347
|
|
|
346
348
|
setLogLevel("info");
|
|
@@ -356,6 +358,21 @@ Once that credential authenticates, the following message will appear in the log
|
|
|
356
358
|
azure:identity:info [Authenticated account] Client ID: HIDDEN. Tenant ID: HIDDEN. User Principal Name: HIDDEN. Object ID (user): HIDDEN
|
|
357
359
|
```
|
|
358
360
|
|
|
361
|
+
In cases where the user's [Personally Identifiable Information](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/PII) needs to be logged for customer support, developers can set `enableSupportLogging` to true in the
|
|
362
|
+
`loggingOptions`.
|
|
363
|
+
|
|
364
|
+
For example, using the `DefaultAzureCredential`:
|
|
365
|
+
|
|
366
|
+
```ts
|
|
367
|
+
import { setLogLevel } from "@azure/logger";
|
|
368
|
+
|
|
369
|
+
setLogLevel("info");
|
|
370
|
+
|
|
371
|
+
const credential = new DefaultAzureCredential({
|
|
372
|
+
loggingOptions: { enableSupportLogging: true },
|
|
373
|
+
});
|
|
374
|
+
```
|
|
375
|
+
|
|
359
376
|
For assistance with troubleshooting, see the [troubleshooting guide](https://aka.ms/azsdk/js/identity/troubleshoot).
|
|
360
377
|
|
|
361
378
|
## 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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
1264
|
+
* This workaround serves as a workaround for silent authentication not happening when authenticationRecord is passed.
|
|
1222
1265
|
*/
|
|
1223
|
-
await ((_a =
|
|
1224
|
-
const response = (_c = (await ((_b = this.
|
|
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.
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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.
|
|
4153
|
+
const result = await this.getApp("confidential", options.enableCae).acquireTokenOnBehalfOf({
|
|
4108
4154
|
scopes,
|
|
4109
4155
|
correlationId: options.correlationId,
|
|
4110
4156
|
authority: options.authority,
|