@azure/msal-browser 3.14.0 → 3.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/IPublicClientApplication.mjs +1 -1
- package/dist/app/PublicClientApplication.d.ts +17 -0
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.mjs +37 -9
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientNext.d.ts +3 -0
- package/dist/app/PublicClientNext.d.ts.map +1 -1
- package/dist/app/PublicClientNext.mjs +4 -1
- package/dist/app/PublicClientNext.mjs.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
- package/dist/cache/AccountManager.d.ts +49 -0
- package/dist/cache/AccountManager.d.ts.map +1 -0
- package/dist/cache/AccountManager.mjs +131 -0
- package/dist/cache/AccountManager.mjs.map +1 -0
- package/dist/cache/AsyncMemoryStorage.mjs +1 -1
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +9 -2
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/BrowserStorage.mjs +1 -1
- package/dist/cache/DatabaseStorage.mjs +1 -1
- package/dist/cache/MemoryStorage.mjs +1 -1
- package/dist/cache/TokenCache.mjs +1 -1
- package/dist/config/Configuration.d.ts +3 -1
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +1 -1
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/controllers/ControllerFactory.d.ts.map +1 -1
- package/dist/controllers/ControllerFactory.mjs +10 -11
- package/dist/controllers/ControllerFactory.mjs.map +1 -1
- package/dist/controllers/NestedAppAuthController.d.ts +118 -10
- package/dist/controllers/NestedAppAuthController.d.ts.map +1 -1
- package/dist/controllers/NestedAppAuthController.mjs +227 -83
- package/dist/controllers/NestedAppAuthController.mjs.map +1 -1
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +28 -82
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/controllers/UnknownOperatingContextController.mjs +1 -1
- package/dist/crypto/BrowserCrypto.mjs +1 -1
- package/dist/crypto/CryptoOps.mjs +1 -1
- package/dist/crypto/PkceGenerator.mjs +1 -1
- package/dist/crypto/SignedHttpRequest.mjs +1 -1
- package/dist/encode/Base64Decode.mjs +1 -1
- package/dist/encode/Base64Encode.mjs +1 -1
- package/dist/error/BrowserAuthError.mjs +1 -1
- package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
- package/dist/error/NativeAuthError.mjs +1 -1
- package/dist/error/NativeAuthErrorCodes.mjs +1 -1
- package/dist/error/NestedAppAuthError.mjs +1 -1
- package/dist/event/EventHandler.mjs +1 -1
- package/dist/event/EventMessage.mjs +1 -1
- package/dist/event/EventType.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/interaction_client/BaseInteractionClient.mjs +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
- package/dist/interaction_client/NativeInteractionClient.mjs +1 -1
- package/dist/interaction_client/PopupClient.mjs +1 -1
- package/dist/interaction_client/RedirectClient.mjs +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +1 -1
- package/dist/interaction_client/SilentCacheClient.mjs +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +1 -1
- package/dist/interaction_client/SilentRefreshClient.mjs +1 -1
- package/dist/interaction_client/StandardInteractionClient.mjs +1 -1
- package/dist/interaction_handler/InteractionHandler.mjs +1 -1
- package/dist/interaction_handler/RedirectHandler.mjs +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +1 -1
- package/dist/naa/BridgeAccountContext.d.ts +13 -0
- package/dist/naa/BridgeAccountContext.d.ts.map +1 -0
- package/dist/naa/BridgeCapabilities.d.ts +1 -1
- package/dist/naa/BridgeCapabilities.d.ts.map +1 -1
- package/dist/naa/BridgeError.mjs +1 -1
- package/dist/naa/BridgeProxy.d.ts +3 -2
- package/dist/naa/BridgeProxy.d.ts.map +1 -1
- package/dist/naa/BridgeProxy.mjs +9 -7
- package/dist/naa/BridgeProxy.mjs.map +1 -1
- package/dist/naa/BridgeRequestEnvelope.d.ts +1 -1
- package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -1
- package/dist/naa/BridgeStatusCode.mjs +1 -1
- package/dist/naa/IBridgeProxy.d.ts +2 -2
- package/dist/naa/IBridgeProxy.d.ts.map +1 -1
- package/dist/naa/InitContext.d.ts +2 -0
- package/dist/naa/InitContext.d.ts.map +1 -1
- package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +12 -2
- package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -1
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs +43 -6
- package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -1
- package/dist/navigation/NavigationClient.mjs +1 -1
- package/dist/network/FetchClient.mjs +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
- package/dist/operatingcontext/{TeamsAppOperatingContext.d.ts → NestedAppOperatingContext.d.ts} +8 -6
- package/dist/operatingcontext/NestedAppOperatingContext.d.ts.map +1 -0
- package/dist/operatingcontext/{TeamsAppOperatingContext.mjs → NestedAppOperatingContext.mjs} +17 -30
- package/dist/operatingcontext/NestedAppOperatingContext.mjs.map +1 -0
- package/dist/operatingcontext/StandardOperatingContext.d.ts.map +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/UnknownOperatingContext.d.ts +5 -5
- package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -1
- package/dist/operatingcontext/UnknownOperatingContext.mjs +8 -8
- package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/request/RequestHelpers.mjs +1 -1
- package/dist/response/ResponseHandler.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
- package/dist/utils/BrowserConstants.mjs +1 -1
- package/dist/utils/BrowserProtocolUtils.mjs +1 -1
- package/dist/utils/BrowserUtils.mjs +1 -1
- package/lib/msal-browser.cjs +10469 -10204
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +10469 -10204
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +69 -69
- package/package.json +5 -3
- package/src/app/PublicClientApplication.ts +43 -8
- package/src/app/PublicClientNext.ts +3 -0
- package/src/cache/AccountManager.ts +184 -0
- package/src/cache/BrowserCacheManager.ts +11 -2
- package/src/config/Configuration.ts +3 -1
- package/src/controllers/ControllerFactory.ts +9 -11
- package/src/controllers/NestedAppAuthController.ts +375 -82
- package/src/controllers/StandardController.ts +49 -107
- package/src/index.ts +5 -1
- package/src/naa/BridgeAccountContext.ts +17 -0
- package/src/naa/BridgeCapabilities.ts +2 -1
- package/src/naa/BridgeProxy.ts +11 -6
- package/src/naa/BridgeRequestEnvelope.ts +1 -6
- package/src/naa/IBridgeProxy.ts +2 -2
- package/src/naa/InitContext.ts +2 -0
- package/src/naa/mapping/NestedAppAuthAdapter.ts +68 -2
- package/src/operatingcontext/{TeamsAppOperatingContext.ts → NestedAppOperatingContext.ts} +15 -29
- package/src/operatingcontext/StandardOperatingContext.ts +1 -0
- package/src/operatingcontext/UnknownOperatingContext.ts +8 -7
- package/src/packageMetadata.ts +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +0 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +0 -1
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
BrowserCacheManager,
|
|
34
34
|
DEFAULT_BROWSER_CACHE_MANAGER,
|
|
35
35
|
} from "../cache/BrowserCacheManager";
|
|
36
|
+
import * as AccountManager from "../cache/AccountManager";
|
|
36
37
|
import { BrowserConfiguration, CacheOptions } from "../config/Configuration";
|
|
37
38
|
import {
|
|
38
39
|
InteractionType,
|
|
@@ -100,6 +101,18 @@ function getAccountType(
|
|
|
100
101
|
return "AAD";
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
function preflightCheck(
|
|
105
|
+
initialized: boolean,
|
|
106
|
+
performanceEvent: InProgressPerformanceEvent
|
|
107
|
+
) {
|
|
108
|
+
try {
|
|
109
|
+
BrowserUtils.preflightCheck(initialized);
|
|
110
|
+
} catch (e) {
|
|
111
|
+
performanceEvent.end({ success: false }, e);
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
103
116
|
export class StandardController implements IController {
|
|
104
117
|
// OperatingContext
|
|
105
118
|
protected readonly operatingContext: StandardOperatingContext;
|
|
@@ -663,7 +676,7 @@ export class StandardController implements IController {
|
|
|
663
676
|
|
|
664
677
|
try {
|
|
665
678
|
this.logger.verbose("acquireTokenPopup called", correlationId);
|
|
666
|
-
|
|
679
|
+
preflightCheck(this.initialized, atPopupMeasurement);
|
|
667
680
|
this.browserStorage.setInteractionInProgress(true);
|
|
668
681
|
} catch (e) {
|
|
669
682
|
// Since this function is syncronous we need to reject
|
|
@@ -833,18 +846,18 @@ export class StandardController implements IController {
|
|
|
833
846
|
prompt: request.prompt,
|
|
834
847
|
correlationId: correlationId,
|
|
835
848
|
};
|
|
836
|
-
BrowserUtils.preflightCheck(this.initialized);
|
|
837
849
|
this.ssoSilentMeasurement = this.performanceClient.startMeasurement(
|
|
838
850
|
PerformanceEvents.SsoSilent,
|
|
839
851
|
correlationId
|
|
840
852
|
);
|
|
841
|
-
this.ssoSilentMeasurement?.increment({
|
|
842
|
-
visibilityChangeCount: 0,
|
|
843
|
-
});
|
|
844
853
|
this.ssoSilentMeasurement?.add({
|
|
845
854
|
scenarioId: request.scenarioId,
|
|
846
855
|
accountType: getAccountType(request.account),
|
|
847
856
|
});
|
|
857
|
+
preflightCheck(this.initialized, this.ssoSilentMeasurement);
|
|
858
|
+
this.ssoSilentMeasurement?.increment({
|
|
859
|
+
visibilityChangeCount: 0,
|
|
860
|
+
});
|
|
848
861
|
|
|
849
862
|
document.addEventListener(
|
|
850
863
|
"visibilitychange",
|
|
@@ -936,16 +949,16 @@ export class StandardController implements IController {
|
|
|
936
949
|
): Promise<AuthenticationResult> {
|
|
937
950
|
const correlationId = this.getRequestCorrelationId(request);
|
|
938
951
|
this.logger.trace("acquireTokenByCode called", correlationId);
|
|
939
|
-
|
|
952
|
+
const atbcMeasurement = this.performanceClient.startMeasurement(
|
|
953
|
+
PerformanceEvents.AcquireTokenByCode,
|
|
954
|
+
correlationId
|
|
955
|
+
);
|
|
956
|
+
preflightCheck(this.initialized, atbcMeasurement);
|
|
940
957
|
this.eventHandler.emitEvent(
|
|
941
958
|
EventType.ACQUIRE_TOKEN_BY_CODE_START,
|
|
942
959
|
InteractionType.Silent,
|
|
943
960
|
request
|
|
944
961
|
);
|
|
945
|
-
const atbcMeasurement = this.performanceClient.startMeasurement(
|
|
946
|
-
PerformanceEvents.AcquireTokenByCode,
|
|
947
|
-
correlationId
|
|
948
|
-
);
|
|
949
962
|
atbcMeasurement.add({ scenarioId: request.scenarioId });
|
|
950
963
|
|
|
951
964
|
try {
|
|
@@ -1287,10 +1300,12 @@ export class StandardController implements IController {
|
|
|
1287
1300
|
* @returns Array of AccountInfo objects in cache
|
|
1288
1301
|
*/
|
|
1289
1302
|
getAllAccounts(accountFilter?: AccountFilter): AccountInfo[] {
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1303
|
+
return AccountManager.getAllAccounts(
|
|
1304
|
+
this.logger,
|
|
1305
|
+
this.browserStorage,
|
|
1306
|
+
this.isBrowserEnvironment,
|
|
1307
|
+
accountFilter
|
|
1308
|
+
);
|
|
1294
1309
|
}
|
|
1295
1310
|
|
|
1296
1311
|
/**
|
|
@@ -1299,26 +1314,11 @@ export class StandardController implements IController {
|
|
|
1299
1314
|
* @returns The first account found in the cache matching the provided filter or null if no account could be found.
|
|
1300
1315
|
*/
|
|
1301
1316
|
getAccount(accountFilter: AccountFilter): AccountInfo | null {
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
this.logger
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
const account: AccountInfo | null =
|
|
1309
|
-
this.browserStorage.getAccountInfoFilteredBy(accountFilter);
|
|
1310
|
-
|
|
1311
|
-
if (account) {
|
|
1312
|
-
this.logger.verbose(
|
|
1313
|
-
"getAccount: Account matching provided filter found, returning"
|
|
1314
|
-
);
|
|
1315
|
-
return account;
|
|
1316
|
-
} else {
|
|
1317
|
-
this.logger.verbose(
|
|
1318
|
-
"getAccount: No matching account found, returning null"
|
|
1319
|
-
);
|
|
1320
|
-
return null;
|
|
1321
|
-
}
|
|
1317
|
+
return AccountManager.getAccount(
|
|
1318
|
+
accountFilter,
|
|
1319
|
+
this.logger,
|
|
1320
|
+
this.browserStorage
|
|
1321
|
+
);
|
|
1322
1322
|
}
|
|
1323
1323
|
|
|
1324
1324
|
/**
|
|
@@ -1330,29 +1330,11 @@ export class StandardController implements IController {
|
|
|
1330
1330
|
* @returns The account object stored in MSAL
|
|
1331
1331
|
*/
|
|
1332
1332
|
getAccountByUsername(username: string): AccountInfo | null {
|
|
1333
|
-
|
|
1334
|
-
if (!username) {
|
|
1335
|
-
this.logger.warning("getAccountByUsername: No username provided");
|
|
1336
|
-
return null;
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
const account = this.browserStorage.getAccountInfoFilteredBy({
|
|
1333
|
+
return AccountManager.getAccountByUsername(
|
|
1340
1334
|
username,
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
"getAccountByUsername: Account matching username found, returning"
|
|
1345
|
-
);
|
|
1346
|
-
this.logger.verbosePii(
|
|
1347
|
-
`getAccountByUsername: Returning signed-in accounts matching username: ${username}`
|
|
1348
|
-
);
|
|
1349
|
-
return account;
|
|
1350
|
-
} else {
|
|
1351
|
-
this.logger.verbose(
|
|
1352
|
-
"getAccountByUsername: No matching account found, returning null"
|
|
1353
|
-
);
|
|
1354
|
-
return null;
|
|
1355
|
-
}
|
|
1335
|
+
this.logger,
|
|
1336
|
+
this.browserStorage
|
|
1337
|
+
);
|
|
1356
1338
|
}
|
|
1357
1339
|
|
|
1358
1340
|
/**
|
|
@@ -1363,31 +1345,11 @@ export class StandardController implements IController {
|
|
|
1363
1345
|
* @returns The account object stored in MSAL
|
|
1364
1346
|
*/
|
|
1365
1347
|
getAccountByHomeId(homeAccountId: string): AccountInfo | null {
|
|
1366
|
-
|
|
1367
|
-
if (!homeAccountId) {
|
|
1368
|
-
this.logger.warning(
|
|
1369
|
-
"getAccountByHomeId: No homeAccountId provided"
|
|
1370
|
-
);
|
|
1371
|
-
return null;
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
const account = this.browserStorage.getAccountInfoFilteredBy({
|
|
1348
|
+
return AccountManager.getAccountByHomeId(
|
|
1375
1349
|
homeAccountId,
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
"getAccountByHomeId: Account matching homeAccountId found, returning"
|
|
1380
|
-
);
|
|
1381
|
-
this.logger.verbosePii(
|
|
1382
|
-
`getAccountByHomeId: Returning signed-in accounts matching homeAccountId: ${homeAccountId}`
|
|
1383
|
-
);
|
|
1384
|
-
return account;
|
|
1385
|
-
} else {
|
|
1386
|
-
this.logger.verbose(
|
|
1387
|
-
"getAccountByHomeId: No matching account found, returning null"
|
|
1388
|
-
);
|
|
1389
|
-
return null;
|
|
1390
|
-
}
|
|
1350
|
+
this.logger,
|
|
1351
|
+
this.browserStorage
|
|
1352
|
+
);
|
|
1391
1353
|
}
|
|
1392
1354
|
|
|
1393
1355
|
/**
|
|
@@ -1398,31 +1360,11 @@ export class StandardController implements IController {
|
|
|
1398
1360
|
* @returns The account object stored in MSAL
|
|
1399
1361
|
*/
|
|
1400
1362
|
getAccountByLocalId(localAccountId: string): AccountInfo | null {
|
|
1401
|
-
|
|
1402
|
-
if (!localAccountId) {
|
|
1403
|
-
this.logger.warning(
|
|
1404
|
-
"getAccountByLocalId: No localAccountId provided"
|
|
1405
|
-
);
|
|
1406
|
-
return null;
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
const account = this.browserStorage.getAccountInfoFilteredBy({
|
|
1363
|
+
return AccountManager.getAccountByLocalId(
|
|
1410
1364
|
localAccountId,
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
"getAccountByLocalId: Account matching localAccountId found, returning"
|
|
1415
|
-
);
|
|
1416
|
-
this.logger.verbosePii(
|
|
1417
|
-
`getAccountByLocalId: Returning signed-in accounts matching localAccountId: ${localAccountId}`
|
|
1418
|
-
);
|
|
1419
|
-
return account;
|
|
1420
|
-
} else {
|
|
1421
|
-
this.logger.verbose(
|
|
1422
|
-
"getAccountByLocalId: No matching account found, returning null"
|
|
1423
|
-
);
|
|
1424
|
-
return null;
|
|
1425
|
-
}
|
|
1365
|
+
this.logger,
|
|
1366
|
+
this.browserStorage
|
|
1367
|
+
);
|
|
1426
1368
|
}
|
|
1427
1369
|
|
|
1428
1370
|
/**
|
|
@@ -1430,14 +1372,14 @@ export class StandardController implements IController {
|
|
|
1430
1372
|
* @param account
|
|
1431
1373
|
*/
|
|
1432
1374
|
setActiveAccount(account: AccountInfo | null): void {
|
|
1433
|
-
|
|
1375
|
+
AccountManager.setActiveAccount(account, this.browserStorage);
|
|
1434
1376
|
}
|
|
1435
1377
|
|
|
1436
1378
|
/**
|
|
1437
1379
|
* Gets the currently active account
|
|
1438
1380
|
*/
|
|
1439
1381
|
getActiveAccount(): AccountInfo | null {
|
|
1440
|
-
return this.browserStorage
|
|
1382
|
+
return AccountManager.getActiveAccount(this.browserStorage);
|
|
1441
1383
|
}
|
|
1442
1384
|
|
|
1443
1385
|
// #endregion
|
|
@@ -1898,7 +1840,7 @@ export class StandardController implements IController {
|
|
|
1898
1840
|
scenarioId: request.scenarioId,
|
|
1899
1841
|
});
|
|
1900
1842
|
|
|
1901
|
-
|
|
1843
|
+
preflightCheck(this.initialized, atsMeasurement);
|
|
1902
1844
|
this.logger.verbose("acquireTokenSilent called", correlationId);
|
|
1903
1845
|
|
|
1904
1846
|
const account = request.account || this.getActiveAccount();
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
import * as BrowserUtils from "./utils/BrowserUtils";
|
|
12
12
|
export { BrowserUtils };
|
|
13
13
|
|
|
14
|
-
export {
|
|
14
|
+
export {
|
|
15
|
+
PublicClientApplication,
|
|
16
|
+
createNestablePublicClientApplication,
|
|
17
|
+
createStandardPublicClientApplication,
|
|
18
|
+
} from "./app/PublicClientApplication";
|
|
15
19
|
export { PublicClientNext } from "./app/PublicClientNext";
|
|
16
20
|
export { IController } from "./controllers/IController";
|
|
17
21
|
export {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* AccountContext is used to pass account information when the bridge is initialized
|
|
8
|
+
*
|
|
9
|
+
* NAA (MetaOS) apps are created and destroyed for the same session multiple times.
|
|
10
|
+
* `AccountContext` helps in booting up the cached account when the bridge
|
|
11
|
+
* is recreated for a new NAA instance in the same auth session.
|
|
12
|
+
*/
|
|
13
|
+
export interface AccountContext {
|
|
14
|
+
homeAccountId: string;
|
|
15
|
+
environment: string;
|
|
16
|
+
tenantId: string;
|
|
17
|
+
}
|
package/src/naa/BridgeProxy.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { AccountInfo } from "./AccountInfo";
|
|
7
6
|
import { AuthBridge, AuthBridgeResponse } from "./AuthBridge";
|
|
8
7
|
import { AuthResult } from "./AuthResult";
|
|
9
8
|
import { BridgeCapabilities } from "./BridgeCapabilities";
|
|
9
|
+
import { AccountContext } from "./BridgeAccountContext";
|
|
10
10
|
import { BridgeError } from "./BridgeError";
|
|
11
11
|
import { BridgeRequest } from "./BridgeRequest";
|
|
12
12
|
import { BridgeRequestEnvelope, BridgeMethods } from "./BridgeRequestEnvelope";
|
|
@@ -33,6 +33,7 @@ export class BridgeProxy implements IBridgeProxy {
|
|
|
33
33
|
sdkName: string;
|
|
34
34
|
sdkVersion: string;
|
|
35
35
|
capabilities?: BridgeCapabilities;
|
|
36
|
+
accountContext?: AccountContext;
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* initializeNestedAppAuthBridge - Initializes the bridge to the host app
|
|
@@ -80,6 +81,7 @@ export class BridgeProxy implements IBridgeProxy {
|
|
|
80
81
|
messageType: "NestedAppAuthRequest",
|
|
81
82
|
method: "GetInitContext",
|
|
82
83
|
requestId: BrowserCrypto.createNewGuid(),
|
|
84
|
+
sendTime: Date.now(),
|
|
83
85
|
};
|
|
84
86
|
const request: BridgeRequest = {
|
|
85
87
|
requestId: message.requestId,
|
|
@@ -134,15 +136,14 @@ export class BridgeProxy implements IBridgeProxy {
|
|
|
134
136
|
};
|
|
135
137
|
}
|
|
136
138
|
|
|
137
|
-
public async getActiveAccount(): Promise<AccountInfo> {
|
|
138
|
-
const result = await this.sendRequest("GetActiveAccount");
|
|
139
|
-
return BridgeProxy.validateBridgeResultOrThrow(result.account);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
139
|
public getHostCapabilities(): BridgeCapabilities | null {
|
|
143
140
|
return this.capabilities ?? null;
|
|
144
141
|
}
|
|
145
142
|
|
|
143
|
+
public getAccountContext(): AccountContext | null {
|
|
144
|
+
return this.accountContext ? this.accountContext : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
146
147
|
/**
|
|
147
148
|
* A method used to send a request to the bridge
|
|
148
149
|
* @param request A token request
|
|
@@ -156,6 +157,7 @@ export class BridgeProxy implements IBridgeProxy {
|
|
|
156
157
|
messageType: "NestedAppAuthRequest",
|
|
157
158
|
method: method,
|
|
158
159
|
requestId: BrowserCrypto.createNewGuid(),
|
|
160
|
+
sendTime: Date.now(),
|
|
159
161
|
...requestParams,
|
|
160
162
|
};
|
|
161
163
|
|
|
@@ -194,10 +196,12 @@ export class BridgeProxy implements IBridgeProxy {
|
|
|
194
196
|
private constructor(
|
|
195
197
|
sdkName: string,
|
|
196
198
|
sdkVersion: string,
|
|
199
|
+
accountContext?: AccountContext,
|
|
197
200
|
capabilities?: BridgeCapabilities
|
|
198
201
|
) {
|
|
199
202
|
this.sdkName = sdkName;
|
|
200
203
|
this.sdkVersion = sdkVersion;
|
|
204
|
+
this.accountContext = accountContext;
|
|
201
205
|
this.capabilities = capabilities;
|
|
202
206
|
}
|
|
203
207
|
|
|
@@ -210,6 +214,7 @@ export class BridgeProxy implements IBridgeProxy {
|
|
|
210
214
|
return new BridgeProxy(
|
|
211
215
|
response.sdkName,
|
|
212
216
|
response.sdkVersion,
|
|
217
|
+
response.accountContext,
|
|
213
218
|
response.capabilities
|
|
214
219
|
);
|
|
215
220
|
}
|
|
@@ -5,12 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { TokenRequest } from "./TokenRequest";
|
|
7
7
|
|
|
8
|
-
export type BridgeMethods =
|
|
9
|
-
| "GetToken"
|
|
10
|
-
| "GetActiveAccount"
|
|
11
|
-
| "GetAllAccounts"
|
|
12
|
-
| "GetInitContext"
|
|
13
|
-
| "GetTokenPopup";
|
|
8
|
+
export type BridgeMethods = "GetToken" | "GetInitContext" | "GetTokenPopup";
|
|
14
9
|
|
|
15
10
|
export type BridgeRequestEnvelope = {
|
|
16
11
|
messageType: "NestedAppAuthRequest";
|
package/src/naa/IBridgeProxy.ts
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { AccountInfo } from "./AccountInfo";
|
|
7
6
|
import { AuthResult } from "./AuthResult";
|
|
7
|
+
import { AccountContext } from "./BridgeAccountContext";
|
|
8
8
|
import { BridgeCapabilities } from "./BridgeCapabilities";
|
|
9
9
|
import { TokenRequest } from "./TokenRequest";
|
|
10
10
|
|
|
11
11
|
export interface IBridgeProxy {
|
|
12
12
|
getTokenInteractive(request: TokenRequest): Promise<AuthResult>;
|
|
13
13
|
getTokenSilent(request: TokenRequest): Promise<AuthResult>;
|
|
14
|
-
getActiveAccount(): Promise<AccountInfo>;
|
|
15
14
|
getHostCapabilities(): BridgeCapabilities | null;
|
|
15
|
+
getAccountContext(): AccountContext | null;
|
|
16
16
|
}
|
package/src/naa/InitContext.ts
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { BridgeCapabilities } from "./BridgeCapabilities";
|
|
7
|
+
import { AccountContext } from "./BridgeAccountContext";
|
|
7
8
|
|
|
8
9
|
export interface InitContext {
|
|
9
10
|
capabilities?: BridgeCapabilities;
|
|
10
11
|
sdkName: string;
|
|
11
12
|
sdkVersion: string;
|
|
13
|
+
accountContext?: AccountContext;
|
|
12
14
|
}
|
|
@@ -24,6 +24,11 @@ import {
|
|
|
24
24
|
StringUtils,
|
|
25
25
|
createClientAuthError,
|
|
26
26
|
OIDC_DEFAULT_SCOPES,
|
|
27
|
+
AccountInfo,
|
|
28
|
+
IdTokenEntity,
|
|
29
|
+
AccessTokenEntity,
|
|
30
|
+
TenantProfile,
|
|
31
|
+
buildTenantProfileFromIdTokenClaims,
|
|
27
32
|
} from "@azure/msal-common";
|
|
28
33
|
import { isBridgeError } from "../BridgeError";
|
|
29
34
|
import { BridgeStatusCode } from "../BridgeStatusCode";
|
|
@@ -110,6 +115,7 @@ export class NestedAppAuthAdapter {
|
|
|
110
115
|
);
|
|
111
116
|
const account = this.fromNaaAccountInfo(
|
|
112
117
|
response.account,
|
|
118
|
+
response.token.id_token,
|
|
113
119
|
idTokenClaims
|
|
114
120
|
);
|
|
115
121
|
const scopes = response.token.scope || request.scope;
|
|
@@ -123,7 +129,7 @@ export class NestedAppAuthAdapter {
|
|
|
123
129
|
idToken: response.token.id_token,
|
|
124
130
|
idTokenClaims,
|
|
125
131
|
accessToken: response.token.access_token,
|
|
126
|
-
fromCache:
|
|
132
|
+
fromCache: false,
|
|
127
133
|
expiresOn: expiresOn,
|
|
128
134
|
tokenType:
|
|
129
135
|
request.authenticationScheme || AuthenticationScheme.BEARER,
|
|
@@ -159,6 +165,7 @@ export class NestedAppAuthAdapter {
|
|
|
159
165
|
*/
|
|
160
166
|
public fromNaaAccountInfo(
|
|
161
167
|
fromAccount: NaaAccountInfo,
|
|
168
|
+
idToken?: string,
|
|
162
169
|
idTokenClaims?: TokenClaims
|
|
163
170
|
): MsalAccountInfo {
|
|
164
171
|
const effectiveIdTokenClaims =
|
|
@@ -183,6 +190,14 @@ export class NestedAppAuthAdapter {
|
|
|
183
190
|
|
|
184
191
|
const name = fromAccount.name || effectiveIdTokenClaims?.name;
|
|
185
192
|
|
|
193
|
+
const tenantProfiles = new Map<string, TenantProfile>();
|
|
194
|
+
|
|
195
|
+
const tenantProfile = buildTenantProfileFromIdTokenClaims(
|
|
196
|
+
homeAccountId,
|
|
197
|
+
effectiveIdTokenClaims
|
|
198
|
+
);
|
|
199
|
+
tenantProfiles.set(tenantId, tenantProfile);
|
|
200
|
+
|
|
186
201
|
const account: MsalAccountInfo = {
|
|
187
202
|
homeAccountId,
|
|
188
203
|
environment: fromAccount.environment,
|
|
@@ -190,8 +205,9 @@ export class NestedAppAuthAdapter {
|
|
|
190
205
|
username,
|
|
191
206
|
localAccountId,
|
|
192
207
|
name,
|
|
193
|
-
idToken:
|
|
208
|
+
idToken: idToken,
|
|
194
209
|
idTokenClaims: effectiveIdTokenClaims,
|
|
210
|
+
tenantProfiles,
|
|
195
211
|
};
|
|
196
212
|
|
|
197
213
|
return account;
|
|
@@ -249,4 +265,54 @@ export class NestedAppAuthAdapter {
|
|
|
249
265
|
return new AuthError("unknown_error", "An unknown error occurred");
|
|
250
266
|
}
|
|
251
267
|
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Returns an AuthenticationResult from the given cache items
|
|
271
|
+
*
|
|
272
|
+
* @param account
|
|
273
|
+
* @param idToken
|
|
274
|
+
* @param accessToken
|
|
275
|
+
* @param reqTimestamp
|
|
276
|
+
* @returns
|
|
277
|
+
*/
|
|
278
|
+
public toAuthenticationResultFromCache(
|
|
279
|
+
account: AccountInfo,
|
|
280
|
+
idToken: IdTokenEntity,
|
|
281
|
+
accessToken: AccessTokenEntity,
|
|
282
|
+
request: SilentRequest,
|
|
283
|
+
correlationId: string
|
|
284
|
+
): AuthenticationResult {
|
|
285
|
+
if (!idToken || !accessToken) {
|
|
286
|
+
throw createClientAuthError(ClientAuthErrorCodes.nullOrEmptyToken);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const idTokenClaims = AuthToken.extractTokenClaims(
|
|
290
|
+
idToken.secret,
|
|
291
|
+
this.crypto.base64Decode
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const scopes = accessToken.target || request.scopes.join(" ");
|
|
295
|
+
|
|
296
|
+
const authenticationResult: AuthenticationResult = {
|
|
297
|
+
authority: accessToken.environment || account.environment,
|
|
298
|
+
uniqueId: account.localAccountId,
|
|
299
|
+
tenantId: account.tenantId,
|
|
300
|
+
scopes: scopes.split(" "),
|
|
301
|
+
account,
|
|
302
|
+
idToken: idToken.secret,
|
|
303
|
+
idTokenClaims: idTokenClaims || {},
|
|
304
|
+
accessToken: accessToken.secret,
|
|
305
|
+
fromCache: true,
|
|
306
|
+
expiresOn: new Date(Number(accessToken.expiresOn) * 1000),
|
|
307
|
+
tokenType:
|
|
308
|
+
request.authenticationScheme || AuthenticationScheme.BEARER,
|
|
309
|
+
correlationId,
|
|
310
|
+
extExpiresOn: new Date(
|
|
311
|
+
Number(accessToken.extendedExpiresOn) * 1000
|
|
312
|
+
),
|
|
313
|
+
state: request.state,
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
return authenticationResult;
|
|
317
|
+
}
|
|
252
318
|
}
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
import { BaseOperatingContext } from "./BaseOperatingContext";
|
|
7
7
|
import { IBridgeProxy } from "../naa/IBridgeProxy";
|
|
8
8
|
import { BridgeProxy } from "../naa/BridgeProxy";
|
|
9
|
-
import {
|
|
9
|
+
import { AccountContext } from "../naa/BridgeAccountContext";
|
|
10
10
|
|
|
11
|
-
export class
|
|
11
|
+
export class NestedAppOperatingContext extends BaseOperatingContext {
|
|
12
12
|
protected bridgeProxy: IBridgeProxy | undefined = undefined;
|
|
13
|
-
protected
|
|
13
|
+
protected accountContext: AccountContext | null = null;
|
|
14
14
|
|
|
15
15
|
/*
|
|
16
16
|
* TODO: Once we have determine the bundling code return here to specify the name of the bundle
|
|
@@ -21,7 +21,7 @@ export class TeamsAppOperatingContext extends BaseOperatingContext {
|
|
|
21
21
|
/**
|
|
22
22
|
* Unique identifier for the operating context
|
|
23
23
|
*/
|
|
24
|
-
static readonly ID: string = "
|
|
24
|
+
static readonly ID: string = "NestedAppOperatingContext";
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Return the module name. Intended for use with import() to enable dynamic import
|
|
@@ -29,28 +29,25 @@ export class TeamsAppOperatingContext extends BaseOperatingContext {
|
|
|
29
29
|
* @returns
|
|
30
30
|
*/
|
|
31
31
|
getModuleName(): string {
|
|
32
|
-
return
|
|
32
|
+
return NestedAppOperatingContext.MODULE_NAME;
|
|
33
33
|
}
|
|
34
|
+
|
|
34
35
|
/**
|
|
35
36
|
* Returns the unique identifier for this operating context
|
|
36
37
|
* @returns string
|
|
37
38
|
*/
|
|
38
39
|
getId(): string {
|
|
39
|
-
return
|
|
40
|
+
return NestedAppOperatingContext.ID;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Returns the current BridgeProxy
|
|
45
|
+
* @returns IBridgeProxy | undefined
|
|
46
|
+
*/
|
|
42
47
|
getBridgeProxy(): IBridgeProxy | undefined {
|
|
43
48
|
return this.bridgeProxy;
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
getActiveAccount(): AccountInfo | undefined {
|
|
47
|
-
return this.activeAccount;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
setActiveAccount(account: AccountInfo): void {
|
|
51
|
-
this.activeAccount = account;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
51
|
/**
|
|
55
52
|
* Checks whether the operating context is available.
|
|
56
53
|
* Confirms that the code is running a browser rather. This is required.
|
|
@@ -62,26 +59,15 @@ export class TeamsAppOperatingContext extends BaseOperatingContext {
|
|
|
62
59
|
*
|
|
63
60
|
*/
|
|
64
61
|
|
|
65
|
-
if (!this.getConfig().auth.supportsNestedAppAuth) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
62
|
try {
|
|
70
63
|
if (typeof window !== "undefined") {
|
|
71
64
|
const bridgeProxy: IBridgeProxy = await BridgeProxy.create();
|
|
72
65
|
/*
|
|
73
|
-
* Because we want single sign on we
|
|
74
|
-
*
|
|
75
|
-
* this.
|
|
66
|
+
* Because we want single sign on we expect the host app to provide the account context
|
|
67
|
+
* with a min set of params that can be used to identify the account
|
|
68
|
+
* this.account = nestedApp.getAccountByFilter(bridgeProxy.getAccountContext());
|
|
76
69
|
*/
|
|
77
|
-
|
|
78
|
-
if (bridgeProxy.getHostCapabilities()?.queryAccount) {
|
|
79
|
-
this.activeAccount =
|
|
80
|
-
await bridgeProxy.getActiveAccount();
|
|
81
|
-
}
|
|
82
|
-
} catch {
|
|
83
|
-
// Ignore errors
|
|
84
|
-
}
|
|
70
|
+
this.accountContext = bridgeProxy.getAccountContext();
|
|
85
71
|
this.bridgeProxy = bridgeProxy;
|
|
86
72
|
this.available = bridgeProxy !== undefined;
|
|
87
73
|
}
|
|
@@ -17,6 +17,14 @@ export class UnknownOperatingContext extends BaseOperatingContext {
|
|
|
17
17
|
*/
|
|
18
18
|
static readonly ID: string = "UnknownOperatingContext";
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Returns the unique identifier for this operating context
|
|
22
|
+
* @returns string
|
|
23
|
+
*/
|
|
24
|
+
getId(): string {
|
|
25
|
+
return UnknownOperatingContext.ID;
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
/**
|
|
21
29
|
* Return the module name. Intended for use with import() to enable dynamic import
|
|
22
30
|
* of the implementation associated with this operating context
|
|
@@ -25,13 +33,6 @@ export class UnknownOperatingContext extends BaseOperatingContext {
|
|
|
25
33
|
getModuleName(): string {
|
|
26
34
|
return UnknownOperatingContext.MODULE_NAME;
|
|
27
35
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Returns the unique identifier for this operating context
|
|
30
|
-
* @returns string
|
|
31
|
-
*/
|
|
32
|
-
getId(): string {
|
|
33
|
-
return UnknownOperatingContext.ID;
|
|
34
|
-
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* Checks whether the operating context is available.
|
package/src/packageMetadata.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TeamsAppOperatingContext.d.ts","sourceRoot":"","sources":["../../src/operatingcontext/TeamsAppOperatingContext.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,qBAAa,wBAAyB,SAAQ,oBAAoB;IAC9D,SAAS,CAAC,WAAW,EAAE,YAAY,GAAG,SAAS,CAAa;IAC5D,SAAS,CAAC,aAAa,EAAE,WAAW,GAAG,SAAS,CAAa;IAM7D,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAM;IAEzC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAA8B;IAExD;;;;OAIG;IACH,aAAa,IAAI,MAAM;IAGvB;;;OAGG;IACH,KAAK,IAAI,MAAM;IAIf,cAAc,IAAI,YAAY,GAAG,SAAS;IAI1C,gBAAgB,IAAI,WAAW,GAAG,SAAS;IAI3C,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAI5C;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;CAsCvC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TeamsAppOperatingContext.mjs","sources":["../../src/operatingcontext/TeamsAppOperatingContext.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;AAGG;AAOG,MAAO,wBAAyB,SAAQ,oBAAoB,CAAA;AAAlE,IAAA,WAAA,GAAA;;QACc,IAAW,CAAA,WAAA,GAA6B,SAAS,CAAC;QAClD,IAAa,CAAA,aAAA,GAA4B,SAAS,CAAC;KAoFhE;AAvEG;;;;AAIG;IACH,aAAa,GAAA;QACT,OAAO,wBAAwB,CAAC,WAAW,CAAC;KAC/C;AACD;;;AAGG;IACH,KAAK,GAAA;QACD,OAAO,wBAAwB,CAAC,EAAE,CAAC;KACtC;IAED,cAAc,GAAA;QACV,OAAO,IAAI,CAAC,WAAW,CAAC;KAC3B;IAED,gBAAgB,GAAA;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC;KAC7B;AAED,IAAA,gBAAgB,CAAC,OAAoB,EAAA;AACjC,QAAA,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;KAChC;AAED;;;;AAIG;AACH,IAAA,MAAM,UAAU,GAAA;AACZ;;;AAGG;QAEH,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,qBAAqB,EAAE;AAC9C,YAAA,OAAO,KAAK,CAAC;AAChB,SAAA;QAED,IAAI;AACA,YAAA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AAC/B,gBAAA,MAAM,WAAW,GAAiB,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;AAC7D;;;;AAIG;gBACH,IAAI;AACA,oBAAA,IAAI,WAAW,CAAC,mBAAmB,EAAE,EAAE,YAAY,EAAE;AACjD,wBAAA,IAAI,CAAC,aAAa;AACd,4BAAA,MAAM,WAAW,CAAC,gBAAgB,EAAE,CAAC;AAC5C,qBAAA;AACJ,iBAAA;gBAAC,MAAM;;AAEP,iBAAA;AACD,gBAAA,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;AAC/B,gBAAA,IAAI,CAAC,SAAS,GAAG,WAAW,KAAK,SAAS,CAAC;AAC9C,aAAA;AACJ,SAAA;AAAC,QAAA,OAAO,EAAE,EAAE;YACT,IAAI,CAAC,MAAM,CAAC,OAAO,CACf,CAAgD,6CAAA,EAAA,EAAE,CAAG,CAAA,CAAA,CACxD,CAAC;AACL,SAAA;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAqC,kCAAA,EAAA,IAAI,CAAC,SAAS,CAAE,CAAA,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC,SAAS,CAAC;KACzB;;AAjFD;;;AAGG;AACa,wBAAW,CAAA,WAAA,GAAW,EAAE,CAAC;AAEzC;;AAEG;AACa,wBAAE,CAAA,EAAA,GAAW,0BAA0B;;;;"}
|