@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.
- package/README.md +3 -1
- package/dist/browser/credentials/interactiveBrowserCredential-browser.d.mts.map +1 -1
- package/dist/browser/credentials/interactiveBrowserCredential-browser.mjs.map +1 -1
- package/dist/browser/credentials/interactiveBrowserCredential.d.ts +1 -1
- package/dist/browser/credentials/interactiveBrowserCredential.js +5 -5
- package/dist/browser/credentials/usernamePasswordCredential-browser.d.mts.map +1 -1
- package/dist/browser/credentials/usernamePasswordCredential-browser.mjs.map +1 -1
- package/dist/browser/credentials/usernamePasswordCredential.d.ts +2 -0
- package/dist/browser/credentials/usernamePasswordCredential.js +2 -0
- package/dist/browser/msal/browserFlows/msalBrowserCommon.d.ts +10 -97
- package/dist/browser/msal/browserFlows/msalBrowserCommon.d.ts.map +1 -1
- package/dist/browser/msal/browserFlows/msalBrowserCommon.js +235 -60
- package/dist/browser/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist/browser/msal/browserFlows/msalBrowserOptions.d.ts +87 -0
- package/dist/browser/msal/browserFlows/msalBrowserOptions.d.ts.map +1 -0
- package/dist/{esm/msal/browserFlows/flows.js → browser/msal/browserFlows/msalBrowserOptions.js} +1 -1
- package/dist/browser/msal/browserFlows/msalBrowserOptions.js.map +1 -0
- package/dist/commonjs/credentials/usernamePasswordCredential.d.ts +2 -0
- package/dist/commonjs/credentials/usernamePasswordCredential.d.ts.map +1 -1
- package/dist/commonjs/credentials/usernamePasswordCredential.js +2 -0
- package/dist/commonjs/credentials/usernamePasswordCredential.js.map +1 -1
- package/dist/commonjs/msal/browserFlows/msalBrowserCommon.d.ts +10 -97
- package/dist/commonjs/msal/browserFlows/msalBrowserCommon.d.ts.map +1 -1
- package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js +237 -63
- package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist/commonjs/msal/browserFlows/msalBrowserOptions.d.ts +87 -0
- package/dist/commonjs/msal/browserFlows/msalBrowserOptions.d.ts.map +1 -0
- package/dist/commonjs/msal/browserFlows/{flows.js → msalBrowserOptions.js} +1 -1
- package/dist/commonjs/msal/browserFlows/msalBrowserOptions.js.map +1 -0
- package/dist/esm/credentials/usernamePasswordCredential.d.ts +2 -0
- package/dist/esm/credentials/usernamePasswordCredential.d.ts.map +1 -1
- package/dist/esm/credentials/usernamePasswordCredential.js +2 -0
- package/dist/esm/credentials/usernamePasswordCredential.js.map +1 -1
- package/dist/esm/msal/browserFlows/msalBrowserCommon.d.ts +10 -97
- package/dist/esm/msal/browserFlows/msalBrowserCommon.d.ts.map +1 -1
- package/dist/esm/msal/browserFlows/msalBrowserCommon.js +235 -60
- package/dist/esm/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist/esm/msal/browserFlows/msalBrowserOptions.d.ts +87 -0
- package/dist/esm/msal/browserFlows/msalBrowserOptions.d.ts.map +1 -0
- package/dist/{browser/msal/browserFlows/flows.js → esm/msal/browserFlows/msalBrowserOptions.js} +1 -1
- package/dist/esm/msal/browserFlows/msalBrowserOptions.js.map +1 -0
- package/package.json +2 -2
- package/dist/browser/msal/browserFlows/flows.d.ts +0 -42
- package/dist/browser/msal/browserFlows/flows.d.ts.map +0 -1
- package/dist/browser/msal/browserFlows/flows.js.map +0 -1
- package/dist/browser/msal/browserFlows/msalAuthCode.d.ts +0 -48
- package/dist/browser/msal/browserFlows/msalAuthCode.d.ts.map +0 -1
- package/dist/browser/msal/browserFlows/msalAuthCode.js +0 -203
- package/dist/browser/msal/browserFlows/msalAuthCode.js.map +0 -1
- package/dist/commonjs/msal/browserFlows/flows.d.ts +0 -42
- package/dist/commonjs/msal/browserFlows/flows.d.ts.map +0 -1
- package/dist/commonjs/msal/browserFlows/flows.js.map +0 -1
- package/dist/commonjs/msal/browserFlows/msalAuthCode.d.ts +0 -48
- package/dist/commonjs/msal/browserFlows/msalAuthCode.d.ts.map +0 -1
- package/dist/commonjs/msal/browserFlows/msalAuthCode.js +0 -208
- package/dist/commonjs/msal/browserFlows/msalAuthCode.js.map +0 -1
- package/dist/esm/msal/browserFlows/flows.d.ts +0 -42
- package/dist/esm/msal/browserFlows/flows.d.ts.map +0 -1
- package/dist/esm/msal/browserFlows/flows.js.map +0 -1
- package/dist/esm/msal/browserFlows/msalAuthCode.d.ts +0 -48
- package/dist/esm/msal/browserFlows/msalAuthCode.d.ts.map +0 -1
- package/dist/esm/msal/browserFlows/msalAuthCode.js +0 -203
- package/dist/esm/msal/browserFlows/msalAuthCode.js.map +0 -1
@@ -1,15 +1,18 @@
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
2
2
|
// Licensed under the MIT License.
|
3
|
+
import * as msalBrowser from "@azure/msal-browser";
|
4
|
+
import { defaultLoggerCallback, ensureValidMsalToken, getAuthority, getKnownAuthorities, getMSALLogLevel, handleMsalError, msalToPublic, publicToMsal, } from "../utils.js";
|
3
5
|
import { AuthenticationRequiredError, CredentialUnavailableError } from "../../errors.js";
|
6
|
+
import { getLogLevel } from "@azure/logger";
|
4
7
|
import { formatSuccess } from "../../util/logging.js";
|
5
|
-
import { ensureValidMsalToken, getAuthority, getKnownAuthorities, msalToPublic } from "../utils.js";
|
6
8
|
import { processMultiTenantRequest, resolveAdditionallyAllowedTenantIds, resolveTenantId, } from "../../util/tenantIdUtils.js";
|
7
9
|
import { DefaultTenantId } from "../../constants.js";
|
8
10
|
/**
|
9
11
|
* Generates a MSAL configuration that generally works for browsers
|
10
12
|
* @internal
|
11
13
|
*/
|
12
|
-
|
14
|
+
function generateMsalBrowserConfiguration(options) {
|
15
|
+
var _a;
|
13
16
|
const tenantId = options.tenantId || DefaultTenantId;
|
14
17
|
const authority = getAuthority(tenantId, options.authorityHost);
|
15
18
|
return {
|
@@ -22,89 +25,124 @@ export function defaultBrowserMsalConfig(options) {
|
|
22
25
|
// we can try to use the current page we're in as a default value.
|
23
26
|
redirectUri: options.redirectUri || self.location.origin,
|
24
27
|
},
|
28
|
+
cache: {
|
29
|
+
cacheLocation: "sessionStorage",
|
30
|
+
storeAuthStateInCookie: true, // Set to true to improve the experience on IE11 and Edge.
|
31
|
+
},
|
32
|
+
system: {
|
33
|
+
loggerOptions: {
|
34
|
+
loggerCallback: defaultLoggerCallback(options.logger, "Browser"),
|
35
|
+
logLevel: getMSALLogLevel(getLogLevel()),
|
36
|
+
piiLoggingEnabled: (_a = options.loggingOptions) === null || _a === void 0 ? void 0 : _a.enableUnsafeSupportLogging,
|
37
|
+
},
|
38
|
+
},
|
25
39
|
};
|
26
40
|
}
|
41
|
+
// We keep a copy of the redirect hash.
|
42
|
+
const redirectHash = self.location.hash;
|
27
43
|
/**
|
28
|
-
* MSAL
|
29
|
-
*
|
30
|
-
* It completes the input configuration with some default values.
|
31
|
-
* It also provides with utility protected methods that can be used from any of the clients,
|
32
|
-
* which includes handlers for successful responses and errors.
|
33
|
-
*
|
44
|
+
* Uses MSAL Browser 2.X for browser authentication,
|
45
|
+
* which uses the [Auth Code Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow).
|
34
46
|
* @internal
|
35
47
|
*/
|
36
|
-
export
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
if (!options.clientId) {
|
42
|
-
throw new CredentialUnavailableError("A client ID is required in browsers");
|
43
|
-
}
|
44
|
-
this.clientId = options.clientId;
|
45
|
-
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds((_a = options === null || options === void 0 ? void 0 : options.tokenCredentialOptions) === null || _a === void 0 ? void 0 : _a.additionallyAllowedTenants);
|
46
|
-
this.tenantId = resolveTenantId(this.logger, options.tenantId, options.clientId);
|
47
|
-
this.authorityHost = options.authorityHost;
|
48
|
-
this.msalConfig = defaultBrowserMsalConfig(options);
|
49
|
-
this.disableAutomaticAuthentication = options.disableAutomaticAuthentication;
|
50
|
-
if (options.authenticationRecord) {
|
51
|
-
this.account = Object.assign(Object.assign({}, options.authenticationRecord), { tenantId: this.tenantId });
|
52
|
-
}
|
48
|
+
export function createMsalBrowserClient(options) {
|
49
|
+
var _a;
|
50
|
+
const loginStyle = options.loginStyle;
|
51
|
+
if (!options.clientId) {
|
52
|
+
throw new CredentialUnavailableError("A client ID is required in browsers");
|
53
53
|
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
const clientId = options.clientId;
|
55
|
+
const logger = options.logger;
|
56
|
+
const tenantId = resolveTenantId(logger, options.tenantId, options.clientId);
|
57
|
+
const additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds((_a = options === null || options === void 0 ? void 0 : options.tokenCredentialOptions) === null || _a === void 0 ? void 0 : _a.additionallyAllowedTenants);
|
58
|
+
const authorityHost = options.authorityHost;
|
59
|
+
const msalConfig = generateMsalBrowserConfiguration(options);
|
60
|
+
const disableAutomaticAuthentication = options.disableAutomaticAuthentication;
|
61
|
+
const loginHint = options.loginHint;
|
62
|
+
let account;
|
63
|
+
if (options.authenticationRecord) {
|
64
|
+
account = Object.assign(Object.assign({}, options.authenticationRecord), { tenantId });
|
59
65
|
}
|
66
|
+
// This variable should only be used through calling `getApp` function
|
67
|
+
let app;
|
60
68
|
/**
|
61
|
-
*
|
69
|
+
* Return the MSAL account if not set yet
|
70
|
+
* @returns MSAL application
|
62
71
|
*/
|
63
|
-
async
|
64
|
-
|
65
|
-
|
72
|
+
async function getApp() {
|
73
|
+
if (!app) {
|
74
|
+
// Prepare the MSAL application
|
75
|
+
app = await msalBrowser.PublicClientApplication.createPublicClientApplication(msalConfig);
|
76
|
+
// setting the account right after the app is created.
|
77
|
+
if (account) {
|
78
|
+
app.setActiveAccount(publicToMsal(account));
|
79
|
+
}
|
80
|
+
}
|
81
|
+
return app;
|
66
82
|
}
|
67
83
|
/**
|
68
|
-
*
|
84
|
+
* Loads the account based on the result of the authentication.
|
85
|
+
* If no result was received, tries to load the account from the cache.
|
86
|
+
* @param result - Result object received from MSAL.
|
69
87
|
*/
|
70
|
-
async
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
await this.handleRedirect();
|
78
|
-
if (!(await this.getActiveAccount()) && !this.disableAutomaticAuthentication) {
|
79
|
-
await this.login(scopes);
|
80
|
-
}
|
81
|
-
return this.getTokenSilent(scopes).catch((err) => {
|
82
|
-
if (err.name !== "AuthenticationRequiredError") {
|
83
|
-
throw err;
|
88
|
+
async function handleBrowserResult(result) {
|
89
|
+
try {
|
90
|
+
const msalApp = await getApp();
|
91
|
+
if (result && result.account) {
|
92
|
+
logger.info(`MSAL Browser V2 authentication successful.`);
|
93
|
+
msalApp.setActiveAccount(result.account);
|
94
|
+
return msalToPublic(clientId, result.account);
|
84
95
|
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
96
|
+
// If by this point we happen to have an active account, we should stop trying to parse this.
|
97
|
+
const activeAccount = msalApp.getActiveAccount();
|
98
|
+
if (activeAccount) {
|
99
|
+
return msalToPublic(clientId, activeAccount);
|
100
|
+
}
|
101
|
+
// If we don't have an active account, we try to activate it from all the already loaded accounts.
|
102
|
+
const allAccounts = app.getAllAccounts();
|
103
|
+
if (allAccounts.length > 1) {
|
104
|
+
// If there's more than one account in memory, we force the user to authenticate again.
|
105
|
+
// At this point we can't identify which account should this credential work with,
|
106
|
+
// since at this point the user won't have provided enough information.
|
107
|
+
// We log a message in case that helps.
|
108
|
+
logger.info(`More than one account was found authenticated for this Client ID and Tenant ID.
|
109
|
+
However, no "authenticationRecord" has been provided for this credential,
|
110
|
+
therefore we're unable to pick between these accounts.
|
111
|
+
A new login attempt will be requested, to ensure the correct account is picked.
|
112
|
+
To work with multiple accounts for the same Client ID and Tenant ID, please provide an "authenticationRecord" when initializing "InteractiveBrowserCredential".`);
|
113
|
+
// To safely trigger a new login, we're also ensuring the local cache is cleared up for this MSAL object.
|
114
|
+
// However, we want to avoid kicking the user out of their authentication on the Azure side.
|
115
|
+
// We do this by calling to logout while specifying a `onRedirectNavigate` that returns false.
|
116
|
+
await msalApp.logout({
|
117
|
+
onRedirectNavigate: () => false,
|
90
118
|
});
|
119
|
+
return;
|
91
120
|
}
|
92
|
-
this
|
93
|
-
|
94
|
-
|
121
|
+
// If there's only one account for this MSAL object, we can safely activate it.
|
122
|
+
if (allAccounts.length === 1) {
|
123
|
+
const msalAccount = allAccounts[0];
|
124
|
+
msalApp.setActiveAccount(msalAccount);
|
125
|
+
return msalToPublic(clientId, msalAccount);
|
126
|
+
}
|
127
|
+
logger.info(`No accounts were found through MSAL.`);
|
128
|
+
}
|
129
|
+
catch (e) {
|
130
|
+
logger.info(`Failed to acquire token through MSAL. ${e.message}`);
|
131
|
+
}
|
132
|
+
return;
|
95
133
|
}
|
96
134
|
/**
|
97
135
|
* Handles the MSAL authentication result.
|
98
136
|
* If the result has an account, we update the local account reference.
|
99
137
|
* If the token received is invalid, an error will be thrown depending on what's missing.
|
100
138
|
*/
|
101
|
-
handleResult(scopes, result, getTokenOptions) {
|
139
|
+
function handleResult(scopes, result, getTokenOptions) {
|
102
140
|
var _a;
|
103
141
|
if (result === null || result === void 0 ? void 0 : result.account) {
|
104
|
-
|
142
|
+
account = msalToPublic(clientId, result.account);
|
105
143
|
}
|
106
144
|
ensureValidMsalToken(scopes, result, getTokenOptions);
|
107
|
-
|
145
|
+
logger.getToken.info(formatSuccess(scopes));
|
108
146
|
return {
|
109
147
|
token: result.accessToken,
|
110
148
|
expiresOnTimestamp: result.expiresOn.getTime(),
|
@@ -112,5 +150,142 @@ export class MsalBrowser {
|
|
112
150
|
tokenType: "Bearer",
|
113
151
|
};
|
114
152
|
}
|
153
|
+
/**
|
154
|
+
* Uses MSAL to handle the redirect.
|
155
|
+
*/
|
156
|
+
async function handleRedirect() {
|
157
|
+
const msalApp = await getApp();
|
158
|
+
return handleBrowserResult((await msalApp.handleRedirectPromise(redirectHash)) || undefined);
|
159
|
+
}
|
160
|
+
/**
|
161
|
+
* Uses MSAL to retrieve the active account.
|
162
|
+
*/
|
163
|
+
async function getActiveAccount() {
|
164
|
+
const msalApp = await getApp();
|
165
|
+
const activeAccount = msalApp.getActiveAccount();
|
166
|
+
if (!activeAccount) {
|
167
|
+
return;
|
168
|
+
}
|
169
|
+
return msalToPublic(clientId, activeAccount);
|
170
|
+
}
|
171
|
+
/**
|
172
|
+
* Uses MSAL to trigger a redirect or a popup login.
|
173
|
+
*/
|
174
|
+
async function login(scopes = []) {
|
175
|
+
const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
|
176
|
+
const loginRequest = {
|
177
|
+
scopes: arrayScopes,
|
178
|
+
loginHint: loginHint,
|
179
|
+
};
|
180
|
+
const msalApp = await getApp();
|
181
|
+
switch (loginStyle) {
|
182
|
+
case "redirect": {
|
183
|
+
await app.loginRedirect(loginRequest);
|
184
|
+
return;
|
185
|
+
}
|
186
|
+
case "popup":
|
187
|
+
return handleBrowserResult(await msalApp.loginPopup(loginRequest));
|
188
|
+
}
|
189
|
+
}
|
190
|
+
/**
|
191
|
+
* Tries to retrieve the token silently using MSAL.
|
192
|
+
*/
|
193
|
+
async function getTokenSilent(scopes, getTokenOptions) {
|
194
|
+
const activeAccount = await getActiveAccount();
|
195
|
+
if (!activeAccount) {
|
196
|
+
throw new AuthenticationRequiredError({
|
197
|
+
scopes,
|
198
|
+
getTokenOptions,
|
199
|
+
message: "Silent authentication failed. We couldn't retrieve an active account from the cache.",
|
200
|
+
});
|
201
|
+
}
|
202
|
+
const parameters = {
|
203
|
+
authority: (getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.authority) || msalConfig.auth.authority,
|
204
|
+
correlationId: getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.correlationId,
|
205
|
+
claims: getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.claims,
|
206
|
+
account: publicToMsal(activeAccount),
|
207
|
+
forceRefresh: false,
|
208
|
+
scopes,
|
209
|
+
};
|
210
|
+
try {
|
211
|
+
logger.info("Attempting to acquire token silently");
|
212
|
+
const msalApp = await getApp();
|
213
|
+
const response = await msalApp.acquireTokenSilent(parameters);
|
214
|
+
return handleResult(scopes, response);
|
215
|
+
}
|
216
|
+
catch (err) {
|
217
|
+
throw handleMsalError(scopes, err, options);
|
218
|
+
}
|
219
|
+
}
|
220
|
+
/**
|
221
|
+
* Attempts to retrieve the token in the browser through interactive methods.
|
222
|
+
*/
|
223
|
+
async function getTokenInteractive(scopes, getTokenOptions) {
|
224
|
+
const activeAccount = await getActiveAccount();
|
225
|
+
if (!activeAccount) {
|
226
|
+
throw new AuthenticationRequiredError({
|
227
|
+
scopes,
|
228
|
+
getTokenOptions,
|
229
|
+
message: "Silent authentication failed. We couldn't retrieve an active account from the cache.",
|
230
|
+
});
|
231
|
+
}
|
232
|
+
const parameters = {
|
233
|
+
authority: (getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.authority) || msalConfig.auth.authority,
|
234
|
+
correlationId: getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.correlationId,
|
235
|
+
claims: getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.claims,
|
236
|
+
account: publicToMsal(activeAccount),
|
237
|
+
loginHint: loginHint,
|
238
|
+
scopes,
|
239
|
+
};
|
240
|
+
const msalApp = await getApp();
|
241
|
+
switch (loginStyle) {
|
242
|
+
case "redirect":
|
243
|
+
// This will go out of the page.
|
244
|
+
// Once the InteractiveBrowserCredential is initialized again,
|
245
|
+
// we'll load the MSAL account in the constructor.
|
246
|
+
await msalApp.acquireTokenRedirect(parameters);
|
247
|
+
return { token: "", expiresOnTimestamp: 0, tokenType: "Bearer" };
|
248
|
+
case "popup":
|
249
|
+
return handleResult(scopes, await app.acquireTokenPopup(parameters));
|
250
|
+
}
|
251
|
+
}
|
252
|
+
/**
|
253
|
+
* Attempts to get token through the silent flow.
|
254
|
+
* If failed, get token through interactive method with `doGetToken` method.
|
255
|
+
*/
|
256
|
+
async function getToken(scopes, getTokenOptions = {}) {
|
257
|
+
const getTokenTenantId = processMultiTenantRequest(tenantId, getTokenOptions, additionallyAllowedTenantIds) ||
|
258
|
+
tenantId;
|
259
|
+
if (!getTokenOptions.authority) {
|
260
|
+
getTokenOptions.authority = getAuthority(getTokenTenantId, authorityHost);
|
261
|
+
}
|
262
|
+
// We ensure that redirection is handled at this point.
|
263
|
+
await handleRedirect();
|
264
|
+
if (!(await getActiveAccount()) && !disableAutomaticAuthentication) {
|
265
|
+
await login(scopes);
|
266
|
+
}
|
267
|
+
// Attempts to get the token silently; else, falls back to interactive method.
|
268
|
+
try {
|
269
|
+
return await getTokenSilent(scopes, getTokenOptions);
|
270
|
+
}
|
271
|
+
catch (err) {
|
272
|
+
if (err.name !== "AuthenticationRequiredError") {
|
273
|
+
throw err;
|
274
|
+
}
|
275
|
+
if (getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.disableAutomaticAuthentication) {
|
276
|
+
throw new AuthenticationRequiredError({
|
277
|
+
scopes,
|
278
|
+
getTokenOptions,
|
279
|
+
message: "Automatic authentication has been disabled. You may call the authenticate() method.",
|
280
|
+
});
|
281
|
+
}
|
282
|
+
logger.info(`Silent authentication failed, falling back to interactive method ${loginStyle}`);
|
283
|
+
return getTokenInteractive(scopes, getTokenOptions);
|
284
|
+
}
|
285
|
+
}
|
286
|
+
return {
|
287
|
+
getActiveAccount,
|
288
|
+
getToken,
|
289
|
+
};
|
115
290
|
}
|
116
291
|
//# sourceMappingURL=msalBrowserCommon.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"msalBrowserCommon.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalBrowserCommon.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE1F,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,m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;YAC/C,IAAI,GAAG,CAAC,IAAI,KAAK,6BAA6B,EAAE,CAAC;gBAC/C,MAAM,GAAG,CAAC;YACZ,CAAC;YACD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,8BAA8B,EAAE,CAAC;gBAC5C,MAAM,IAAI,2BAA2B,CAAC;oBACpC,MAAM;oBACN,eAAe,EAAE,OAAO;oBACxB,OAAO,EACL,uFAAuF;iBAC1F,CAAC,CAAC;YACL,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,oEAAoE,IAAI,CAAC,UAAU,EAAE,CACtF,CAAC;YACF,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;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;YAC9C,qBAAqB,EAAE,MAAA,MAAM,CAAC,SAAS,0CAAE,OAAO,EAAE;YAClD,SAAS,EAAE,QAAQ;SACL,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type * as msalBrowser from \"@azure/msal-browser\";\n\nimport type { AccessToken, GetTokenOptions } from \"@azure/core-auth\";\nimport type { AuthenticationRecord, MsalResult } from \"../types.js\";\nimport { AuthenticationRequiredError, CredentialUnavailableError } from \"../../errors.js\";\nimport type { CredentialLogger } from \"../../util/logging.js\";\nimport { formatSuccess } from \"../../util/logging.js\";\nimport type { MsalFlow, MsalFlowOptions } from \"./flows.js\";\nimport { ensureValidMsalToken, getAuthority, getKnownAuthorities, msalToPublic } from \"../utils.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../../util/tenantIdUtils.js\";\n\nimport type { BrowserLoginStyle } from \"../../credentials/interactiveBrowserCredentialOptions.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport { DefaultTenantId } from \"../../constants.js\";\nimport type { LogPolicyOptions } from \"@azure/core-rest-pipeline\";\nimport type { MultiTenantTokenCredentialOptions } from \"../../credentials/multiTenantTokenCredentialOptions.js\";\n\n/**\n * Union of the constructor parameters that all MSAL flow types take.\n * Some properties might not be used by some flow types.\n */\nexport interface MsalBrowserFlowOptions extends MsalFlowOptions {\n tokenCredentialOptions: MultiTenantTokenCredentialOptions;\n redirectUri?: string;\n loginStyle: BrowserLoginStyle;\n loginHint?: 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}\n\n/**\n * The common methods we use to work with the MSAL browser flows.\n * @internal\n */\nexport interface MsalBrowserFlow extends MsalFlow {\n login(scopes?: string[]): Promise<AuthenticationRecord | undefined>;\n handleRedirect(): Promise<AuthenticationRecord | undefined>;\n}\n\n/**\n * Generates a MSAL configuration that generally works for browsers\n * @internal\n */\nexport function defaultBrowserMsalConfig(\n options: MsalBrowserFlowOptions,\n): msalBrowser.Configuration {\n const tenantId = options.tenantId || DefaultTenantId;\n const authority = getAuthority(tenantId, options.authorityHost);\n return {\n auth: {\n clientId: options.clientId!,\n authority,\n knownAuthorities: getKnownAuthorities(tenantId, authority, options.disableInstanceDiscovery),\n // If the users picked redirect as their login style,\n // but they didn't provide a redirectUri,\n // we can try to use the current page we're in as a default value.\n redirectUri: options.redirectUri || self.location.origin,\n },\n };\n}\n\n/**\n * MSAL partial base client for the browsers.\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 MsalBrowser implements MsalBrowserFlow {\n protected loginStyle: BrowserLoginStyle;\n protected clientId: string;\n protected tenantId: string;\n protected additionallyAllowedTenantIds: string[];\n protected authorityHost?: string;\n protected account: AuthenticationRecord | undefined;\n protected msalConfig: msalBrowser.Configuration;\n protected disableAutomaticAuthentication?: boolean;\n protected app?: msalBrowser.IPublicClientApplication;\n protected logger: CredentialLogger;\n\n constructor(options: MsalBrowserFlowOptions) {\n this.logger = options.logger;\n this.loginStyle = options.loginStyle;\n if (!options.clientId) {\n throw new CredentialUnavailableError(\"A client ID is required in browsers\");\n }\n this.clientId = options.clientId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.tokenCredentialOptions?.additionallyAllowedTenants,\n );\n this.tenantId = resolveTenantId(this.logger, options.tenantId, options.clientId);\n this.authorityHost = options.authorityHost;\n this.msalConfig = defaultBrowserMsalConfig(options);\n this.disableAutomaticAuthentication = options.disableAutomaticAuthentication;\n\n if (options.authenticationRecord) {\n this.account = {\n ...options.authenticationRecord,\n tenantId: this.tenantId,\n };\n }\n }\n\n /**\n * In the browsers we don't need to init()\n */\n async init(): Promise<void> {\n // Nothing to do here.\n }\n\n /**\n * Attempts to handle a redirection request the least amount of times possible.\n */\n public abstract handleRedirect(): Promise<AuthenticationRecord | undefined>;\n\n /**\n * Clears MSAL's cache.\n */\n async logout(): Promise<void> {\n this.app?.logout();\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n public abstract getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n public abstract login(scopes?: string | string[]): Promise<AuthenticationRecord | undefined>;\n\n /**\n * Attempts to retrieve a token from cache.\n */\n public abstract getTokenSilent(scopes: string[]): Promise<AccessToken>;\n\n /**\n * Attempts to retrieve the token in the browser.\n */\n protected abstract doGetToken(scopes: string[]): Promise<AccessToken>;\n\n /**\n * Attempts to retrieve an authenticated token from MSAL.\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 if (!options.authority) {\n options.authority = getAuthority(tenantId, this.authorityHost);\n }\n\n // We ensure that redirection is handled at this point.\n await this.handleRedirect();\n\n if (!(await this.getActiveAccount()) && !this.disableAutomaticAuthentication) {\n await this.login(scopes);\n }\n return this.getTokenSilent(scopes).catch((err) => {\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(\n `Silent authentication failed, falling back to interactive method ${this.loginStyle}`,\n );\n return this.doGetToken(scopes);\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 refreshAfterTimestamp: result.refreshOn?.getTime(),\n tokenType: \"Bearer\",\n } as AccessToken;\n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Af,eAAe,uBAAf,eAAe,CAAE,8BAA8B,EAAE,CAAC;gBACpD,MAAM,IAAI,2BAA2B,CAAC;oBACpC,MAAM;oBACN,eAAe;oBACf,OAAO,EACL,qFAAqF;iBACxF,CAAC,CAAC;YACL,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,oEAAoE,UAAU,EAAE,CAAC,CAAC;YAC9F,OAAO,mBAAmB,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IACD,OAAO;QACL,gBAAgB;QAChB,QAAQ;KACT,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport * as msalBrowser from \"@azure/msal-browser\";\n\nimport type { MsalBrowserFlowOptions } from \"./msalBrowserOptions.js\";\nimport {\n defaultLoggerCallback,\n ensureValidMsalToken,\n getAuthority,\n getKnownAuthorities,\n getMSALLogLevel,\n handleMsalError,\n msalToPublic,\n publicToMsal,\n} from \"../utils.js\";\n\nimport type { AccessToken, GetTokenOptions } from \"@azure/core-auth\";\nimport type { AuthenticationRecord, MsalResult } from \"../types.js\";\nimport { AuthenticationRequiredError, CredentialUnavailableError } from \"../../errors.js\";\nimport type { CredentialFlowGetTokenOptions } from \"../credentials.js\";\nimport { getLogLevel } from \"@azure/logger\";\nimport { formatSuccess } from \"../../util/logging.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../../util/tenantIdUtils.js\";\nimport { DefaultTenantId } from \"../../constants.js\";\n\n/**\n * Generates a MSAL configuration that generally works for browsers\n * @internal\n */\nfunction generateMsalBrowserConfiguration(\n options: MsalBrowserFlowOptions,\n): msalBrowser.Configuration {\n const tenantId = options.tenantId || DefaultTenantId;\n const authority = getAuthority(tenantId, options.authorityHost);\n return {\n auth: {\n clientId: options.clientId!,\n authority,\n knownAuthorities: getKnownAuthorities(tenantId, authority, options.disableInstanceDiscovery),\n // If the users picked redirect as their login style,\n // but they didn't provide a redirectUri,\n // we can try to use the current page we're in as a default value.\n redirectUri: options.redirectUri || self.location.origin,\n },\n cache: {\n cacheLocation: \"sessionStorage\",\n storeAuthStateInCookie: true, // Set to true to improve the experience on IE11 and Edge.\n },\n system: {\n loggerOptions: {\n loggerCallback: defaultLoggerCallback(options.logger, \"Browser\"),\n logLevel: getMSALLogLevel(getLogLevel()),\n piiLoggingEnabled: options.loggingOptions?.enableUnsafeSupportLogging,\n },\n },\n };\n}\n\n/**\n * Methods that are used by InteractiveBrowserCredential\n * @internal\n */\nexport interface MsalBrowserClient {\n getActiveAccount(): Promise<AuthenticationRecord | undefined>;\n getToken(scopes: string[], options: CredentialFlowGetTokenOptions): Promise<AccessToken>;\n}\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 function createMsalBrowserClient(options: MsalBrowserFlowOptions): MsalBrowserClient {\n const loginStyle = options.loginStyle;\n if (!options.clientId) {\n throw new CredentialUnavailableError(\"A client ID is required in browsers\");\n }\n const clientId = options.clientId;\n const logger = options.logger;\n const tenantId = resolveTenantId(logger, options.tenantId, options.clientId);\n const additionallyAllowedTenantIds: string[] = resolveAdditionallyAllowedTenantIds(\n options?.tokenCredentialOptions?.additionallyAllowedTenants,\n );\n const authorityHost = options.authorityHost;\n const msalConfig = generateMsalBrowserConfiguration(options);\n const disableAutomaticAuthentication = options.disableAutomaticAuthentication;\n const loginHint = options.loginHint;\n\n let account: AuthenticationRecord | undefined;\n if (options.authenticationRecord) {\n account = {\n ...options.authenticationRecord,\n tenantId,\n };\n }\n\n // This variable should only be used through calling `getApp` function\n let app: msalBrowser.IPublicClientApplication;\n /**\n * Return the MSAL account if not set yet\n * @returns MSAL application\n */\n async function getApp(): Promise<msalBrowser.IPublicClientApplication> {\n if (!app) {\n // Prepare the MSAL application\n app = await msalBrowser.PublicClientApplication.createPublicClientApplication(msalConfig);\n\n // setting the account right after the app is created.\n if (account) {\n app.setActiveAccount(publicToMsal(account));\n }\n }\n\n return 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 async function handleBrowserResult(\n result?: msalBrowser.AuthenticationResult,\n ): Promise<AuthenticationRecord | undefined> {\n try {\n const msalApp = await getApp();\n if (result && result.account) {\n logger.info(`MSAL Browser V2 authentication successful.`);\n msalApp.setActiveAccount(result.account);\n return msalToPublic(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 = msalApp.getActiveAccount();\n if (activeAccount) {\n return msalToPublic(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 allAccounts = app.getAllAccounts();\n if (allAccounts.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 logger.info(\n `More than one account was found authenticated for this Client ID and Tenant ID.\n However, no \"authenticationRecord\" has been provided for this credential,\n therefore we're unable to pick between these accounts.\n A new login attempt will be requested, to ensure the correct account is picked.\n To 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 msalApp.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 (allAccounts.length === 1) {\n const msalAccount = allAccounts[0];\n msalApp.setActiveAccount(msalAccount);\n return msalToPublic(clientId, msalAccount);\n }\n\n logger.info(`No accounts were found through MSAL.`);\n } catch (e: any) {\n logger.info(`Failed to acquire token through MSAL. ${e.message}`);\n }\n return;\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 function handleResult(\n scopes: string | string[],\n result?: MsalResult,\n getTokenOptions?: GetTokenOptions,\n ): AccessToken {\n if (result?.account) {\n account = msalToPublic(clientId, result.account);\n }\n ensureValidMsalToken(scopes, result, getTokenOptions);\n logger.getToken.info(formatSuccess(scopes));\n return {\n token: result.accessToken,\n expiresOnTimestamp: result.expiresOn.getTime(),\n refreshAfterTimestamp: result.refreshOn?.getTime(),\n tokenType: \"Bearer\",\n };\n }\n\n /**\n * Uses MSAL to handle the redirect.\n */\n async function handleRedirect(): Promise<AuthenticationRecord | undefined> {\n const msalApp = await getApp();\n return handleBrowserResult((await msalApp.handleRedirectPromise(redirectHash)) || undefined);\n }\n\n /**\n * Uses MSAL to retrieve the active account.\n */\n async function getActiveAccount(): Promise<AuthenticationRecord | undefined> {\n const msalApp = await getApp();\n const activeAccount = msalApp.getActiveAccount();\n if (!activeAccount) {\n return;\n }\n return msalToPublic(clientId, activeAccount);\n }\n\n /**\n * Uses MSAL to trigger a redirect or a popup login.\n */\n async function 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: loginHint,\n };\n const msalApp = await getApp();\n switch (loginStyle) {\n case \"redirect\": {\n await app.loginRedirect(loginRequest);\n return;\n }\n case \"popup\":\n return handleBrowserResult(await msalApp.loginPopup(loginRequest));\n }\n }\n\n /**\n * Tries to retrieve the token silently using MSAL.\n */\n async function getTokenSilent(\n scopes: string[],\n getTokenOptions?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const activeAccount = await getActiveAccount();\n if (!activeAccount) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions,\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: getTokenOptions?.authority || msalConfig.auth.authority!,\n correlationId: getTokenOptions?.correlationId,\n claims: getTokenOptions?.claims,\n account: publicToMsal(activeAccount),\n forceRefresh: false,\n scopes,\n };\n\n try {\n logger.info(\"Attempting to acquire token silently\");\n const msalApp = await getApp();\n const response = await msalApp.acquireTokenSilent(parameters);\n return 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 through interactive methods.\n */\n async function getTokenInteractive(\n scopes: string[],\n getTokenOptions?: CredentialFlowGetTokenOptions,\n ): Promise<AccessToken> {\n const activeAccount = await getActiveAccount();\n if (!activeAccount) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions,\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: getTokenOptions?.authority || msalConfig.auth.authority!,\n correlationId: getTokenOptions?.correlationId,\n claims: getTokenOptions?.claims,\n account: publicToMsal(activeAccount),\n loginHint: loginHint,\n scopes,\n };\n const msalApp = await getApp();\n switch (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 msalApp.acquireTokenRedirect(parameters);\n return { token: \"\", expiresOnTimestamp: 0, tokenType: \"Bearer\" };\n case \"popup\":\n return handleResult(scopes, await app.acquireTokenPopup(parameters));\n }\n }\n\n /**\n * Attempts to get token through the silent flow.\n * If failed, get token through interactive method with `doGetToken` method.\n */\n async function getToken(\n scopes: string[],\n getTokenOptions: CredentialFlowGetTokenOptions = {},\n ): Promise<AccessToken> {\n const getTokenTenantId =\n processMultiTenantRequest(tenantId, getTokenOptions, additionallyAllowedTenantIds) ||\n tenantId;\n\n if (!getTokenOptions.authority) {\n getTokenOptions.authority = getAuthority(getTokenTenantId, authorityHost);\n }\n\n // We ensure that redirection is handled at this point.\n await handleRedirect();\n\n if (!(await getActiveAccount()) && !disableAutomaticAuthentication) {\n await login(scopes);\n }\n\n // Attempts to get the token silently; else, falls back to interactive method.\n try {\n return await getTokenSilent(scopes, getTokenOptions);\n } catch (err: any) {\n if (err.name !== \"AuthenticationRequiredError\") {\n throw err;\n }\n if (getTokenOptions?.disableAutomaticAuthentication) {\n throw new AuthenticationRequiredError({\n scopes,\n getTokenOptions,\n message:\n \"Automatic authentication has been disabled. You may call the authenticate() method.\",\n });\n }\n logger.info(`Silent authentication failed, falling back to interactive method ${loginStyle}`);\n return getTokenInteractive(scopes, getTokenOptions);\n }\n }\n return {\n getActiveAccount,\n getToken,\n };\n}\n"]}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import type { AuthenticationRecord } from "../types.js";
|
2
|
+
import type { BrowserLoginStyle } from "../../credentials/interactiveBrowserCredentialOptions.js";
|
3
|
+
import type { LogPolicyOptions } from "@azure/core-rest-pipeline";
|
4
|
+
import type { MultiTenantTokenCredentialOptions } from "../../credentials/multiTenantTokenCredentialOptions.js";
|
5
|
+
import type { CredentialLogger } from "../../util/logging.js";
|
6
|
+
/**
|
7
|
+
* Options for the MSAL browser flows.
|
8
|
+
* @internal
|
9
|
+
*/
|
10
|
+
export interface MsalBrowserFlowOptions {
|
11
|
+
logger: CredentialLogger;
|
12
|
+
/**
|
13
|
+
* The Client ID of the Microsoft Entra application that users will sign into.
|
14
|
+
* This parameter is required on the browser.
|
15
|
+
*/
|
16
|
+
clientId?: string;
|
17
|
+
/**
|
18
|
+
* The Microsoft Entra tenant (directory) ID.
|
19
|
+
*/
|
20
|
+
tenantId?: string;
|
21
|
+
/**
|
22
|
+
* The authority host to use for authentication requests.
|
23
|
+
* Possible values are available through {@link AzureAuthorityHosts}.
|
24
|
+
* The default is "https://login.microsoftonline.com".
|
25
|
+
*/
|
26
|
+
authorityHost?: string;
|
27
|
+
/**
|
28
|
+
* Result of a previous authentication that can be used to retrieve the cached credentials of each individual account.
|
29
|
+
* This is necessary to provide in case the application wants to work with more than one account per
|
30
|
+
* Client ID and Tenant ID pair.
|
31
|
+
*
|
32
|
+
* This record can be retrieved by calling to the credential's `authenticate()` method, as follows:
|
33
|
+
*
|
34
|
+
* const authenticationRecord = await credential.authenticate();
|
35
|
+
*
|
36
|
+
*/
|
37
|
+
authenticationRecord?: AuthenticationRecord;
|
38
|
+
/**
|
39
|
+
* Makes getToken throw if a manual authentication is necessary.
|
40
|
+
* Developers will need to call to `authenticate()` to control when to manually authenticate.
|
41
|
+
*/
|
42
|
+
disableAutomaticAuthentication?: boolean;
|
43
|
+
/**
|
44
|
+
* The field determines whether instance discovery is performed when attempting to authenticate.
|
45
|
+
* Setting this to `true` will completely disable both instance discovery and authority validation.
|
46
|
+
* As a result, it's crucial to ensure that the configured authority host is valid and trustworthy.
|
47
|
+
* This functionality is intended for use in scenarios where the metadata endpoint cannot be reached, such as in private clouds or Azure Stack.
|
48
|
+
* The process of instance discovery entails retrieving authority metadata from https://login.microsoft.com/ to validate the authority.
|
49
|
+
*/
|
50
|
+
disableInstanceDiscovery?: boolean;
|
51
|
+
/**
|
52
|
+
* Options for multi-tenant applications which allows for additionally allowed tenants.
|
53
|
+
*/
|
54
|
+
tokenCredentialOptions: MultiTenantTokenCredentialOptions;
|
55
|
+
/**
|
56
|
+
* Gets the redirect URI of the application. This should be same as the value
|
57
|
+
* in the application registration portal. Defaults to `window.location.href`.
|
58
|
+
* This field is no longer required for Node.js.
|
59
|
+
*/
|
60
|
+
redirectUri?: string;
|
61
|
+
/**
|
62
|
+
* Specifies whether a redirect or a popup window should be used to
|
63
|
+
* initiate the user authentication flow. Possible values are "redirect"
|
64
|
+
* or "popup" (default) for browser and "popup" (default) for node.
|
65
|
+
*
|
66
|
+
*/
|
67
|
+
loginStyle: BrowserLoginStyle;
|
68
|
+
/**
|
69
|
+
* loginHint allows a user name to be pre-selected for interactive logins.
|
70
|
+
* Setting this option skips the account selection prompt and immediately attempts to login with the specified account.
|
71
|
+
*/
|
72
|
+
loginHint?: string;
|
73
|
+
/**
|
74
|
+
* Allows users to configure settings for logging policy options, allow logging account information and personally identifiable information for customer support.
|
75
|
+
*/
|
76
|
+
loggingOptions?: LogPolicyOptions & {
|
77
|
+
/**
|
78
|
+
* Allows logging account information once the authentication flow succeeds.
|
79
|
+
*/
|
80
|
+
allowLoggingAccountIdentifiers?: boolean;
|
81
|
+
/**
|
82
|
+
* Allows logging personally identifiable information for customer support.
|
83
|
+
*/
|
84
|
+
enableUnsafeSupportLogging?: boolean;
|
85
|
+
};
|
86
|
+
}
|
87
|
+
//# sourceMappingURL=msalBrowserOptions.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"msalBrowserOptions.d.ts","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalBrowserOptions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0DAA0D,CAAC;AAClG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wDAAwD,CAAC;AAChH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,gBAAgB,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;;;;OASG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;IAEzC;;;;;;OAMG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;OAEG;IACH,sBAAsB,EAAE,iCAAiC,CAAC;IAE1D;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;OAKG;IACH,UAAU,EAAE,iBAAiB,CAAC;IAE9B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,cAAc,CAAC,EAAE,gBAAgB,GAAG;QAClC;;WAEG;QACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;QACzC;;WAEG;QACH,0BAA0B,CAAC,EAAE,OAAO,CAAC;KACtC,CAAC;CACH"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"msalBrowserOptions.js","sourceRoot":"","sources":["../../../../src/msal/browserFlows/msalBrowserOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AuthenticationRecord } from \"../types.js\";\nimport type { BrowserLoginStyle } from \"../../credentials/interactiveBrowserCredentialOptions.js\";\nimport type { LogPolicyOptions } from \"@azure/core-rest-pipeline\";\nimport type { MultiTenantTokenCredentialOptions } from \"../../credentials/multiTenantTokenCredentialOptions.js\";\nimport type { CredentialLogger } from \"../../util/logging.js\";\n\n/**\n * Options for the MSAL browser flows.\n * @internal\n */\nexport interface MsalBrowserFlowOptions {\n logger: CredentialLogger;\n\n /**\n * The Client ID of the Microsoft Entra application that users will sign into.\n * This parameter is required on the browser.\n */\n clientId?: string;\n\n /**\n * The Microsoft Entra tenant (directory) ID.\n */\n tenantId?: string;\n\n /**\n * The authority host to use for authentication requests.\n * Possible values are available through {@link AzureAuthorityHosts}.\n * The default is \"https://login.microsoftonline.com\".\n */\n authorityHost?: string;\n\n /**\n * Result of a previous authentication that can be used to retrieve the cached credentials of each individual account.\n * This is necessary to provide in case the application wants to work with more than one account per\n * Client ID and Tenant ID pair.\n *\n * This record can be retrieved by calling to the credential's `authenticate()` method, as follows:\n *\n * const authenticationRecord = await credential.authenticate();\n *\n */\n authenticationRecord?: AuthenticationRecord;\n\n /**\n * Makes getToken throw if a manual authentication is necessary.\n * Developers will need to call to `authenticate()` to control when to manually authenticate.\n */\n disableAutomaticAuthentication?: boolean;\n\n /**\n * The field determines whether instance discovery is performed when attempting to authenticate.\n * Setting this to `true` will completely disable both instance discovery and authority validation.\n * As a result, it's crucial to ensure that the configured authority host is valid and trustworthy.\n * This functionality is intended for use in scenarios where the metadata endpoint cannot be reached, such as in private clouds or Azure Stack.\n * The process of instance discovery entails retrieving authority metadata from https://login.microsoft.com/ to validate the authority.\n */\n disableInstanceDiscovery?: boolean;\n\n /**\n * Options for multi-tenant applications which allows for additionally allowed tenants.\n */\n tokenCredentialOptions: MultiTenantTokenCredentialOptions;\n\n /**\n * Gets the redirect URI of the application. This should be same as the value\n * in the application registration portal. Defaults to `window.location.href`.\n * This field is no longer required for Node.js.\n */\n redirectUri?: string;\n\n /**\n * Specifies whether a redirect or a popup window should be used to\n * initiate the user authentication flow. Possible values are \"redirect\"\n * or \"popup\" (default) for browser and \"popup\" (default) for node.\n *\n */\n loginStyle: BrowserLoginStyle;\n\n /**\n * loginHint allows a user name to be pre-selected for interactive logins.\n * Setting this option skips the account selection prompt and immediately attempts to login with the specified account.\n */\n loginHint?: string;\n\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}\n"]}
|
@@ -22,6 +22,8 @@ export declare class UsernamePasswordCredential implements TokenCredential {
|
|
22
22
|
* @param username - The user account's e-mail address (user name).
|
23
23
|
* @param password - The user account's account password
|
24
24
|
* @param options - Options for configuring the client which makes the authentication request.
|
25
|
+
*
|
26
|
+
* @deprecated UsernamePasswordCredential is deprecated. Use a more secure credential. See https://aka.ms/azsdk/identity/mfa for details.
|
25
27
|
*/
|
26
28
|
constructor(tenantId: string, clientId: string, username: string, password: string, options?: UsernamePasswordCredentialOptions);
|
27
29
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usernamePasswordCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/usernamePasswordCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAStF,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAOhG;;;;;GAKG;AACH,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,4BAA4B,CAAW;IAC/C,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IAEzB
|
1
|
+
{"version":3,"file":"usernamePasswordCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/usernamePasswordCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAStF,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAOhG;;;;;GAKG;AACH,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,4BAA4B,CAAW;IAC/C,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IAEzB;;;;;;;;;;;;OAYG;gBAED,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,iCAAsC;IAwCjD;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;CAsB/F"}
|
@@ -27,6 +27,8 @@ class UsernamePasswordCredential {
|
|
27
27
|
* @param username - The user account's e-mail address (user name).
|
28
28
|
* @param password - The user account's account password
|
29
29
|
* @param options - Options for configuring the client which makes the authentication request.
|
30
|
+
*
|
31
|
+
* @deprecated UsernamePasswordCredential is deprecated. Use a more secure credential. See https://aka.ms/azsdk/identity/mfa for details.
|
30
32
|
*/
|
31
33
|
constructor(tenantId, clientId, username, password, options = {}) {
|
32
34
|
if (!tenantId) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usernamePasswordCredential.js","sourceRoot":"","sources":["../../../src/credentials/usernamePasswordCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC,mEAAmE;AACnE,+DAGkC;AAElC,4CAA0D;AAE1D,mDAAsD;AACtD,yDAAqD;AACrD,mDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,4BAA4B,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,MAAa,0BAA0B;IAOrC
|
1
|
+
{"version":3,"file":"usernamePasswordCredential.js","sourceRoot":"","sources":["../../../src/credentials/usernamePasswordCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC,mEAAmE;AACnE,+DAGkC;AAElC,4CAA0D;AAE1D,mDAAsD;AACtD,yDAAqD;AACrD,mDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,4BAA4B,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,MAAa,0BAA0B;IAOrC;;;;;;;;;;;;OAYG;IACH,YACE,QAAgB,EAChB,QAAgB,EAChB,QAAgB,EAChB,QAAgB,EAChB,UAA6C,EAAE;QAE/C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,sCAA0B,CAClC,gKAAgK,CACjK,CAAC;QACJ,CAAC;QAED,IA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U,CACX,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAnGD,gEAmGC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport type { UsernamePasswordCredentialOptions } from \"./usernamePasswordCredentialOptions.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst logger = credentialLogger(\"UsernamePasswordCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID with a user's\n * username and password. This credential requires a high degree of\n * trust so you should only use it when other, more secure credential\n * types can't be used.\n */\nexport class UsernamePasswordCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private username: string;\n private password: string;\n\n /**\n * Creates an instance of the UsernamePasswordCredential with the details\n * needed to authenticate against Microsoft Entra ID with a username\n * and password.\n *\n * @param tenantId - The Microsoft Entra tenant (directory).\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param username - The user account's e-mail address (user name).\n * @param password - The user account's account password\n * @param options - Options for configuring the client which makes the authentication request.\n *\n * @deprecated UsernamePasswordCredential is deprecated. Use a more secure credential. See https://aka.ms/azsdk/identity/mfa for details.\n */\n constructor(\n tenantId: string,\n clientId: string,\n username: string,\n password: string,\n options: UsernamePasswordCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!username) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: username is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!password) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: password is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.username = username;\n this.password = password;\n\n this.msalClient = createMsalClient(clientId, this.tenantId, {\n ...options,\n tokenCredentialOptions: options ?? {},\n });\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the user provided the option `disableAutomaticAuthentication`,\n * once the token can't be retrieved silently,\n * this method won't attempt to request user interaction to retrieve the token.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n return this.msalClient.getTokenByUsernamePassword(\n arrayScopes,\n this.username,\n this.password,\n newOptions,\n );\n },\n );\n }\n}\n"]}
|