@azure/identity-cache-persistence 1.1.2-alpha.20240702.3 → 1.1.2-alpha.20240813.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/index.js +1 -1
  2. package/dist-esm/identity/src/client/identityClient.js +8 -2
  3. package/dist-esm/identity/src/client/identityClient.js.map +1 -1
  4. package/dist-esm/identity/src/constants.js +1 -1
  5. package/dist-esm/identity/src/constants.js.map +1 -1
  6. package/dist-esm/identity/src/credentials/azurePipelinesCredential.js +52 -28
  7. package/dist-esm/identity/src/credentials/azurePipelinesCredential.js.map +1 -1
  8. package/dist-esm/identity/src/credentials/azurePowerShellCredential.js +65 -19
  9. package/dist-esm/identity/src/credentials/azurePowerShellCredential.js.map +1 -1
  10. package/dist-esm/identity/src/credentials/clientAssertionCredential.js +9 -2
  11. package/dist-esm/identity/src/credentials/clientAssertionCredential.js.map +1 -1
  12. package/dist-esm/identity/src/credentials/clientCertificateCredential.js +38 -30
  13. package/dist-esm/identity/src/credentials/clientCertificateCredential.js.map +1 -1
  14. package/dist-esm/identity/src/credentials/clientSecretCredential.js +9 -2
  15. package/dist-esm/identity/src/credentials/clientSecretCredential.js.map +1 -1
  16. package/dist-esm/identity/src/credentials/deviceCodeCredential.js +1 -1
  17. package/dist-esm/identity/src/credentials/deviceCodeCredential.js.map +1 -1
  18. package/dist-esm/identity/src/credentials/deviceCodeCredentialOptions.js.map +1 -1
  19. package/dist-esm/identity/src/credentials/environmentCredential.js +11 -1
  20. package/dist-esm/identity/src/credentials/environmentCredential.js.map +1 -1
  21. package/dist-esm/identity/src/credentials/interactiveBrowserCredential.js +1 -1
  22. package/dist-esm/identity/src/credentials/interactiveBrowserCredential.js.map +1 -1
  23. package/dist-esm/identity/src/credentials/interactiveBrowserCredentialOptions.js.map +1 -1
  24. package/dist-esm/identity/src/credentials/managedIdentityCredential/imdsMsi.js +3 -3
  25. package/dist-esm/identity/src/credentials/managedIdentityCredential/imdsRetryPolicy.js +37 -0
  26. package/dist-esm/identity/src/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -0
  27. package/dist-esm/identity/src/credentials/managedIdentityCredential/index.js +6 -2
  28. package/dist-esm/identity/src/credentials/managedIdentityCredential/index.js.map +1 -1
  29. package/dist-esm/identity/src/credentials/managedIdentityCredential/legacyMsiProvider.js +1 -1
  30. package/dist-esm/identity/src/credentials/managedIdentityCredential/legacyMsiProvider.js.map +1 -1
  31. package/dist-esm/identity/src/credentials/managedIdentityCredential/msalMsiProvider.js +198 -0
  32. package/dist-esm/identity/src/credentials/managedIdentityCredential/msalMsiProvider.js.map +1 -0
  33. package/dist-esm/identity/src/credentials/managedIdentityCredential/tokenExchangeMsi.js +23 -26
  34. package/dist-esm/identity/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  35. package/dist-esm/identity/src/credentials/onBehalfOfCredential.js +16 -9
  36. package/dist-esm/identity/src/credentials/onBehalfOfCredential.js.map +1 -1
  37. package/dist-esm/identity/src/credentials/usernamePasswordCredential.js +13 -3
  38. package/dist-esm/identity/src/credentials/usernamePasswordCredential.js.map +1 -1
  39. package/dist-esm/identity/src/credentials/workloadIdentityCredential.js +16 -6
  40. package/dist-esm/identity/src/credentials/workloadIdentityCredential.js.map +1 -1
  41. package/dist-esm/identity/src/errors.js +12 -7
  42. package/dist-esm/identity/src/errors.js.map +1 -1
  43. package/dist-esm/identity/src/msal/nodeFlows/msalClient.js +8 -1
  44. package/dist-esm/identity/src/msal/nodeFlows/msalClient.js.map +1 -1
  45. package/dist-esm/identity-cache-persistence/src/platforms.js +1 -1
  46. package/package.json +2 -2
  47. package/dist-esm/identity/src/msal/credentials.js +0 -4
  48. package/dist-esm/identity/src/msal/credentials.js.map +0 -1
  49. package/dist-esm/identity/src/msal/flows.js +0 -4
  50. package/dist-esm/identity/src/msal/flows.js.map +0 -1
  51. package/dist-esm/identity/src/msal/nodeFlows/msalNodeCommon.js +0 -332
  52. package/dist-esm/identity/src/msal/nodeFlows/msalNodeCommon.js.map +0 -1
  53. package/dist-esm/identity/src/msal/nodeFlows/msalOpenBrowser.js +0 -118
  54. package/dist-esm/identity/src/msal/nodeFlows/msalOpenBrowser.js.map +0 -1
