@azure/identity 4.7.1-alpha.20250219.1 → 4.7.1-alpha.20250220.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/README.md +3 -1
  2. package/dist/browser/credentials/interactiveBrowserCredential-browser.d.mts.map +1 -1
  3. package/dist/browser/credentials/interactiveBrowserCredential-browser.mjs.map +1 -1
  4. package/dist/browser/credentials/interactiveBrowserCredential.d.ts +1 -1
  5. package/dist/browser/credentials/interactiveBrowserCredential.js +5 -5
  6. package/dist/browser/credentials/usernamePasswordCredential-browser.d.mts.map +1 -1
  7. package/dist/browser/credentials/usernamePasswordCredential-browser.mjs.map +1 -1
  8. package/dist/browser/credentials/usernamePasswordCredential.d.ts +2 -0
  9. package/dist/browser/credentials/usernamePasswordCredential.js +2 -0
  10. package/dist/browser/msal/browserFlows/msalBrowserCommon.d.ts +10 -97
  11. package/dist/browser/msal/browserFlows/msalBrowserCommon.d.ts.map +1 -1
  12. package/dist/browser/msal/browserFlows/msalBrowserCommon.js +235 -60
  13. package/dist/browser/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  14. package/dist/browser/msal/browserFlows/msalBrowserOptions.d.ts +87 -0
  15. package/dist/browser/msal/browserFlows/msalBrowserOptions.d.ts.map +1 -0
  16. package/dist/{esm/msal/browserFlows/flows.js → browser/msal/browserFlows/msalBrowserOptions.js} +1 -1
  17. package/dist/browser/msal/browserFlows/msalBrowserOptions.js.map +1 -0
  18. package/dist/commonjs/credentials/usernamePasswordCredential.d.ts +2 -0
  19. package/dist/commonjs/credentials/usernamePasswordCredential.d.ts.map +1 -1
  20. package/dist/commonjs/credentials/usernamePasswordCredential.js +2 -0
  21. package/dist/commonjs/credentials/usernamePasswordCredential.js.map +1 -1
  22. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.d.ts +10 -97
  23. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.d.ts.map +1 -1
  24. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js +237 -63
  25. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  26. package/dist/commonjs/msal/browserFlows/msalBrowserOptions.d.ts +87 -0
  27. package/dist/commonjs/msal/browserFlows/msalBrowserOptions.d.ts.map +1 -0
  28. package/dist/commonjs/msal/browserFlows/{flows.js → msalBrowserOptions.js} +1 -1
  29. package/dist/commonjs/msal/browserFlows/msalBrowserOptions.js.map +1 -0
  30. package/dist/esm/credentials/usernamePasswordCredential.d.ts +2 -0
  31. package/dist/esm/credentials/usernamePasswordCredential.d.ts.map +1 -1
  32. package/dist/esm/credentials/usernamePasswordCredential.js +2 -0
  33. package/dist/esm/credentials/usernamePasswordCredential.js.map +1 -1
  34. package/dist/esm/msal/browserFlows/msalBrowserCommon.d.ts +10 -97
  35. package/dist/esm/msal/browserFlows/msalBrowserCommon.d.ts.map +1 -1
  36. package/dist/esm/msal/browserFlows/msalBrowserCommon.js +235 -60
  37. package/dist/esm/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  38. package/dist/esm/msal/browserFlows/msalBrowserOptions.d.ts +87 -0
  39. package/dist/esm/msal/browserFlows/msalBrowserOptions.d.ts.map +1 -0
  40. package/dist/{browser/msal/browserFlows/flows.js → esm/msal/browserFlows/msalBrowserOptions.js} +1 -1
  41. package/dist/esm/msal/browserFlows/msalBrowserOptions.js.map +1 -0
  42. package/package.json +2 -2
  43. package/dist/browser/msal/browserFlows/flows.d.ts +0 -42
  44. package/dist/browser/msal/browserFlows/flows.d.ts.map +0 -1
  45. package/dist/browser/msal/browserFlows/flows.js.map +0 -1
  46. package/dist/browser/msal/browserFlows/msalAuthCode.d.ts +0 -48
  47. package/dist/browser/msal/browserFlows/msalAuthCode.d.ts.map +0 -1
  48. package/dist/browser/msal/browserFlows/msalAuthCode.js +0 -203
  49. package/dist/browser/msal/browserFlows/msalAuthCode.js.map +0 -1
  50. package/dist/commonjs/msal/browserFlows/flows.d.ts +0 -42
  51. package/dist/commonjs/msal/browserFlows/flows.d.ts.map +0 -1
  52. package/dist/commonjs/msal/browserFlows/flows.js.map +0 -1
  53. package/dist/commonjs/msal/browserFlows/msalAuthCode.d.ts +0 -48
  54. package/dist/commonjs/msal/browserFlows/msalAuthCode.d.ts.map +0 -1
  55. package/dist/commonjs/msal/browserFlows/msalAuthCode.js +0 -208
  56. package/dist/commonjs/msal/browserFlows/msalAuthCode.js.map +0 -1
  57. package/dist/esm/msal/browserFlows/flows.d.ts +0 -42
  58. package/dist/esm/msal/browserFlows/flows.d.ts.map +0 -1
  59. package/dist/esm/msal/browserFlows/flows.js.map +0 -1
  60. package/dist/esm/msal/browserFlows/msalAuthCode.d.ts +0 -48
  61. package/dist/esm/msal/browserFlows/msalAuthCode.d.ts.map +0 -1
  62. package/dist/esm/msal/browserFlows/msalAuthCode.js +0 -203
  63. package/dist/esm/msal/browserFlows/msalAuthCode.js.map +0 -1