@@ -1,332 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- import { __awaiter } from "tslib";
4
- import * as msalNode from "@azure/msal-node";
5
- import { CACHE_CAE_SUFFIX, CACHE_NON_CAE_SUFFIX, DEFAULT_TOKEN_CACHE_NAME, DeveloperSignOnClientId, } from "../../constants";
6
- import { formatSuccess } from "../../util/logging";
7
- import { defaultLoggerCallback, ensureValidMsalToken, getAuthority, getKnownAuthorities, getMSALLogLevel, handleMsalError, msalToPublic, publicToMsal, randomUUID, } from "../utils";
8
- import { hasNativeBroker, nativeBrokerInfo, persistenceProvider } from "./msalPlugins";
9
- import { processMultiTenantRequest, resolveAdditionallyAllowedTenantIds, resolveTenantId, } from "../../util/tenantIdUtils";
10
- import { AuthenticationRequiredError } from "../../errors";
11
- import { IdentityClient } from "../../client/identityClient";
12
- import { calculateRegionalAuthority } from "../../regionalAuthority";
13
- import { getLogLevel } from "@azure/logger";
14
- /**
15
- * MSAL partial base client for Node.js.
16
- *
17
- * It completes the input configuration with some default values.
18
- * It also provides with utility protected methods that can be used from any of the clients,
19
- * which includes handlers for successful responses and errors.
20
- *
21
- * @internal
22
- */
23
- export class MsalNode {
24
- constructor(options) {
25
- var _a, _b, _c, _d, _e, _f;
26
- this.app = {};
27
- this.caeApp = {};
28
- this.requiresConfidential = false;
29
- this.logger = options.logger;
30
- this.msalConfig = this.defaultNodeMsalConfig(options);
31
- this.tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
32
- this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds((_a = options === null || options === void 0 ? void 0 : options.tokenCredentialOptions) === null || _a === void 0 ? void 0 : _a.additionallyAllowedTenants);
33
- this.clientId = this.msalConfig.auth.clientId;
34
- if (options === null || options === void 0 ? void 0 : options.getAssertion) {
35
- this.getAssertion = options.getAssertion;
36
- }
37
- this.enableBroker = (_b = options === null || options === void 0 ? void 0 : options.brokerOptions) === null || _b === void 0 ? void 0 : _b.enabled;
38
- this.enableMsaPassthrough = (_c = options === null || options === void 0 ? void 0 : options.brokerOptions) === null || _c === void 0 ? void 0 : _c.legacyEnableMsaPassthrough;
39
- this.parentWindowHandle = (_d = options.brokerOptions) === null || _d === void 0 ? void 0 : _d.parentWindowHandle;
40
- // If persistence has been configured
41
- if (persistenceProvider !== undefined && ((_e = options.tokenCachePersistenceOptions) === null || _e === void 0 ? void 0 : _e.enabled)) {
42
- const cacheBaseName = options.tokenCachePersistenceOptions.name || DEFAULT_TOKEN_CACHE_NAME;
43
- const nonCaeOptions = Object.assign({ name: `${cacheBaseName}.${CACHE_NON_CAE_SUFFIX}` }, options.tokenCachePersistenceOptions);
44
- const caeOptions = Object.assign({ name: `${cacheBaseName}.${CACHE_CAE_SUFFIX}` }, options.tokenCachePersistenceOptions);
45
- this.createCachePlugin = () => persistenceProvider(nonCaeOptions);
46
- this.createCachePluginCae = () => persistenceProvider(caeOptions);
47
- }
48
- else if ((_f = options.tokenCachePersistenceOptions) === null || _f === void 0 ? void 0 : _f.enabled) {
49
- throw new Error([
50
- "Persistent token caching was requested, but no persistence provider was configured.",
51
- "You must install the identity-cache-persistence plugin package (`npm install --save @azure/identity-cache-persistence`)",
52
- "and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling",
53
- "`useIdentityPlugin(cachePersistencePlugin)` before using `tokenCachePersistenceOptions`.",
54
- ].join(" "));
55
- }
56
- // If broker has not been configured
57
- if (!hasNativeBroker() && this.enableBroker) {
58
- throw new Error([
59
- "Broker for WAM was requested to be enabled, but no native broker was configured.",
60
- "You must install the identity-broker plugin package (`npm install --save @azure/identity-broker`)",
61
- "and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling",
62
- "`useIdentityPlugin(createNativeBrokerPlugin())` before using `enableBroker`.",
63
- ].join(" "));
64
- }
65
- this.azureRegion = calculateRegionalAuthority(options.regionalAuthority);
66
- }
67
- /**
68
- * Generates a MSAL configuration that generally works for Node.js
69
- */
70
- defaultNodeMsalConfig(options) {
71
- var _a;
72
- const clientId = options.clientId || DeveloperSignOnClientId;
73
- const tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
74
- this.authorityHost = options.authorityHost || process.env.AZURE_AUTHORITY_HOST;
75
- const authority = getAuthority(tenantId, this.authorityHost);
76
- this.identityClient = new IdentityClient(Object.assign(Object.assign({}, options.tokenCredentialOptions), { authorityHost: authority, loggingOptions: options.loggingOptions }));
77
- const clientCapabilities = [];
78
- return {
79
- auth: {
80
- clientId,
81
- authority,
82
- knownAuthorities: getKnownAuthorities(tenantId, authority, options.disableInstanceDiscovery),
83
- clientCapabilities,
84
- },
85
- // Cache is defined in this.prepare();
86
- system: {
87
- networkClient: this.identityClient,
88
- loggerOptions: {
89
- loggerCallback: defaultLoggerCallback(options.logger),
90
- logLevel: getMSALLogLevel(getLogLevel()),
91
- piiLoggingEnabled: (_a = options.loggingOptions) === null || _a === void 0 ? void 0 : _a.enableUnsafeSupportLogging,
92
- },
93
- },
94
- };
95
- }
96
- getApp(appType, enableCae) {
97
- const app = enableCae ? this.caeApp : this.app;
98
- if (appType === "publicFirst") {
99
- return (app.public || app.confidential);
100
- }
101
- else if (appType === "confidentialFirst") {
102
- return (app.confidential || app.public);
103
- }
104
- else if (appType === "confidential") {
105
- return app.confidential;
106
- }
107
- else {
108
- return app.public;
109
- }
110
- }
111
- /**
112
- * Prepares the MSAL applications.
113
- */
114
- init(options) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- if (options === null || options === void 0 ? void 0 : options.abortSignal) {
117
- options.abortSignal.addEventListener("abort", () => {
118
- // This will abort any pending request in the IdentityClient,
119
- // based on the received or generated correlationId
120
- this.identityClient.abortRequests(options.correlationId);
121
- });
122
- }
123
- const app = (options === null || options === void 0 ? void 0 : options.enableCae) ? this.caeApp : this.app;
124
- if (options === null || options === void 0 ? void 0 : options.enableCae) {
125
- this.msalConfig.auth.clientCapabilities = ["cp1"];
126
- }
127
- if (app.public || app.confidential) {
128
- return;
129
- }
130
- if ((options === null || options === void 0 ? void 0 : options.enableCae) && this.createCachePluginCae !== undefined) {
131
- this.msalConfig.cache = {
132
- cachePlugin: yield this.createCachePluginCae(),
133
- };
134
- }
135
- if (this.createCachePlugin !== undefined) {
136
- this.msalConfig.cache = {
137
- cachePlugin: yield this.createCachePlugin(),
138
- };
139
- }
140
- if (hasNativeBroker() && this.enableBroker) {
141
- this.msalConfig.broker = {
142
- nativeBrokerPlugin: nativeBrokerInfo.broker,
143
- };
144
- if (!this.parentWindowHandle) {
145
- // error should have been thrown from within the constructor of InteractiveBrowserCredential
146
- this.logger.warning("Parent window handle is not specified for the broker. This may cause unexpected behavior. Please provide the parentWindowHandle.");
147
- }
148
- }
149
- if (options === null || options === void 0 ? void 0 : options.enableCae) {
150
- this.caeApp.public = new msalNode.PublicClientApplication(this.msalConfig);
151
- }
152
- else {
153
- this.app.public = new msalNode.PublicClientApplication(this.msalConfig);
154
- }
155
- // write a test so that user callback is invoked just once and the second time the token is cached and user callback not called
156
- //
157
- if (this.getAssertion !== undefined) {
158
- this.msalConfig.auth.clientAssertion = this.getAssertion;
159
- }
160
- // The confidential client requires either a secret, assertion or certificate.
161
- if (this.msalConfig.auth.clientSecret ||
162
- this.msalConfig.auth.clientAssertion ||
163
- this.msalConfig.auth.clientCertificate) {
164
- if (options === null || options === void 0 ? void 0 : options.enableCae) {
165
- this.caeApp.confidential = new msalNode.ConfidentialClientApplication(this.msalConfig);
166
- }
167
- else {
168
- this.app.confidential = new msalNode.ConfidentialClientApplication(this.msalConfig);
169
- }
170
- }
171
- else {
172
- if (this.requiresConfidential) {
173
- throw new Error("Unable to generate the MSAL confidential client. Missing either the client's secret, certificate or assertion.");
174
- }
175
- }
176
- });
177
- }
178
- /**
179
- * Allows the cancellation of a MSAL request.
180
- */
181
- withCancellation(promise, abortSignal, onCancel) {
182
- return new Promise((resolve, reject) => {
183
- promise
184
- .then((msalToken) => {
185
- return resolve(msalToken);
186
- })
187
- .catch(reject);
188
- if (abortSignal) {
189
- abortSignal.addEventListener("abort", () => {
190
- onCancel === null || onCancel === void 0 ? void 0 : onCancel();
191
- });
192
- }
193
- });
194
- }
195
- /**
196
- * Returns the existing account, attempts to load the account from MSAL.
197
- */
198
- getActiveAccount() {
199
- return __awaiter(this, arguments, void 0, function* (enableCae = false) {
200
- if (this.account) {
201
- return this.account;
202
- }
203
- const cache = this.getApp("confidentialFirst", enableCae).getTokenCache();
204
- const accountsByTenant = yield (cache === null || cache === void 0 ? void 0 : cache.getAllAccounts());
205
- if (!accountsByTenant) {
206
- return;
207
- }
208
- if (accountsByTenant.length === 1) {
209
- this.account = msalToPublic(this.clientId, accountsByTenant[0]);
210
- }
211
- else {
212
- this.logger
213
- .info(`More than one account was found authenticated for this Client ID and Tenant ID.
214
- However, no "authenticationRecord" has been provided for this credential,
215
- therefore we're unable to pick between these accounts.
216
- A new login attempt will be requested, to ensure the correct account is picked.
217
- To work with multiple accounts for the same Client ID and Tenant ID, please provide an "authenticationRecord" when initializing a credential to prevent this from happening.`);
218
- return;
219
- }
220
- return this.account;
221
- });
222
- }
223
- /**
224
- * Attempts to retrieve a token from cache.
225
- */
226
- getTokenSilent(scopes, options) {
227
- return __awaiter(this, void 0, void 0, function* () {
228
- var _a, _b, _c;
229
- yield this.getActiveAccount(options === null || options === void 0 ? void 0 : options.enableCae);
230
- if (!this.account) {
231
- throw new AuthenticationRequiredError({
232
- scopes,
233
- getTokenOptions: options,
234
- message: "Silent authentication failed. We couldn't retrieve an active account from the cache.",
235
- });
236
- }
237
- const silentRequest = {
238
- // To be able to re-use the account, the Token Cache must also have been provided.
239
- account: publicToMsal(this.account),
240
- correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
241
- scopes,
242
- authority: options === null || options === void 0 ? void 0 : options.authority,
243
- claims: options === null || options === void 0 ? void 0 : options.claims,
244
- };
245
- if (hasNativeBroker() && this.enableBroker) {
246
- if (!silentRequest.tokenQueryParameters) {
247
- silentRequest.tokenQueryParameters = {};
248
- }
249
- if (!this.parentWindowHandle) {
250
- // error should have been thrown from within the constructor of InteractiveBrowserCredential
251
- this.logger.warning("Parent window handle is not specified for the broker. This may cause unexpected behavior. Please provide the parentWindowHandle.");
252
- }
253
- if (this.enableMsaPassthrough) {
254
- silentRequest.tokenQueryParameters["msal_request_type"] = "consumer_passthrough";
255
- }
256
- }
257
- try {
258
- this.logger.info("Attempting to acquire token silently");
259
- /**
260
- * The following code to retrieve all accounts is done as a workaround in an attempt to force the
261
- * refresh of the token cache with the token and the account passed in through the
262
- * `authenticationRecord` parameter. See issue - https://github.com/Azure/azure-sdk-for-js/issues/24349#issuecomment-1496715651
263
- * This workaround serves as a workaround for silent authentication not happening when authenticationRecord is passed.
264
- */
265
- yield ((_a = this.getApp("publicFirst", options === null || options === void 0 ? void 0 : options.enableCae)) === null || _a === void 0 ? void 0 : _a.getTokenCache().getAllAccounts());
266
- const response = (_c = (yield ((_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 : (yield this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).acquireTokenSilent(silentRequest));
267
- return this.handleResult(scopes, response || undefined);
268
- }
269
- catch (err) {
270
- throw handleMsalError(scopes, err, options);
271
- }
272
- });
273
- }
274
- /**
275
- * Wrapper around each MSAL flow get token operation: doGetToken.
276
- * If disableAutomaticAuthentication is sent through the constructor, it will prevent MSAL from requesting the user input.
277
- */
278
- getToken(scopes_1) {
279
- return __awaiter(this, arguments, void 0, function* (scopes, options = {}) {
280
- const tenantId = processMultiTenantRequest(this.tenantId, options, this.additionallyAllowedTenantIds) ||
281
- this.tenantId;
282
- options.authority = getAuthority(tenantId, this.authorityHost);
283
- options.correlationId = (options === null || options === void 0 ? void 0 : options.correlationId) || randomUUID();
284
- yield this.init(options);
285
- try {
286
- // MSAL now caches tokens based on their claims,
287
- // so now one has to keep track fo claims in order to retrieve the newer tokens from acquireTokenSilent
288
- // This update happened on PR: https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/4533
289
- const optionsClaims = options.claims;
290
- if (optionsClaims) {
291
- this.cachedClaims = optionsClaims;
292
- }
293
- if (this.cachedClaims && !optionsClaims) {
294
- options.claims = this.cachedClaims;
295
- }
296
- // We don't return the promise since we want to catch errors right here.
297
- return yield this.getTokenSilent(scopes, options);
298
- }
299
- catch (err) {
300
- if (err.name !== "AuthenticationRequiredError") {
301
- throw err;
302
- }
303
- if (options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication) {
304
- throw new AuthenticationRequiredError({
305
- scopes,
306
- getTokenOptions: options,
307
- message: "Automatic authentication has been disabled. You may call the authentication() method.",
308
- });
309
- }
310
- this.logger.info(`Silent authentication failed, falling back to interactive method.`);
311
- return this.doGetToken(scopes, options);
312
- }
313
- });
314
- }
315
- /**
316
- * Handles the MSAL authentication result.
317
- * If the result has an account, we update the local account reference.
318
- * If the token received is invalid, an error will be thrown depending on what's missing.
319
- */
320
- handleResult(scopes, result, getTokenOptions) {
321
- if (result === null || result === void 0 ? void 0 : result.account) {
322
- this.account = msalToPublic(this.clientId, result.account);
323
- }
324
- ensureValidMsalToken(scopes, result, getTokenOptions);
325
- this.logger.getToken.info(formatSuccess(scopes));
326
- return {
327
- token: result.accessToken,
328
- expiresOnTimestamp: result.expiresOn.getTime(),
329
- };
330
- }
331
- }
332
- //# sourceMappingURL=msalNodeCommon.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msalNodeCommon.js","sourceRoot":"","sources":["../../../../../../identity/src/msal/nodeFlows/msalNodeCommon.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAI7C,OAAO,EACL,gBAA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;oBAC/C,MAAM,GAAG,CAAC;gBACZ,CAAC;gBACD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,8BAA8B,EAAE,CAAC;oBAC5C,MAAM,IAAI,2BAA2B,CAAC;wBACpC,MAAM;wBACN,eAAe,EAAE,OAAO;wBACxB,OAAO,EACL,uFAAuF;qBAC1F,CAAC,CAAC;gBACL,CAAC;gBACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAC;gBACtF,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;KAAA;IAED;;;;OAIG;IACO,YAAY,CACpB,MAAyB,EACzB,MAAmB,EACnB,eAAiC;QAEjC,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7D,CAAC;QACD,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;QACjD,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,WAAW;YACzB,kBAAkB,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE;SAC/C,CAAC;IACJ,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as msalNode from \"@azure/msal-node\";\n\nimport { AccessToken, GetTokenOptions } from \"@azure/core-auth\";\nimport { AppType, AuthenticationRecord, MsalResult } from \"../types\";\nimport {\n CACHE_CAE_SUFFIX,\n CACHE_NON_CAE_SUFFIX,\n DEFAULT_TOKEN_CACHE_NAME,\n DeveloperSignOnClientId,\n} from \"../../constants\";\nimport { CredentialLogger, formatSuccess } from \"../../util/logging\";\nimport { MsalFlow, MsalFlowOptions } from \"../flows\";\nimport {\n defaultLoggerCallback,\n ensureValidMsalToken,\n getAuthority,\n getKnownAuthorities,\n getMSALLogLevel,\n handleMsalError,\n msalToPublic,\n publicToMsal,\n randomUUID,\n} from \"../utils\";\nimport { hasNativeBroker, nativeBrokerInfo, persistenceProvider } from \"./msalPlugins\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../../util/tenantIdUtils\";\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { AuthenticationRequiredError } from \"../../errors\";\nimport { BrokerOptions } from \"./brokerOptions\";\nimport { CredentialFlowGetTokenOptions } from \"../credentials\";\nimport { IdentityClient } from \"../../client/identityClient\";\nimport { LogPolicyOptions } from \"@azure/core-rest-pipeline\";\nimport { MultiTenantTokenCredentialOptions } from \"../../credentials/multiTenantTokenCredentialOptions\";\nimport { TokenCachePersistenceOptions } from \"./tokenCachePersistenceOptions\";\nimport { calculateRegionalAuthority } from \"../../regionalAuthority\";\nimport { getLogLevel } from \"@azure/logger\";\n\n/**\n * Union of the constructor parameters that all MSAL flow types for Node.\n * @internal\n */\nexport interface MsalNodeOptions extends MsalFlowOptions {\n tokenCachePersistenceOptions?: TokenCachePersistenceOptions;\n brokerOptions?: BrokerOptions;\n tokenCredentialOptions: MultiTenantTokenCredentialOptions;\n /**\n * Specifies a regional authority. Please refer to the {@link RegionalAuthority} type for the accepted values.\n * If {@link RegionalAuthority.AutoDiscoverRegion} is specified, we will try to discover the regional authority endpoint.\n * If the property is not specified, uses a non-regional authority endpoint.\n */\n regionalAuthority?: string;\n /**\n * Allows users to configure settings for logging policy options, allow logging account information and personally identifiable information for customer support.\n */\n loggingOptions?: LogPolicyOptions & {\n /**\n * Allows logging account information once the authentication flow succeeds.\n */\n allowLoggingAccountIdentifiers?: boolean;\n /**\n * Allows logging personally identifiable information for customer support.\n */\n enableUnsafeSupportLogging?: boolean;\n };\n}\nexport type ClientAssertionCallback = (config: ClientAssertionConfig) => Promise<string>;\n\nexport type ClientAssertionConfig = {\n clientId: string;\n tokenEndpoint?: string;\n};\n/**\n * MSAL partial base client for Node.js.\n *\n * It completes the input configuration with some default values.\n * It also provides with utility protected methods that can be used from any of the clients,\n * which includes handlers for successful responses and errors.\n *\n * @internal\n */\nexport abstract class MsalNode implements MsalFlow {\n private app: {\n public?: msalNode.PublicClientApplication;\n confidential?: msalNode.ConfidentialClientApplication;\n } = {};\n private caeApp: {\n public?: msalNode.PublicClientApplication;\n confidential?: msalNode.ConfidentialClientApplication;\n } = {};\n private account?: AuthenticationRecord;\n protected msalConfig: msalNode.Configuration;\n protected clientId: string;\n protected tenantId: string;\n protected additionallyAllowedTenantIds: string[];\n protected authorityHost?: string;\n protected identityClient?: IdentityClient;\n protected requiresConfidential: boolean = false;\n protected azureRegion?: string;\n protected createCachePlugin: (() => Promise<msalNode.ICachePlugin>) | undefined;\n protected createCachePluginCae: (() => Promise<msalNode.ICachePlugin>) | undefined;\n protected createNativeBrokerPlugin: (() => Promise<msalNode.INativeBrokerPlugin>) | undefined;\n protected enableMsaPassthrough?: boolean;\n protected parentWindowHandle?: Uint8Array;\n protected enableBroker?: boolean;\n protected logger: CredentialLogger;\n\n /**\n * MSAL currently caches the tokens depending on the claims used to retrieve them.\n * In cases like CAE, in which we use claims to update the tokens, trying to retrieve the token without the claims will yield the original token.\n * To ensure we always get the latest token, we have to keep track of the claims.\n */\n private cachedClaims: string | undefined;\n\n protected getAssertion?: () => Promise<string>;\n constructor(options: MsalNodeOptions) {\n this.logger = options.logger;\n this.msalConfig = this.defaultNodeMsalConfig(options);\n this.tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.tokenCredentialOptions?.additionallyAllowedTenants,\n );\n this.clientId = this.msalConfig.auth.clientId;\n if (options?.getAssertion) {\n this.getAssertion = options.getAssertion;\n }\n this.enableBroker = options?.brokerOptions?.enabled;\n this.enableMsaPassthrough = options?.brokerOptions?.legacyEnableMsaPassthrough;\n this.parentWindowHandle = options.brokerOptions?.parentWindowHandle;\n\n // If persistence has been configured\n if (persistenceProvider !== undefined && options.tokenCachePersistenceOptions?.enabled) {\n const cacheBaseName = options.tokenCachePersistenceOptions.name || DEFAULT_TOKEN_CACHE_NAME;\n const nonCaeOptions = {\n name: `${cacheBaseName}.${CACHE_NON_CAE_SUFFIX}`,\n ...options.tokenCachePersistenceOptions,\n };\n const caeOptions = {\n name: `${cacheBaseName}.${CACHE_CAE_SUFFIX}`,\n ...options.tokenCachePersistenceOptions,\n };\n this.createCachePlugin = () => persistenceProvider!(nonCaeOptions);\n this.createCachePluginCae = () => persistenceProvider!(caeOptions);\n } else if (options.tokenCachePersistenceOptions?.enabled) {\n throw new Error(\n [\n \"Persistent token caching was requested, but no persistence provider was configured.\",\n \"You must install the identity-cache-persistence plugin package (`npm install --save @azure/identity-cache-persistence`)\",\n \"and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling\",\n \"`useIdentityPlugin(cachePersistencePlugin)` before using `tokenCachePersistenceOptions`.\",\n ].join(\" \"),\n );\n }\n\n // If broker has not been configured\n if (!hasNativeBroker() && this.enableBroker) {\n throw new Error(\n [\n \"Broker for WAM was requested to be enabled, but no native broker was configured.\",\n \"You must install the identity-broker plugin package (`npm install --save @azure/identity-broker`)\",\n \"and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling\",\n \"`useIdentityPlugin(createNativeBrokerPlugin())` before using `enableBroker`.\",\n ].join(\" \"),\n );\n }\n\n this.azureRegion = calculateRegionalAuthority(options.regionalAuthority);\n }\n\n /**\n * Generates a MSAL configuration that generally works for Node.js\n */\n protected defaultNodeMsalConfig(options: MsalNodeOptions): msalNode.Configuration {\n const clientId = options.clientId || DeveloperSignOnClientId;\n const tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);\n\n this.authorityHost = options.authorityHost || process.env.AZURE_AUTHORITY_HOST;\n const authority = getAuthority(tenantId, this.authorityHost);\n\n this.identityClient = new IdentityClient({\n ...options.tokenCredentialOptions,\n authorityHost: authority,\n loggingOptions: options.loggingOptions,\n });\n\n const clientCapabilities: string[] = [];\n\n return {\n auth: {\n clientId,\n authority,\n knownAuthorities: getKnownAuthorities(\n tenantId,\n authority,\n options.disableInstanceDiscovery,\n ),\n clientCapabilities,\n },\n // Cache is defined in this.prepare();\n system: {\n networkClient: this.identityClient,\n loggerOptions: {\n loggerCallback: defaultLoggerCallback(options.logger),\n logLevel: getMSALLogLevel(getLogLevel()),\n piiLoggingEnabled: options.loggingOptions?.enableUnsafeSupportLogging,\n },\n },\n };\n }\n protected getApp(\n appType: \"publicFirst\" | \"confidentialFirst\",\n enableCae?: boolean,\n ): msalNode.ConfidentialClientApplication | msalNode.PublicClientApplication;\n protected getApp(appType: \"public\", enableCae?: boolean): msalNode.PublicClientApplication;\n\n protected getApp(\n appType: \"confidential\",\n enableCae?: boolean,\n ): msalNode.ConfidentialClientApplication;\n\n protected getApp(\n appType: AppType,\n enableCae?: boolean,\n ): msalNode.ConfidentialClientApplication | msalNode.PublicClientApplication {\n const app = enableCae ? this.caeApp : this.app;\n if (appType === \"publicFirst\") {\n return (app.public || app.confidential)!;\n } else if (appType === \"confidentialFirst\") {\n return (app.confidential || app.public)!;\n } else if (appType === \"confidential\") {\n return app.confidential!;\n } else {\n return app.public!;\n }\n }\n\n /**\n * Prepares the MSAL applications.\n */\n async init(options?: CredentialFlowGetTokenOptions): Promise<void> {\n if (options?.abortSignal) {\n options.abortSignal.addEventListener(\"abort\", () => {\n // This will abort any pending request in the IdentityClient,\n // based on the received or generated correlationId\n this.identityClient!.abortRequests(options.correlationId);\n });\n }\n\n const app = options?.enableCae ? this.caeApp : this.app;\n if (options?.enableCae) {\n this.msalConfig.auth.clientCapabilities = [\"cp1\"];\n }\n if (app.public || app.confidential) {\n return;\n }\n if (options?.enableCae && this.createCachePluginCae !== undefined) {\n this.msalConfig.cache = {\n cachePlugin: await this.createCachePluginCae(),\n };\n }\n if (this.createCachePlugin !== undefined) {\n this.msalConfig.cache = {\n cachePlugin: await this.createCachePlugin(),\n };\n }\n\n if (hasNativeBroker() && this.enableBroker) {\n this.msalConfig.broker = {\n nativeBrokerPlugin: nativeBrokerInfo!.broker,\n };\n if (!this.parentWindowHandle) {\n // error should have been thrown from within the constructor of InteractiveBrowserCredential\n this.logger.warning(\n \"Parent window handle is not specified for the broker. This may cause unexpected behavior. Please provide the parentWindowHandle.\",\n );\n }\n }\n\n if (options?.enableCae) {\n this.caeApp.public = new msalNode.PublicClientApplication(this.msalConfig);\n } else {\n this.app.public = new msalNode.PublicClientApplication(this.msalConfig);\n }\n\n // write a test so that user callback is invoked just once and the second time the token is cached and user callback not called\n //\n if (this.getAssertion !== undefined) {\n this.msalConfig.auth.clientAssertion = this.getAssertion;\n }\n // The confidential client requires either a secret, assertion or certificate.\n if (\n this.msalConfig.auth.clientSecret ||\n this.msalConfig.auth.clientAssertion ||\n this.msalConfig.auth.clientCertificate\n ) {\n if (options?.enableCae) {\n this.caeApp.confidential = new msalNode.ConfidentialClientApplication(this.msalConfig);\n } else {\n this.app.confidential = new msalNode.ConfidentialClientApplication(this.msalConfig);\n }\n } else {\n if (this.requiresConfidential) {\n throw new Error(\n \"Unable to generate the MSAL confidential client. Missing either the client's secret, certificate or assertion.\",\n );\n }\n }\n }\n\n /**\n * Allows the cancellation of a MSAL request.\n */\n protected withCancellation(\n promise: Promise<msalNode.AuthenticationResult | null>,\n abortSignal?: AbortSignalLike,\n onCancel?: () => void,\n ): Promise<msalNode.AuthenticationResult | null> {\n return new Promise((resolve, reject) => {\n promise\n .then((msalToken) => {\n return resolve(msalToken!);\n })\n .catch(reject);\n if (abortSignal) {\n abortSignal.addEventListener(\"abort\", () => {\n onCancel?.();\n });\n }\n });\n }\n\n /**\n * Returns the existing account, attempts to load the account from MSAL.\n */\n async getActiveAccount(enableCae = false): Promise<AuthenticationRecord | undefined> {\n if (this.account) {\n return this.account;\n }\n const cache = this.getApp(\"confidentialFirst\", enableCae).getTokenCache();\n const accountsByTenant = await cache?.getAllAccounts();\n\n if (!accountsByTenant) {\n return;\n }\n\n if (accountsByTenant.length === 1) {\n this.account = msalToPublic(this.clientId, accountsByTenant[0]);\n } else {\n this.logger\n .info(`More than one account was found authenticated for this Client ID and Tenant ID.\nHowever, no \"authenticationRecord\" has been provided for this credential,\ntherefore we're unable to pick between these accounts.\nA new login attempt will be requested, to ensure the correct account is picked.\nTo work with multiple accounts for the same Client ID and Tenant ID, please provide an \"authenticationRecord\" when initializing a credential to prevent this from happening.`);\n return;\n }\n\n return this.account;\n }\n\n /**\n * Attempts to retrieve a token from cache.\n */\n async getTokenSilent(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n await this.getActiveAccount(options?.enableCae);\n if (!this.account) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions: options,\n message:\n \"Silent authentication failed. We couldn't retrieve an active account from the cache.\",\n });\n }\n\n const silentRequest: msalNode.SilentFlowRequest = {\n // To be able to re-use the account, the Token Cache must also have been provided.\n account: publicToMsal(this.account),\n correlationId: options?.correlationId,\n scopes,\n authority: options?.authority,\n claims: options?.claims,\n };\n\n if (hasNativeBroker() && this.enableBroker) {\n if (!silentRequest.tokenQueryParameters) {\n silentRequest.tokenQueryParameters = {};\n }\n if (!this.parentWindowHandle) {\n // error should have been thrown from within the constructor of InteractiveBrowserCredential\n this.logger.warning(\n \"Parent window handle is not specified for the broker. This may cause unexpected behavior. Please provide the parentWindowHandle.\",\n );\n }\n if (this.enableMsaPassthrough) {\n silentRequest.tokenQueryParameters[\"msal_request_type\"] = \"consumer_passthrough\";\n }\n }\n\n try {\n this.logger.info(\"Attempting to acquire token silently\");\n /**\n * The following code to retrieve all accounts is done as a workaround in an attempt to force the\n * refresh of the token cache with the token and the account passed in through the\n * `authenticationRecord` parameter. See issue - https://github.com/Azure/azure-sdk-for-js/issues/24349#issuecomment-1496715651\n * This workaround serves as a workaround for silent authentication not happening when authenticationRecord is passed.\n */\n await this.getApp(\"publicFirst\", options?.enableCae)?.getTokenCache().getAllAccounts();\n const response =\n (await this.getApp(\"confidential\", options?.enableCae)?.acquireTokenSilent(\n silentRequest,\n )) ?? (await this.getApp(\"public\", options?.enableCae).acquireTokenSilent(silentRequest));\n return this.handleResult(scopes, response || undefined);\n } catch (err: any) {\n throw handleMsalError(scopes, err, options);\n }\n }\n\n /**\n * Attempts to retrieve an authenticated token from MSAL.\n */\n protected abstract doGetToken(scopes: string[], options?: GetTokenOptions): Promise<AccessToken>;\n\n /**\n * Wrapper around each MSAL flow get token operation: doGetToken.\n * If disableAutomaticAuthentication is sent through the constructor, it will prevent MSAL from requesting the user input.\n */\n public async getToken(\n scopes: string[],\n options: CredentialFlowGetTokenOptions = {},\n ): Promise<AccessToken> {\n const tenantId =\n processMultiTenantRequest(this.tenantId, options, this.additionallyAllowedTenantIds) ||\n this.tenantId;\n\n options.authority = getAuthority(tenantId, this.authorityHost);\n\n options.correlationId = options?.correlationId || randomUUID();\n await this.init(options);\n\n try {\n // MSAL now caches tokens based on their claims,\n // so now one has to keep track fo claims in order to retrieve the newer tokens from acquireTokenSilent\n // This update happened on PR: https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/4533\n const optionsClaims = (options as any).claims;\n if (optionsClaims) {\n this.cachedClaims = optionsClaims;\n }\n if (this.cachedClaims && !optionsClaims) {\n options.claims = this.cachedClaims;\n }\n // We don't return the promise since we want to catch errors right here.\n return await this.getTokenSilent(scopes, options);\n } catch (err: any) {\n if (err.name !== \"AuthenticationRequiredError\") {\n throw err;\n }\n if (options?.disableAutomaticAuthentication) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions: options,\n message:\n \"Automatic authentication has been disabled. You may call the authentication() method.\",\n });\n }\n this.logger.info(`Silent authentication failed, falling back to interactive method.`);\n return this.doGetToken(scopes, options);\n }\n }\n\n /**\n * Handles the MSAL authentication result.\n * If the result has an account, we update the local account reference.\n * If the token received is invalid, an error will be thrown depending on what's missing.\n */\n protected handleResult(\n scopes: string | string[],\n result?: MsalResult,\n getTokenOptions?: GetTokenOptions,\n ): AccessToken {\n if (result?.account) {\n this.account = msalToPublic(this.clientId, result.account);\n }\n ensureValidMsalToken(scopes, result, getTokenOptions);\n this.logger.getToken.info(formatSuccess(scopes));\n return {\n token: result.accessToken,\n expiresOnTimestamp: result.expiresOn.getTime(),\n };\n }\n}\n"]}
@@ -1,118 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT license.
3
- import { __awaiter } from "tslib";
4
- import { MsalNode } from "./msalNodeCommon";
5
- import { credentialLogger } from "../../util/logging";
6
- import { handleMsalError } from "../utils";
7
- import { hasNativeBroker } from "./msalPlugins";
8
- import open from "open";
9
- /**
10
- * A call to open(), but mockable
11
- * @internal
12
- */
13
- export const interactiveBrowserMockable = {
14
- open,
15
- };
16
- /**
17
- * This MSAL client sets up a web server to listen for redirect callbacks, then calls to the MSAL's public application's `acquireTokenByDeviceCode` during `doGetToken`
18
- * to trigger the authentication flow, and then respond based on the values obtained from the redirect callback
19
- * @internal
20
- */
21
- export class MsalOpenBrowser extends MsalNode {
22
- constructor(options) {
23
- var _a, _b, _c, _d;
24
- super(options);
25
- this.loginHint = options.loginHint;
26
- this.errorTemplate = (_a = options.browserCustomizationOptions) === null || _a === void 0 ? void 0 : _a.errorMessage;
27
- this.successTemplate = (_b = options.browserCustomizationOptions) === null || _b === void 0 ? void 0 : _b.successMessage;
28
- this.logger = credentialLogger("Node.js MSAL Open Browser");
29
- this.useDefaultBrokerAccount =
30
- ((_c = options.brokerOptions) === null || _c === void 0 ? void 0 : _c.enabled) && ((_d = options.brokerOptions) === null || _d === void 0 ? void 0 : _d.useDefaultBrokerAccount);
31
- }
32
- doGetToken(scopes_1) {
33
- return __awaiter(this, arguments, void 0, function* (scopes, options = {}) {
34
- try {
35
- const interactiveRequest = {
36
- openBrowser: (url) => __awaiter(this, void 0, void 0, function* () {
37
- yield interactiveBrowserMockable.open(url, { wait: true, newInstance: true });
38
- }),
39
- scopes,
40
- authority: options === null || options === void 0 ? void 0 : options.authority,
41
- claims: options === null || options === void 0 ? void 0 : options.claims,
42
- correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
43
- loginHint: this.loginHint,
44
- errorTemplate: this.errorTemplate,
45
- successTemplate: this.successTemplate,
46
- };
47
- if (hasNativeBroker() && this.enableBroker) {
48
- return this.doGetBrokeredToken(scopes, interactiveRequest, {
49
- enableCae: options.enableCae,
50
- useDefaultBrokerAccount: this.useDefaultBrokerAccount,
51
- });
52
- }
53
- // If the broker is not enabled, we will fall back to interactive authentication
54
- if (hasNativeBroker() && !this.enableBroker) {
55
- this.logger.verbose("Authentication will resume normally without the broker, since it's not enabled");
56
- }
57
- const result = yield this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).acquireTokenInteractive(interactiveRequest);
58
- return this.handleResult(scopes, result || undefined);
59
- }
60
- catch (err) {
61
- throw handleMsalError(scopes, err, options);
62
- }
63
- });
64
- }
65
- /**
66
- * A helper function that supports brokered authentication through the MSAL's public application.
67
- *
68
- * When options.useDefaultBrokerAccount is true, the method will attempt to authenticate using the default broker account.
69
- * If the default broker account is not available, the method will fall back to interactive authentication.
70
- */
71
- doGetBrokeredToken(scopes, interactiveRequest, options) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- var _a;
74
- this.logger.verbose("Authentication will resume through the broker");
75
- if (this.parentWindowHandle) {
76
- interactiveRequest.windowHandle = Buffer.from(this.parentWindowHandle);
77
- }
78
- else {
79
- // error should have been thrown from within the constructor of InteractiveBrowserCredential
80
- this.logger.warning("Parent window handle is not specified for the broker. This may cause unexpected behavior. Please provide the parentWindowHandle.");
81
- }
82
- if (this.enableMsaPassthrough) {
83
- ((_a = interactiveRequest.tokenQueryParameters) !== null && _a !== void 0 ? _a : (interactiveRequest.tokenQueryParameters = {}))["msal_request_type"] =
84
- "consumer_passthrough";
85
- }
86
- if (options.useDefaultBrokerAccount) {
87
- interactiveRequest.prompt = "none";
88
- this.logger.verbose("Attempting broker authentication using the default broker account");
89
- }
90
- else {
91
- interactiveRequest.prompt = undefined;
92
- this.logger.verbose("Attempting broker authentication without the default broker account");
93
- }
94
- try {
95
- const result = yield this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).acquireTokenInteractive(interactiveRequest);
96
- if (result.fromNativeBroker) {
97
- this.logger.verbose(`This result is returned from native broker`);
98
- }
99
- return this.handleResult(scopes, result || undefined);
100
- }
101
- catch (e) {
102
- this.logger.verbose(`Failed to authenticate through the broker: ${e.message}`);
103
- // If we tried to use the default broker account and failed, fall back to interactive authentication
104
- if (options.useDefaultBrokerAccount) {
105
- return this.doGetBrokeredToken(scopes, interactiveRequest, {
106
- enableCae: options.enableCae,
107
- useDefaultBrokerAccount: false,
108
- });
109
- }
110
- else {
111
- // If we're not using the default broker account, throw the error
112
- throw handleMsalError(scopes, e);
113
- }
114
- }
115
- });
116
- }
117
- }
118
- //# sourceMappingURL=msalOpenBrowser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msalOpenBrowser.js","sourceRoot":"","sources":["../../../../../../identity/src/msal/nodeFlows/msalOpenBrowser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAIlC,OAAO,EAAE,QAAQ,EAAmB,MAAM,kBAAkB,CAAC;AAI7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,IAAI,MAAM,MAAM,CAAC;AAexB;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,IAAI;CACL,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAM3C,YAAY,OAA+B;;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,C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MAAM,CAAC,OAAO,CAAC,mEAAmE,CAAC,CAAC;YAC3F,CAAC;iBAAM,CAAC;gBACN,kBAAkB,CAAC,MAAM,GAAG,SAAS,CAAC;gBACtC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,qEAAqE,CAAC,CAAC;YAC7F,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAC,CAAC,uBAAuB,CACpF,kBAAkB,CACnB,CAAC;gBACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;oBAC5B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC;gBACpE,CAAC;gBACD,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,IAAI,SAAS,CAAC,CAAC;YACxD,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,8CAA8C,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC/E,oGAAoG;gBACpG,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC;oBACpC,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE;wBACzD,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,uBAAuB,EAAE,KAAK;qBAC/B,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,iEAAiE;oBACjE,MAAM,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport * as msalNode from \"@azure/msal-node\";\n\nimport { MsalNode, MsalNodeOptions } from \"./msalNodeCommon\";\n\nimport { AccessToken } from \"@azure/core-auth\";\nimport { CredentialFlowGetTokenOptions } from \"../credentials\";\nimport { credentialLogger } from \"../../util/logging\";\nimport { handleMsalError } from \"../utils\";\nimport { hasNativeBroker } from \"./msalPlugins\";\nimport open from \"open\";\n\n/**\n * Options that can be passed to configure MSAL to handle authentication through opening a browser window.\n * @internal\n */\nexport interface MsalOpenBrowserOptions extends MsalNodeOptions {\n redirectUri?: string;\n loginHint?: string;\n browserCustomizationOptions?: {\n errorMessage?: string;\n successMessage?: string;\n };\n}\n\n/**\n * A call to open(), but mockable\n * @internal\n */\nexport const interactiveBrowserMockable = {\n open,\n};\n\n/**\n * This MSAL client sets up a web server to listen for redirect callbacks, then calls to the MSAL's public application's `acquireTokenByDeviceCode` during `doGetToken`\n * to trigger the authentication flow, and then respond based on the values obtained from the redirect callback\n * @internal\n */\nexport class MsalOpenBrowser extends MsalNode {\n private loginHint?: string;\n private errorTemplate?: string;\n private successTemplate?: string;\n private useDefaultBrokerAccount?: boolean;\n\n constructor(options: MsalOpenBrowserOptions) {\n super(options);\n this.loginHint = options.loginHint;\n this.errorTemplate = options.browserCustomizationOptions?.errorMessage;\n this.successTemplate = options.browserCustomizationOptions?.successMessage;\n this.logger = credentialLogger(\"Node.js MSAL Open Browser\");\n this.useDefaultBrokerAccount =\n options.brokerOptions?.enabled && options.brokerOptions?.useDefaultBrokerAccount;\n }\n\n protected async doGetToken(\n scopes: string[],\n options: CredentialFlowGetTokenOptions = {},\n ): Promise<AccessToken> {\n try {\n const interactiveRequest: msalNode.InteractiveRequest = {\n openBrowser: async (url) => {\n await interactiveBrowserMockable.open(url, { wait: true, newInstance: true });\n },\n scopes,\n authority: options?.authority,\n claims: options?.claims,\n correlationId: options?.correlationId,\n loginHint: this.loginHint,\n errorTemplate: this.errorTemplate,\n successTemplate: this.successTemplate,\n };\n\n if (hasNativeBroker() && this.enableBroker) {\n return this.doGetBrokeredToken(scopes, interactiveRequest, {\n enableCae: options.enableCae,\n useDefaultBrokerAccount: this.useDefaultBrokerAccount,\n });\n }\n\n // If the broker is not enabled, we will fall back to interactive authentication\n\n if (hasNativeBroker() && !this.enableBroker) {\n this.logger.verbose(\n \"Authentication will resume normally without the broker, since it's not enabled\",\n );\n }\n\n const result = await this.getApp(\"public\", options?.enableCae).acquireTokenInteractive(\n interactiveRequest,\n );\n return this.handleResult(scopes, result || undefined);\n } catch (err: any) {\n throw handleMsalError(scopes, err, options);\n }\n }\n\n /**\n * A helper function that supports brokered authentication through the MSAL's public application.\n *\n * When options.useDefaultBrokerAccount is true, the method will attempt to authenticate using the default broker account.\n * If the default broker account is not available, the method will fall back to interactive authentication.\n */\n private async doGetBrokeredToken(\n scopes: string[],\n interactiveRequest: msalNode.InteractiveRequest,\n options: {\n enableCae?: boolean;\n useDefaultBrokerAccount?: boolean;\n },\n ): Promise<AccessToken> {\n this.logger.verbose(\"Authentication will resume through the broker\");\n if (this.parentWindowHandle) {\n interactiveRequest.windowHandle = Buffer.from(this.parentWindowHandle);\n } else {\n // error should have been thrown from within the constructor of InteractiveBrowserCredential\n this.logger.warning(\n \"Parent window handle is not specified for the broker. This may cause unexpected behavior. Please provide the parentWindowHandle.\",\n );\n }\n\n if (this.enableMsaPassthrough) {\n (interactiveRequest.tokenQueryParameters ??= {})[\"msal_request_type\"] =\n \"consumer_passthrough\";\n }\n\n if (options.useDefaultBrokerAccount) {\n interactiveRequest.prompt = \"none\";\n this.logger.verbose(\"Attempting broker authentication using the default broker account\");\n } else {\n interactiveRequest.prompt = undefined;\n this.logger.verbose(\"Attempting broker authentication without the default broker account\");\n }\n\n try {\n const result = await this.getApp(\"public\", options?.enableCae).acquireTokenInteractive(\n interactiveRequest,\n );\n if (result.fromNativeBroker) {\n this.logger.verbose(`This result is returned from native broker`);\n }\n return this.handleResult(scopes, result || undefined);\n } catch (e: any) {\n this.logger.verbose(`Failed to authenticate through the broker: ${e.message}`);\n // If we tried to use the default broker account and failed, fall back to interactive authentication\n if (options.useDefaultBrokerAccount) {\n return this.doGetBrokeredToken(scopes, interactiveRequest, {\n enableCae: options.enableCae,\n useDefaultBrokerAccount: false,\n });\n } else {\n // If we're not using the default broker account, throw the error\n throw handleMsalError(scopes, e);\n }\n }\n }\n}\n"]}