@@ -1,48 +0,0 @@
1
- import type { MsalBrowserFlowOptions } from "./msalBrowserCommon.js";
2
- import { MsalBrowser } from "./msalBrowserCommon.js";
3
- import type { AccessToken } from "@azure/core-auth";
4
- import type { AuthenticationRecord } from "../types.js";
5
- import type { CredentialFlowGetTokenOptions } from "../credentials.js";
6
- /**
7
- * Uses MSAL Browser 2.X for browser authentication,
8
- * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).
9
- * @internal
10
- */
11
- export declare class MSALAuthCode extends MsalBrowser {
12
- private loginHint?;
13
- /**
14
- * Sets up an MSAL object based on the given parameters.
15
- * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,
16
- * which is set to be the active account.
17
- * @param options - Parameters necessary and otherwise used to create the MSAL object.
18
- */
19
- constructor(options: MsalBrowserFlowOptions);
20
- private getApp;
21
- /**
22
- * Loads the account based on the result of the authentication.
23
- * If no result was received, tries to load the account from the cache.
24
- * @param result - Result object received from MSAL.
25
- */
26
- private handleBrowserResult;
27
- /**
28
- * Uses MSAL to handle the redirect.
29
- */
30
- handleRedirect(): Promise<AuthenticationRecord | undefined>;
31
- /**
32
- * Uses MSAL to trigger a redirect or a popup login.
33
- */
34
- login(scopes?: string | string[]): Promise<AuthenticationRecord | undefined>;
35
- /**
36
- * Uses MSAL to retrieve the active account.
37
- */
38
- getActiveAccount(): Promise<AuthenticationRecord | undefined>;
39
- /**
40
- * Attempts to retrieve a token from cache.
41
- */
42
- getTokenSilent(scopes: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
43
- /**
44
- * Attempts to retrieve the token in the browser.
45
- */
46
- protected doGetToken(scopes: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
47
- }
48
- //# sourceMappingURL=msalAuthCode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msalAuthCode.d.ts","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalAuthCode.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AASrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAMvE;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAC,SAAS,CAAC,CAAS;IAE3B;;;;;OAKG;gBACS,OAAO,EAAE,sBAAsB;YAuB7B,MAAM;IAgBpB;;;;OAIG;YACW,mBAAmB;IAsDjC;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAKxE;;OAEG;IACU,KAAK,CAAC,MAAM,GAAE,MAAM,GAAG,MAAM,EAAO,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAiB7F;;OAEG;IACU,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAS1E;;OAEG;IACU,cAAc,CACzB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,6BAA6B,GACtC,OAAO,CAAC,WAAW,CAAC;IA8BvB;;OAEG;cACa,UAAU,CACxB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,6BAA6B,GACtC,OAAO,CAAC,WAAW,CAAC;CAgCxB"}
@@ -1,208 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.MSALAuthCode = void 0;
6
- const tslib_1 = require("tslib");
7
- const msalBrowser = tslib_1.__importStar(require("@azure/msal-browser"));
8
- const msalBrowserCommon_js_1 = require("./msalBrowserCommon.js");
9
- const utils_js_1 = require("../utils.js");
10
- const errors_js_1 = require("../../errors.js");
11
- const logger_1 = require("@azure/logger");
12
- // We keep a copy of the redirect hash.
13
- const redirectHash = self.location.hash;
14
- /**
15
- * Uses MSAL Browser 2.X for browser authentication,
16
- * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).
17
- * @internal
18
- */
19
- class MSALAuthCode extends msalBrowserCommon_js_1.MsalBrowser {
20
- /**
21
- * Sets up an MSAL object based on the given parameters.
22
- * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,
23
- * which is set to be the active account.
24
- * @param options - Parameters necessary and otherwise used to create the MSAL object.
25
- */
26
- constructor(options) {
27
- var _a;
28
- super(options);
29
- this.loginHint = options.loginHint;
30
- this.msalConfig.cache = {
31
- cacheLocation: "sessionStorage",
32
- storeAuthStateInCookie: true, // Set to true to improve the experience on IE11 and Edge.
33
- };
34
- this.msalConfig.system = {
35
- loggerOptions: {
36
- loggerCallback: (0, utils_js_1.defaultLoggerCallback)(this.logger, "Browser"),
37
- logLevel: (0, utils_js_1.getMSALLogLevel)((0, logger_1.getLogLevel)()),
38
- piiLoggingEnabled: (_a = options.loggingOptions) === null || _a === void 0 ? void 0 : _a.enableUnsafeSupportLogging,
39
- },
40
- };
41
- if (options.authenticationRecord) {
42
- this.account = Object.assign(Object.assign({}, options.authenticationRecord), { tenantId: this.tenantId });
43
- }
44
- }
45
- async getApp() {
46
- if (!this.app) {
47
- // Prepare the MSAL application
48
- this.app = await msalBrowser.PublicClientApplication.createPublicClientApplication(this.msalConfig);
49
- // setting the account right after the app is created.
50
- if (this.account) {
51
- this.app.setActiveAccount((0, utils_js_1.publicToMsal)(this.account));
52
- }
53
- }
54
- return this.app;
55
- }
56
- /**
57
- * Loads the account based on the result of the authentication.
58
- * If no result was received, tries to load the account from the cache.
59
- * @param result - Result object received from MSAL.
60
- */
61
- async handleBrowserResult(result) {
62
- try {
63
- const app = await this.getApp();
64
- if (result && result.account) {
65
- this.logger.info(`MSAL Browser V2 authentication successful.`);
66
- app.setActiveAccount(result.account);
67
- return (0, utils_js_1.msalToPublic)(this.clientId, result.account);
68
- }
69
- // If by this point we happen to have an active account, we should stop trying to parse this.
70
- const activeAccount = await this.app.getActiveAccount();
71
- if (activeAccount) {
72
- return (0, utils_js_1.msalToPublic)(this.clientId, activeAccount);
73
- }
74
- // If we don't have an active account, we try to activate it from all the already loaded accounts.
75
- const accounts = app.getAllAccounts();
76
- if (accounts.length > 1) {
77
- // If there's more than one account in memory, we force the user to authenticate again.
78
- // At this point we can't identify which account should this credential work with,
79
- // since at this point the user won't have provided enough information.
80
- // We log a message in case that helps.
81
- this.logger.info(`More than one account was found authenticated for this Client ID and Tenant ID.
82
- However, no "authenticationRecord" has been provided for this credential,
83
- therefore we're unable to pick between these accounts.
84
- A new login attempt will be requested, to ensure the correct account is picked.
85
- To work with multiple accounts for the same Client ID and Tenant ID, please provide an "authenticationRecord" when initializing "InteractiveBrowserCredential".`);
86
- // To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.
87
- // However, we want to avoid kicking the user out of their authentication on the Azure side.
88
- // We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.
89
- await app.logout({
90
- onRedirectNavigate: () => false,
91
- });
92
- return;
93
- }
94
- // If there's only one account for this MSAL object, we can safely activate it.
95
- if (accounts.length === 1) {
96
- const account = accounts[0];
97
- app.setActiveAccount(account);
98
- return (0, utils_js_1.msalToPublic)(this.clientId, account);
99
- }
100
- this.logger.info(`No accounts were found through MSAL.`);
101
- }
102
- catch (e) {
103
- this.logger.info(`Failed to acquire token through MSAL. ${e.message}`);
104
- }
105
- return;
106
- }
107
- /**
108
- * Uses MSAL to handle the redirect.
109
- */
110
- async handleRedirect() {
111
- const app = await this.getApp();
112
- return this.handleBrowserResult((await app.handleRedirectPromise(redirectHash)) || undefined);
113
- }
114
- /**
115
- * Uses MSAL to trigger a redirect or a popup login.
116
- */
117
- async login(scopes = []) {
118
- const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
119
- const loginRequest = {
120
- scopes: arrayScopes,
121
- loginHint: this.loginHint,
122
- };
123
- const app = await this.getApp();
124
- switch (this.loginStyle) {
125
- case "redirect": {
126
- await app.loginRedirect(loginRequest);
127
- return;
128
- }
129
- case "popup":
130
- return this.handleBrowserResult(await app.loginPopup(loginRequest));
131
- }
132
- }
133
- /**
134
- * Uses MSAL to retrieve the active account.
135
- */
136
- async getActiveAccount() {
137
- const app = await this.getApp();
138
- const account = app.getActiveAccount();
139
- if (!account) {
140
- return;
141
- }
142
- return (0, utils_js_1.msalToPublic)(this.clientId, account);
143
- }
144
- /**
145
- * Attempts to retrieve a token from cache.
146
- */
147
- async getTokenSilent(scopes, options) {
148
- const account = await this.getActiveAccount();
149
- if (!account) {
150
- throw new errors_js_1.AuthenticationRequiredError({
151
- scopes,
152
- getTokenOptions: options,
153
- message: "Silent authentication failed. We couldn't retrieve an active account from the cache.",
154
- });
155
- }
156
- const parameters = {
157
- authority: (options === null || options === void 0 ? void 0 : options.authority) || this.msalConfig.auth.authority,
158
- correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
159
- claims: options === null || options === void 0 ? void 0 : options.claims,
160
- account: (0, utils_js_1.publicToMsal)(account),
161
- forceRefresh: false,
162
- scopes,
163
- };
164
- try {
165
- this.logger.info("Attempting to acquire token silently");
166
- const app = await this.getApp();
167
- const response = await app.acquireTokenSilent(parameters);
168
- return this.handleResult(scopes, response);
169
- }
170
- catch (err) {
171
- throw (0, utils_js_1.handleMsalError)(scopes, err, options);
172
- }
173
- }
174
- /**
175
- * Attempts to retrieve the token in the browser.
176
- */
177
- async doGetToken(scopes, options) {
178
- const account = await this.getActiveAccount();
179
- if (!account) {
180
- throw new errors_js_1.AuthenticationRequiredError({
181
- scopes,
182
- getTokenOptions: options,
183
- message: "Silent authentication failed. We couldn't retrieve an active account from the cache.",
184
- });
185
- }
186
- const parameters = {
187
- authority: (options === null || options === void 0 ? void 0 : options.authority) || this.msalConfig.auth.authority,
188
- correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
189
- claims: options === null || options === void 0 ? void 0 : options.claims,
190
- account: (0, utils_js_1.publicToMsal)(account),
191
- loginHint: this.loginHint,
192
- scopes,
193
- };
194
- const app = await this.getApp();
195
- switch (this.loginStyle) {
196
- case "redirect":
197
- // This will go out of the page.
198
- // Once the InteractiveBrowserCredential is initialized again,
199
- // we'll load the MSAL account in the constructor.
200
- await app.acquireTokenRedirect(parameters);
201
- return { token: "", expiresOnTimestamp: 0, tokenType: "Bearer" };
202
- case "popup":
203
- return this.handleResult(scopes, await app.acquireTokenPopup(parameters));
204
- }
205
- }
206
- }
207
- exports.MSALAuthCode = MSALAuthCode;
208
- //# sourceMappingURL=msalAuthCode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msalAuthCode.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalAuthCode.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,yEAAmD;AAGnD,iEAAqD;AACrD,0CAMqB;AAIrB,+CAA8D;AAE9D,0CAA4C;AAE5C,uCAAuC;AACvC,MAAM,YAAY,GAAG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ft Corporation.\n// Licensed under the MIT License.\n\nimport * as msalBrowser from \"@azure/msal-browser\";\n\nimport type { MsalBrowserFlowOptions } from \"./msalBrowserCommon.js\";\nimport { MsalBrowser } from \"./msalBrowserCommon.js\";\nimport {\n defaultLoggerCallback,\n getMSALLogLevel,\n handleMsalError,\n msalToPublic,\n publicToMsal,\n} from \"../utils.js\";\n\nimport type { AccessToken } from \"@azure/core-auth\";\nimport type { AuthenticationRecord } from \"../types.js\";\nimport { AuthenticationRequiredError } from \"../../errors.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport { getLogLevel } from \"@azure/logger\";\n\n// We keep a copy of the redirect hash.\nconst redirectHash = self.location.hash;\n\n/**\n * Uses MSAL Browser 2.X for browser authentication,\n * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).\n * @internal\n */\nexport class MSALAuthCode extends MsalBrowser {\n private loginHint?: string;\n\n /**\n * Sets up an MSAL object based on the given parameters.\n * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,\n * which is set to be the active account.\n * @param options - Parameters necessary and otherwise used to create the MSAL object.\n */\n constructor(options: MsalBrowserFlowOptions) {\n super(options);\n this.loginHint = options.loginHint;\n\n this.msalConfig.cache = {\n cacheLocation: \"sessionStorage\",\n storeAuthStateInCookie: true, // Set to true to improve the experience on IE11 and Edge.\n };\n this.msalConfig.system = {\n loggerOptions: {\n loggerCallback: defaultLoggerCallback(this.logger, \"Browser\"),\n logLevel: getMSALLogLevel(getLogLevel()),\n piiLoggingEnabled: options.loggingOptions?.enableUnsafeSupportLogging,\n },\n };\n if (options.authenticationRecord) {\n this.account = {\n ...options.authenticationRecord,\n tenantId: this.tenantId,\n };\n }\n }\n\n private async getApp(): Promise<msalBrowser.IPublicClientApplication> {\n if (!this.app) {\n // Prepare the MSAL application\n this.app = await msalBrowser.PublicClientApplication.createPublicClientApplication(\n this.msalConfig as msalBrowser.Configuration,\n );\n\n // setting the account right after the app is created.\n if (this.account) {\n this.app.setActiveAccount(publicToMsal(this.account));\n }\n }\n\n return this.app;\n }\n\n /**\n * Loads the account based on the result of the authentication.\n * If no result was received, tries to load the account from the cache.\n * @param result - Result object received from MSAL.\n */\n private async handleBrowserResult(\n result?: msalBrowser.AuthenticationResult,\n ): Promise<AuthenticationRecord | undefined> {\n try {\n const app = await this.getApp();\n if (result && result.account) {\n this.logger.info(`MSAL Browser V2 authentication successful.`);\n app.setActiveAccount(result.account);\n return msalToPublic(this.clientId, result.account);\n }\n\n // If by this point we happen to have an active account, we should stop trying to parse this.\n const activeAccount = await this.app!.getActiveAccount();\n if (activeAccount) {\n return msalToPublic(this.clientId, activeAccount);\n }\n\n // If we don't have an active account, we try to activate it from all the already loaded accounts.\n const accounts = app.getAllAccounts();\n if (accounts.length > 1) {\n // If there's more than one account in memory, we force the user to authenticate again.\n // At this point we can't identify which account should this credential work with,\n // since at this point the user won't have provided enough information.\n // We log a message in case that helps.\n this.logger.info(\n `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 \"InteractiveBrowserCredential\".`,\n );\n // To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.\n // However, we want to avoid kicking the user out of their authentication on the Azure side.\n // We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.\n await app.logout({\n onRedirectNavigate: () => false,\n });\n return;\n }\n\n // If there's only one account for this MSAL object, we can safely activate it.\n if (accounts.length === 1) {\n const account = accounts[0];\n app.setActiveAccount(account);\n return msalToPublic(this.clientId, account);\n }\n\n this.logger.info(`No accounts were found through MSAL.`);\n } catch (e: any) {\n this.logger.info(`Failed to acquire token through MSAL. ${e.message}`);\n }\n return;\n }\n\n /**\n * Uses MSAL to handle the redirect.\n */\n public async handleRedirect(): Promise<AuthenticationRecord | undefined> {\n const app = await this.getApp();\n return this.handleBrowserResult((await app.handleRedirectPromise(redirectHash)) || undefined);\n }\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n public async login(scopes: string | string[] = []): Promise<AuthenticationRecord | undefined> {\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const loginRequest: msalBrowser.RedirectRequest = {\n scopes: arrayScopes,\n loginHint: this.loginHint,\n };\n const app = await this.getApp();\n switch (this.loginStyle) {\n case \"redirect\": {\n await app.loginRedirect(loginRequest);\n return;\n }\n case \"popup\":\n return this.handleBrowserResult(await app.loginPopup(loginRequest));\n }\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n public async getActiveAccount(): Promise<AuthenticationRecord | undefined> {\n const app = await this.getApp();\n const account = app.getActiveAccount();\n if (!account) {\n return;\n }\n return msalToPublic(this.clientId, account);\n }\n\n /**\n * Attempts to retrieve a token from cache.\n */\n public async getTokenSilent(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!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 parameters: msalBrowser.SilentRequest = {\n authority: options?.authority || this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n claims: options?.claims,\n account: publicToMsal(account),\n forceRefresh: false,\n scopes,\n };\n\n try {\n this.logger.info(\"Attempting to acquire token silently\");\n const app = await this.getApp();\n const response = await app.acquireTokenSilent(parameters);\n return this.handleResult(scopes, response);\n } catch (err: any) {\n throw handleMsalError(scopes, err, options);\n }\n }\n\n /**\n * Attempts to retrieve the token in the browser.\n */\n protected async doGetToken(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!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 parameters: msalBrowser.RedirectRequest = {\n authority: options?.authority || this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n claims: options?.claims,\n account: publicToMsal(account),\n loginHint: this.loginHint,\n scopes,\n };\n const app = await this.getApp();\n switch (this.loginStyle) {\n case \"redirect\":\n // This will go out of the page.\n // Once the InteractiveBrowserCredential is initialized again,\n // we'll load the MSAL account in the constructor.\n\n await app.acquireTokenRedirect(parameters);\n return { token: \"\", expiresOnTimestamp: 0, tokenType: \"Bearer\" };\n case \"popup\":\n return this.handleResult(scopes, await app.acquireTokenPopup(parameters));\n }\n }\n}\n"]}
@@ -1,42 +0,0 @@
1
- import type { AccessToken } from "@azure/core-auth";
2
- import type { AuthenticationRecord } from "../types.js";
3
- import type { CredentialFlowGetTokenOptions } from "../credentials.js";
4
- import type { CredentialLogger } from "../../util/logging.js";
5
- /**
6
- * Union of the constructor parameters that all MSAL flow types take.
7
- * @internal
8
- */
9
- export interface MsalFlowOptions {
10
- logger: CredentialLogger;
11
- clientId?: string;
12
- tenantId?: string;
13
- authorityHost?: string;
14
- authenticationRecord?: AuthenticationRecord;
15
- disableAutomaticAuthentication?: boolean;
16
- disableInstanceDiscovery?: boolean;
17
- getAssertion?: () => Promise<string>;
18
- enableMsaPassthrough?: boolean;
19
- }
20
- /**
21
- * The common methods we use to work with the MSAL flows.
22
- * @internal
23
- */
24
- export interface MsalFlow {
25
- /**
26
- * Allows for any setup before any request is processed.
27
- */
28
- init(options?: CredentialFlowGetTokenOptions): Promise<void>;
29
- /**
30
- * Tries to load the active account, either from memory or from MSAL.
31
- */
32
- getActiveAccount(): Promise<AuthenticationRecord | undefined>;
33
- /**
34
- * Tries to retrieve the token silently using MSAL.
35
- */
36
- getTokenSilent(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
37
- /**
38
- * Calls to the implementation's doGetToken method.
39
- */
40
- getToken(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
41
- }
42
- //# sourceMappingURL=flows.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../../../src/msal/browserFlows/flows.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,8BAA8B,CAAC,EAAE,OAAO,CAAC;IACzC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D;;OAEG;IACH,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAC;IAC9D;;OAEG;IACH,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACjG;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,6BAA6B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC5F"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"flows.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/flows.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken } from \"@azure/core-auth\";\nimport type { AuthenticationRecord } from \"../types.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport type { CredentialLogger } from \"../../util/logging.js\";\n\n/**\n * Union of the constructor parameters that all MSAL flow types take.\n * @internal\n */\nexport interface MsalFlowOptions {\n logger: CredentialLogger;\n clientId?: string;\n tenantId?: string;\n authorityHost?: string;\n authenticationRecord?: AuthenticationRecord;\n disableAutomaticAuthentication?: boolean;\n disableInstanceDiscovery?: boolean;\n getAssertion?: () => Promise<string>;\n enableMsaPassthrough?: boolean;\n}\n\n/**\n * The common methods we use to work with the MSAL flows.\n * @internal\n */\nexport interface MsalFlow {\n /**\n * Allows for any setup before any request is processed.\n */\n init(options?: CredentialFlowGetTokenOptions): Promise<void>;\n /**\n * Tries to load the active account, either from memory or from MSAL.\n */\n getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n /**\n * Tries to retrieve the token silently using MSAL.\n */\n getTokenSilent(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n /**\n * Calls to the implementation's doGetToken method.\n */\n getToken(scopes?: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n}\n"]}
@@ -1,48 +0,0 @@
1
- import type { MsalBrowserFlowOptions } from "./msalBrowserCommon.js";
2
- import { MsalBrowser } from "./msalBrowserCommon.js";
3
- import type { AccessToken } from "@azure/core-auth";
4
- import type { AuthenticationRecord } from "../types.js";
5
- import type { CredentialFlowGetTokenOptions } from "../credentials.js";
6
- /**
7
- * Uses MSAL Browser 2.X for browser authentication,
8
- * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).
9
- * @internal
10
- */
11
- export declare class MSALAuthCode extends MsalBrowser {
12
- private loginHint?;
13
- /**
14
- * Sets up an MSAL object based on the given parameters.
15
- * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,
16
- * which is set to be the active account.
17
- * @param options - Parameters necessary and otherwise used to create the MSAL object.
18
- */
19
- constructor(options: MsalBrowserFlowOptions);
20
- private getApp;
21
- /**
22
- * Loads the account based on the result of the authentication.
23
- * If no result was received, tries to load the account from the cache.
24
- * @param result - Result object received from MSAL.
25
- */
26
- private handleBrowserResult;
27
- /**
28
- * Uses MSAL to handle the redirect.
29
- */
30
- handleRedirect(): Promise<AuthenticationRecord | undefined>;
31
- /**
32
- * Uses MSAL to trigger a redirect or a popup login.
33
- */
34
- login(scopes?: string | string[]): Promise<AuthenticationRecord | undefined>;
35
- /**
36
- * Uses MSAL to retrieve the active account.
37
- */
38
- getActiveAccount(): Promise<AuthenticationRecord | undefined>;
39
- /**
40
- * Attempts to retrieve a token from cache.
41
- */
42
- getTokenSilent(scopes: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
43
- /**
44
- * Attempts to retrieve the token in the browser.
45
- */
46
- protected doGetToken(scopes: string[], options?: CredentialFlowGetTokenOptions): Promise<AccessToken>;
47
- }
48
- //# sourceMappingURL=msalAuthCode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msalAuthCode.d.ts","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalAuthCode.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AASrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAMvE;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,WAAW;IAC3C,OAAO,CAAC,SAAS,CAAC,CAAS;IAE3B;;;;;OAKG;gBACS,OAAO,EAAE,sBAAsB;YAuB7B,MAAM;IAgBpB;;;;OAIG;YACW,mBAAmB;IAsDjC;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAKxE;;OAEG;IACU,KAAK,CAAC,MAAM,GAAE,MAAM,GAAG,MAAM,EAAO,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAiB7F;;OAEG;IACU,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAS1E;;OAEG;IACU,cAAc,CACzB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,6BAA6B,GACtC,OAAO,CAAC,WAAW,CAAC;IA8BvB;;OAEG;cACa,UAAU,CACxB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,6BAA6B,GACtC,OAAO,CAAC,WAAW,CAAC;CAgCxB"}
@@ -1,203 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import * as msalBrowser from "@azure/msal-browser";
4
- import { MsalBrowser } from "./msalBrowserCommon.js";
5
- import { defaultLoggerCallback, getMSALLogLevel, handleMsalError, msalToPublic, publicToMsal, } from "../utils.js";
6
- import { AuthenticationRequiredError } from "../../errors.js";
7
- import { getLogLevel } from "@azure/logger";
8
- // We keep a copy of the redirect hash.
9
- const redirectHash = self.location.hash;
10
- /**
11
- * Uses MSAL Browser 2.X for browser authentication,
12
- * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).
13
- * @internal
14
- */
15
- export class MSALAuthCode extends MsalBrowser {
16
- /**
17
- * Sets up an MSAL object based on the given parameters.
18
- * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,
19
- * which is set to be the active account.
20
- * @param options - Parameters necessary and otherwise used to create the MSAL object.
21
- */
22
- constructor(options) {
23
- var _a;
24
- super(options);
25
- this.loginHint = options.loginHint;
26
- this.msalConfig.cache = {
27
- cacheLocation: "sessionStorage",
28
- storeAuthStateInCookie: true, // Set to true to improve the experience on IE11 and Edge.
29
- };
30
- this.msalConfig.system = {
31
- loggerOptions: {
32
- loggerCallback: defaultLoggerCallback(this.logger, "Browser"),
33
- logLevel: getMSALLogLevel(getLogLevel()),
34
- piiLoggingEnabled: (_a = options.loggingOptions) === null || _a === void 0 ? void 0 : _a.enableUnsafeSupportLogging,
35
- },
36
- };
37
- if (options.authenticationRecord) {
38
- this.account = Object.assign(Object.assign({}, options.authenticationRecord), { tenantId: this.tenantId });
39
- }
40
- }
41
- async getApp() {
42
- if (!this.app) {
43
- // Prepare the MSAL application
44
- this.app = await msalBrowser.PublicClientApplication.createPublicClientApplication(this.msalConfig);
45
- // setting the account right after the app is created.
46
- if (this.account) {
47
- this.app.setActiveAccount(publicToMsal(this.account));
48
- }
49
- }
50
- return this.app;
51
- }
52
- /**
53
- * Loads the account based on the result of the authentication.
54
- * If no result was received, tries to load the account from the cache.
55
- * @param result - Result object received from MSAL.
56
- */
57
- async handleBrowserResult(result) {
58
- try {
59
- const app = await this.getApp();
60
- if (result && result.account) {
61
- this.logger.info(`MSAL Browser V2 authentication successful.`);
62
- app.setActiveAccount(result.account);
63
- return msalToPublic(this.clientId, result.account);
64
- }
65
- // If by this point we happen to have an active account, we should stop trying to parse this.
66
- const activeAccount = await this.app.getActiveAccount();
67
- if (activeAccount) {
68
- return msalToPublic(this.clientId, activeAccount);
69
- }
70
- // If we don't have an active account, we try to activate it from all the already loaded accounts.
71
- const accounts = app.getAllAccounts();
72
- if (accounts.length > 1) {
73
- // If there's more than one account in memory, we force the user to authenticate again.
74
- // At this point we can't identify which account should this credential work with,
75
- // since at this point the user won't have provided enough information.
76
- // We log a message in case that helps.
77
- this.logger.info(`More than one account was found authenticated for this Client ID and Tenant ID.
78
- However, no "authenticationRecord" has been provided for this credential,
79
- therefore we're unable to pick between these accounts.
80
- A new login attempt will be requested, to ensure the correct account is picked.
81
- To work with multiple accounts for the same Client ID and Tenant ID, please provide an "authenticationRecord" when initializing "InteractiveBrowserCredential".`);
82
- // To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.
83
- // However, we want to avoid kicking the user out of their authentication on the Azure side.
84
- // We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.
85
- await app.logout({
86
- onRedirectNavigate: () => false,
87
- });
88
- return;
89
- }
90
- // If there's only one account for this MSAL object, we can safely activate it.
91
- if (accounts.length === 1) {
92
- const account = accounts[0];
93
- app.setActiveAccount(account);
94
- return msalToPublic(this.clientId, account);
95
- }
96
- this.logger.info(`No accounts were found through MSAL.`);
97
- }
98
- catch (e) {
99
- this.logger.info(`Failed to acquire token through MSAL. ${e.message}`);
100
- }
101
- return;
102
- }
103
- /**
104
- * Uses MSAL to handle the redirect.
105
- */
106
- async handleRedirect() {
107
- const app = await this.getApp();
108
- return this.handleBrowserResult((await app.handleRedirectPromise(redirectHash)) || undefined);
109
- }
110
- /**
111
- * Uses MSAL to trigger a redirect or a popup login.
112
- */
113
- async login(scopes = []) {
114
- const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
115
- const loginRequest = {
116
- scopes: arrayScopes,
117
- loginHint: this.loginHint,
118
- };
119
- const app = await this.getApp();
120
- switch (this.loginStyle) {
121
- case "redirect": {
122
- await app.loginRedirect(loginRequest);
123
- return;
124
- }
125
- case "popup":
126
- return this.handleBrowserResult(await app.loginPopup(loginRequest));
127
- }
128
- }
129
- /**
130
- * Uses MSAL to retrieve the active account.
131
- */
132
- async getActiveAccount() {
133
- const app = await this.getApp();
134
- const account = app.getActiveAccount();
135
- if (!account) {
136
- return;
137
- }
138
- return msalToPublic(this.clientId, account);
139
- }
140
- /**
141
- * Attempts to retrieve a token from cache.
142
- */
143
- async getTokenSilent(scopes, options) {
144
- const account = await this.getActiveAccount();
145
- if (!account) {
146
- throw new AuthenticationRequiredError({
147
- scopes,
148
- getTokenOptions: options,
149
- message: "Silent authentication failed. We couldn't retrieve an active account from the cache.",
150
- });
151
- }
152
- const parameters = {
153
- authority: (options === null || options === void 0 ? void 0 : options.authority) || this.msalConfig.auth.authority,
154
- correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
155
- claims: options === null || options === void 0 ? void 0 : options.claims,
156
- account: publicToMsal(account),
157
- forceRefresh: false,
158
- scopes,
159
- };
160
- try {
161
- this.logger.info("Attempting to acquire token silently");
162
- const app = await this.getApp();
163
- const response = await app.acquireTokenSilent(parameters);
164
- return this.handleResult(scopes, response);
165
- }
166
- catch (err) {
167
- throw handleMsalError(scopes, err, options);
168
- }
169
- }
170
- /**
171
- * Attempts to retrieve the token in the browser.
172
- */
173
- async doGetToken(scopes, options) {
174
- const account = await this.getActiveAccount();
175
- if (!account) {
176
- throw new AuthenticationRequiredError({
177
- scopes,
178
- getTokenOptions: options,
179
- message: "Silent authentication failed. We couldn't retrieve an active account from the cache.",
180
- });
181
- }
182
- const parameters = {
183
- authority: (options === null || options === void 0 ? void 0 : options.authority) || this.msalConfig.auth.authority,
184
- correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
185
- claims: options === null || options === void 0 ? void 0 : options.claims,
186
- account: publicToMsal(account),
187
- loginHint: this.loginHint,
188
- scopes,
189
- };
190
- const app = await this.getApp();
191
- switch (this.loginStyle) {
192
- case "redirect":
193
- // This will go out of the page.
194
- // Once the InteractiveBrowserCredential is initialized again,
195
- // we'll load the MSAL account in the constructor.
196
- await app.acquireTokenRedirect(parameters);
197
- return { token: "", expiresOnTimestamp: 0, tokenType: "Bearer" };
198
- case "popup":
199
- return this.handleResult(scopes, await app.acquireTokenPopup(parameters));
200
- }
201
- }
202
- }
203
- //# sourceMappingURL=msalAuthCode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msalAuthCode.js","sourceRoot":"","sources":["../../../../src/msal/brow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oB,CAAC,UAAU,CAAC,CAAC;gBAC3C,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,EAAE,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;YACnE,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport * as msalBrowser from \"@azure/msal-browser\";\n\nimport type { MsalBrowserFlowOptions } from \"./msalBrowserCommon.js\";\nimport { MsalBrowser } from \"./msalBrowserCommon.js\";\nimport {\n defaultLoggerCallback,\n getMSALLogLevel,\n handleMsalError,\n msalToPublic,\n publicToMsal,\n} from \"../utils.js\";\n\nimport type { AccessToken } from \"@azure/core-auth\";\nimport type { AuthenticationRecord } from \"../types.js\";\nimport { AuthenticationRequiredError } from \"../../errors.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport { getLogLevel } from \"@azure/logger\";\n\n// We keep a copy of the redirect hash.\nconst redirectHash = self.location.hash;\n\n/**\n * Uses MSAL Browser 2.X for browser authentication,\n * which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).\n * @internal\n */\nexport class MSALAuthCode extends MsalBrowser {\n private loginHint?: string;\n\n /**\n * Sets up an MSAL object based on the given parameters.\n * MSAL with Auth Code allows sending a previously obtained `authenticationRecord` through the optional parameters,\n * which is set to be the active account.\n * @param options - Parameters necessary and otherwise used to create the MSAL object.\n */\n constructor(options: MsalBrowserFlowOptions) {\n super(options);\n this.loginHint = options.loginHint;\n\n this.msalConfig.cache = {\n cacheLocation: \"sessionStorage\",\n storeAuthStateInCookie: true, // Set to true to improve the experience on IE11 and Edge.\n };\n this.msalConfig.system = {\n loggerOptions: {\n loggerCallback: defaultLoggerCallback(this.logger, \"Browser\"),\n logLevel: getMSALLogLevel(getLogLevel()),\n piiLoggingEnabled: options.loggingOptions?.enableUnsafeSupportLogging,\n },\n };\n if (options.authenticationRecord) {\n this.account = {\n ...options.authenticationRecord,\n tenantId: this.tenantId,\n };\n }\n }\n\n private async getApp(): Promise<msalBrowser.IPublicClientApplication> {\n if (!this.app) {\n // Prepare the MSAL application\n this.app = await msalBrowser.PublicClientApplication.createPublicClientApplication(\n this.msalConfig as msalBrowser.Configuration,\n );\n\n // setting the account right after the app is created.\n if (this.account) {\n this.app.setActiveAccount(publicToMsal(this.account));\n }\n }\n\n return this.app;\n }\n\n /**\n * Loads the account based on the result of the authentication.\n * If no result was received, tries to load the account from the cache.\n * @param result - Result object received from MSAL.\n */\n private async handleBrowserResult(\n result?: msalBrowser.AuthenticationResult,\n ): Promise<AuthenticationRecord | undefined> {\n try {\n const app = await this.getApp();\n if (result && result.account) {\n this.logger.info(`MSAL Browser V2 authentication successful.`);\n app.setActiveAccount(result.account);\n return msalToPublic(this.clientId, result.account);\n }\n\n // If by this point we happen to have an active account, we should stop trying to parse this.\n const activeAccount = await this.app!.getActiveAccount();\n if (activeAccount) {\n return msalToPublic(this.clientId, activeAccount);\n }\n\n // If we don't have an active account, we try to activate it from all the already loaded accounts.\n const accounts = app.getAllAccounts();\n if (accounts.length > 1) {\n // If there's more than one account in memory, we force the user to authenticate again.\n // At this point we can't identify which account should this credential work with,\n // since at this point the user won't have provided enough information.\n // We log a message in case that helps.\n this.logger.info(\n `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 \"InteractiveBrowserCredential\".`,\n );\n // To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.\n // However, we want to avoid kicking the user out of their authentication on the Azure side.\n // We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.\n await app.logout({\n onRedirectNavigate: () => false,\n });\n return;\n }\n\n // If there's only one account for this MSAL object, we can safely activate it.\n if (accounts.length === 1) {\n const account = accounts[0];\n app.setActiveAccount(account);\n return msalToPublic(this.clientId, account);\n }\n\n this.logger.info(`No accounts were found through MSAL.`);\n } catch (e: any) {\n this.logger.info(`Failed to acquire token through MSAL. ${e.message}`);\n }\n return;\n }\n\n /**\n * Uses MSAL to handle the redirect.\n */\n public async handleRedirect(): Promise<AuthenticationRecord | undefined> {\n const app = await this.getApp();\n return this.handleBrowserResult((await app.handleRedirectPromise(redirectHash)) || undefined);\n }\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n public async login(scopes: string | string[] = []): Promise<AuthenticationRecord | undefined> {\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const loginRequest: msalBrowser.RedirectRequest = {\n scopes: arrayScopes,\n loginHint: this.loginHint,\n };\n const app = await this.getApp();\n switch (this.loginStyle) {\n case \"redirect\": {\n await app.loginRedirect(loginRequest);\n return;\n }\n case \"popup\":\n return this.handleBrowserResult(await app.loginPopup(loginRequest));\n }\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n public async getActiveAccount(): Promise<AuthenticationRecord | undefined> {\n const app = await this.getApp();\n const account = app.getActiveAccount();\n if (!account) {\n return;\n }\n return msalToPublic(this.clientId, account);\n }\n\n /**\n * Attempts to retrieve a token from cache.\n */\n public async getTokenSilent(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!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 parameters: msalBrowser.SilentRequest = {\n authority: options?.authority || this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n claims: options?.claims,\n account: publicToMsal(account),\n forceRefresh: false,\n scopes,\n };\n\n try {\n this.logger.info(\"Attempting to acquire token silently\");\n const app = await this.getApp();\n const response = await app.acquireTokenSilent(parameters);\n return this.handleResult(scopes, response);\n } catch (err: any) {\n throw handleMsalError(scopes, err, options);\n }\n }\n\n /**\n * Attempts to retrieve the token in the browser.\n */\n protected async doGetToken(\n scopes: string[],\n options?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const account = await this.getActiveAccount();\n if (!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 parameters: msalBrowser.RedirectRequest = {\n authority: options?.authority || this.msalConfig.auth.authority!,\n correlationId: options?.correlationId,\n claims: options?.claims,\n account: publicToMsal(account),\n loginHint: this.loginHint,\n scopes,\n };\n const app = await this.getApp();\n switch (this.loginStyle) {\n case \"redirect\":\n // This will go out of the page.\n // Once the InteractiveBrowserCredential is initialized again,\n // we'll load the MSAL account in the constructor.\n\n await app.acquireTokenRedirect(parameters);\n return { token: \"\", expiresOnTimestamp: 0, tokenType: \"Bearer\" };\n case \"popup\":\n return this.handleResult(scopes, await app.acquireTokenPopup(parameters));\n }\n }\n}\n"]}