@azure/msal-browser 3.0.2 → 3.2.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.d.ts +2 -0
- package/dist/app/IPublicClientApplication.d.ts.map +1 -1
- package/dist/app/IPublicClientApplication.mjs +22 -18
- package/dist/app/IPublicClientApplication.mjs.map +1 -1
- package/dist/app/PublicClientApplication.d.ts +20 -6
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.mjs +24 -7
- package/dist/app/PublicClientApplication.mjs.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts +3 -4
- package/dist/broker/nativeBroker/NativeMessageHandler.d.ts.map +1 -1
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs +17 -16
- package/dist/broker/nativeBroker/NativeMessageHandler.mjs.map +1 -1
- package/dist/broker/nativeBroker/NativeStatusCodes.d.ts +8 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.d.ts.map +1 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs +16 -0
- package/dist/broker/nativeBroker/NativeStatusCodes.mjs.map +1 -0
- package/dist/cache/AsyncMemoryStorage.mjs +4 -3
- package/dist/cache/AsyncMemoryStorage.mjs.map +1 -1
- package/dist/cache/BrowserCacheManager.d.ts +10 -3
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.mjs +58 -29
- package/dist/cache/BrowserCacheManager.mjs.map +1 -1
- package/dist/cache/BrowserStorage.d.ts.map +1 -1
- package/dist/cache/BrowserStorage.mjs +7 -9
- package/dist/cache/BrowserStorage.mjs.map +1 -1
- package/dist/cache/CryptoKeyStore.mjs +1 -1
- package/dist/cache/CryptoKeyStore.mjs.map +1 -1
- package/dist/cache/DatabaseStorage.d.ts.map +1 -1
- package/dist/cache/DatabaseStorage.mjs +9 -8
- package/dist/cache/DatabaseStorage.mjs.map +1 -1
- package/dist/cache/MemoryStorage.mjs +1 -1
- package/dist/cache/MemoryStorage.mjs.map +1 -1
- package/dist/cache/TokenCache.d.ts.map +1 -1
- package/dist/cache/TokenCache.mjs +30 -30
- package/dist/cache/TokenCache.mjs.map +1 -1
- package/dist/config/Configuration.d.ts +1 -0
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.mjs +12 -16
- package/dist/config/Configuration.mjs.map +1 -1
- package/dist/controllers/ControllerFactory.mjs +1 -1
- package/dist/controllers/ControllerFactory.mjs.map +1 -1
- package/dist/controllers/IController.d.ts +5 -28
- package/dist/controllers/IController.d.ts.map +1 -1
- package/dist/controllers/StandardController.d.ts +17 -31
- package/dist/controllers/StandardController.d.ts.map +1 -1
- package/dist/controllers/StandardController.mjs +78 -83
- package/dist/controllers/StandardController.mjs.map +1 -1
- package/dist/crypto/BrowserCrypto.d.ts +44 -49
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.mjs +78 -77
- package/dist/crypto/BrowserCrypto.mjs.map +1 -1
- package/dist/crypto/CryptoOps.d.ts +1 -10
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.mjs +23 -34
- package/dist/crypto/CryptoOps.mjs.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +6 -22
- package/dist/crypto/PkceGenerator.d.ts.map +1 -1
- package/dist/crypto/PkceGenerator.mjs +48 -49
- package/dist/crypto/PkceGenerator.mjs.map +1 -1
- package/dist/crypto/SignedHttpRequest.mjs +1 -1
- package/dist/crypto/SignedHttpRequest.mjs.map +1 -1
- package/dist/encode/Base64Decode.d.ts +6 -19
- package/dist/encode/Base64Decode.d.ts.map +1 -1
- package/dist/encode/Base64Decode.mjs +31 -68
- package/dist/encode/Base64Decode.mjs.map +1 -1
- package/dist/encode/Base64Encode.d.ts +15 -27
- package/dist/encode/Base64Encode.d.ts.map +1 -1
- package/dist/encode/Base64Encode.mjs +36 -75
- package/dist/encode/Base64Encode.mjs.map +1 -1
- package/dist/error/BrowserAuthError.d.ts +63 -195
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.mjs +159 -381
- package/dist/error/BrowserAuthError.mjs.map +1 -1
- package/dist/error/BrowserAuthErrorCodes.d.ts +46 -0
- package/dist/error/BrowserAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/BrowserAuthErrorCodes.mjs +54 -0
- package/dist/error/BrowserAuthErrorCodes.mjs.map +1 -0
- package/dist/error/BrowserConfigurationAuthError.d.ts +9 -46
- package/dist/error/BrowserConfigurationAuthError.d.ts.map +1 -1
- package/dist/error/BrowserConfigurationAuthError.mjs +20 -73
- package/dist/error/BrowserConfigurationAuthError.mjs.map +1 -1
- package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts +4 -0
- package/dist/error/BrowserConfigurationAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +12 -0
- package/dist/error/BrowserConfigurationAuthErrorCodes.mjs.map +1 -0
- package/dist/error/NativeAuthError.d.ts +17 -45
- package/dist/error/NativeAuthError.d.ts.map +1 -1
- package/dist/error/NativeAuthError.mjs +49 -79
- package/dist/error/NativeAuthError.mjs.map +1 -1
- package/dist/error/NativeAuthErrorCodes.d.ts +3 -0
- package/dist/error/NativeAuthErrorCodes.d.ts.map +1 -0
- package/dist/error/NativeAuthErrorCodes.mjs +11 -0
- package/dist/error/NativeAuthErrorCodes.mjs.map +1 -0
- package/dist/event/EventHandler.d.ts.map +1 -1
- package/dist/event/EventHandler.mjs +3 -2
- package/dist/event/EventHandler.mjs.map +1 -1
- package/dist/event/EventMessage.mjs +1 -1
- package/dist/event/EventMessage.mjs.map +1 -1
- package/dist/event/EventType.mjs +1 -1
- package/dist/event/EventType.mjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +8 -4
- package/dist/index.mjs.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts +2 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.mjs +7 -8
- package/dist/interaction_client/BaseInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.d.ts +4 -10
- package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/NativeInteractionClient.mjs +32 -38
- package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
- package/dist/interaction_client/PopupClient.d.ts.map +1 -1
- package/dist/interaction_client/PopupClient.mjs +16 -15
- package/dist/interaction_client/PopupClient.mjs.map +1 -1
- package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
- package/dist/interaction_client/RedirectClient.mjs +7 -6
- package/dist/interaction_client/RedirectClient.mjs.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.mjs +9 -11
- package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentCacheClient.d.ts +4 -2
- package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentCacheClient.mjs +19 -25
- package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentIframeClient.mjs +20 -47
- package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.mjs +11 -20
- package/dist/interaction_client/SilentRefreshClient.mjs.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.mjs +18 -38
- package/dist/interaction_client/StandardInteractionClient.mjs.map +1 -1
- package/dist/interaction_handler/InteractionHandler.d.ts.map +1 -1
- package/dist/interaction_handler/InteractionHandler.mjs +13 -16
- package/dist/interaction_handler/InteractionHandler.mjs.map +1 -1
- package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
- package/dist/interaction_handler/RedirectHandler.mjs +12 -11
- package/dist/interaction_handler/RedirectHandler.mjs.map +1 -1
- package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
- package/dist/interaction_handler/SilentHandler.mjs +11 -11
- package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
- package/dist/navigation/NavigationClient.mjs +1 -1
- package/dist/navigation/NavigationClient.mjs.map +1 -1
- package/dist/network/FetchClient.d.ts.map +1 -1
- package/dist/network/FetchClient.mjs +9 -8
- package/dist/network/FetchClient.mjs.map +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
- package/dist/operatingcontext/BaseOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
- package/dist/operatingcontext/StandardOperatingContext.mjs.map +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs +1 -1
- package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/packageMetadata.mjs.map +1 -1
- package/dist/request/ClearCacheRequest.d.ts +11 -0
- package/dist/request/ClearCacheRequest.d.ts.map +1 -0
- package/dist/telemetry/BrowserPerformanceClient.d.ts +2 -4
- package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/BrowserPerformanceClient.mjs +2 -6
- package/dist/telemetry/BrowserPerformanceClient.mjs.map +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
- package/dist/telemetry/BrowserPerformanceMeasurement.mjs.map +1 -1
- package/dist/utils/BrowserConstants.mjs +1 -1
- package/dist/utils/BrowserConstants.mjs.map +1 -1
- package/dist/utils/BrowserProtocolUtils.d.ts.map +1 -1
- package/dist/utils/BrowserProtocolUtils.mjs +4 -4
- package/dist/utils/BrowserProtocolUtils.mjs.map +1 -1
- package/dist/utils/BrowserStringUtils.mjs +1 -1
- package/dist/utils/BrowserStringUtils.mjs.map +1 -1
- package/dist/utils/BrowserUtils.d.ts +0 -9
- package/dist/utils/BrowserUtils.d.ts.map +1 -1
- package/dist/utils/BrowserUtils.mjs +8 -33
- package/dist/utils/BrowserUtils.mjs.map +1 -1
- package/lib/msal-browser.cjs +8729 -9566
- package/lib/msal-browser.cjs.map +1 -1
- package/lib/msal-browser.js +8729 -9566
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +68 -62
- package/package.json +7 -5
- package/src/app/IPublicClientApplication.ts +236 -0
- package/src/app/PublicClientApplication.ts +417 -0
- package/src/broker/nativeBroker/NativeMessageHandler.ts +416 -0
- package/src/broker/nativeBroker/NativeRequest.ts +52 -0
- package/src/broker/nativeBroker/NativeResponse.ts +56 -0
- package/src/broker/nativeBroker/NativeStatusCodes.ts +13 -0
- package/src/cache/AsyncMemoryStorage.ts +158 -0
- package/src/cache/BrowserCacheManager.ts +2009 -0
- package/src/cache/BrowserStorage.ts +52 -0
- package/src/cache/CryptoKeyStore.ts +63 -0
- package/src/cache/DatabaseStorage.ts +287 -0
- package/src/cache/IAsyncMemoryStorage.ts +36 -0
- package/src/cache/ITokenCache.ts +21 -0
- package/src/cache/IWindowStorage.ts +36 -0
- package/src/cache/MemoryStorage.ts +42 -0
- package/src/cache/TokenCache.ts +484 -0
- package/src/config/Configuration.ts +383 -0
- package/src/controllers/ControllerFactory.ts +55 -0
- package/src/controllers/IController.ts +134 -0
- package/src/controllers/StandardController.ts +2170 -0
- package/src/crypto/BrowserCrypto.ts +151 -0
- package/src/crypto/CryptoOps.ts +235 -0
- package/src/crypto/PkceGenerator.ts +115 -0
- package/src/crypto/SignedHttpRequest.ts +76 -0
- package/src/encode/Base64Decode.ts +46 -0
- package/src/encode/Base64Encode.ts +52 -0
- package/src/error/BrowserAuthError.ts +352 -0
- package/src/error/BrowserAuthErrorCodes.ts +57 -0
- package/src/error/BrowserConfigurationAuthError.ts +64 -0
- package/src/error/BrowserConfigurationAuthErrorCodes.ts +9 -0
- package/src/error/NativeAuthError.ts +113 -0
- package/src/error/NativeAuthErrorCodes.ts +7 -0
- package/src/event/EventHandler.ts +177 -0
- package/src/event/EventMessage.ts +125 -0
- package/src/event/EventType.ts +33 -0
- package/src/index.ts +157 -0
- package/src/interaction_client/BaseInteractionClient.ts +307 -0
- package/src/interaction_client/HybridSpaAuthorizationCodeClient.ts +16 -0
- package/src/interaction_client/NativeInteractionClient.ts +925 -0
- package/src/interaction_client/PopupClient.ts +926 -0
- package/src/interaction_client/RedirectClient.ts +616 -0
- package/src/interaction_client/SilentAuthCodeClient.ts +165 -0
- package/src/interaction_client/SilentCacheClient.ts +125 -0
- package/src/interaction_client/SilentIframeClient.ts +301 -0
- package/src/interaction_client/SilentRefreshClient.ts +118 -0
- package/src/interaction_client/StandardInteractionClient.ts +450 -0
- package/src/interaction_handler/InteractionHandler.ts +251 -0
- package/src/interaction_handler/RedirectHandler.ts +229 -0
- package/src/interaction_handler/SilentHandler.ts +269 -0
- package/src/navigation/INavigationClient.ts +23 -0
- package/src/navigation/NavigationClient.ts +55 -0
- package/src/navigation/NavigationOptions.ts +18 -0
- package/src/network/FetchClient.ts +130 -0
- package/src/operatingcontext/BaseOperatingContext.ts +82 -0
- package/src/operatingcontext/StandardOperatingContext.ts +49 -0
- package/src/operatingcontext/TeamsAppOperatingContext.ts +48 -0
- package/src/packageMetadata.ts +3 -0
- package/src/request/AuthorizationCodeRequest.ts +19 -0
- package/src/request/AuthorizationUrlRequest.ts +17 -0
- package/src/request/ClearCacheRequest.ts +16 -0
- package/src/request/EndSessionPopupRequest.ts +26 -0
- package/src/request/EndSessionRequest.ts +23 -0
- package/src/request/PopupRequest.ts +51 -0
- package/src/request/PopupWindowAttributes.ts +22 -0
- package/src/request/RedirectRequest.ts +51 -0
- package/src/request/SilentRequest.ts +49 -0
- package/src/request/SsoSilentRequest.ts +44 -0
- package/src/response/AuthenticationResult.ts +13 -0
- package/src/telemetry/BrowserPerformanceClient.ts +226 -0
- package/src/telemetry/BrowserPerformanceMeasurement.ts +144 -0
- package/src/utils/BrowserConstants.ts +241 -0
- package/src/utils/BrowserProtocolUtils.ts +58 -0
- package/src/utils/BrowserStringUtils.ts +143 -0
- package/src/utils/BrowserUtils.ts +156 -0
- package/dist/crypto/GuidGenerator.d.ts +0 -13
- package/dist/crypto/GuidGenerator.d.ts.map +0 -1
- package/dist/crypto/GuidGenerator.mjs +0 -104
- package/dist/crypto/GuidGenerator.mjs.map +0 -1
- package/dist/crypto/ISubtleCrypto.d.ts +0 -10
- package/dist/crypto/ISubtleCrypto.d.ts.map +0 -1
- package/dist/crypto/ModernBrowserCrypto.d.ts +0 -10
- package/dist/crypto/ModernBrowserCrypto.d.ts.map +0 -1
- package/dist/crypto/ModernBrowserCrypto.mjs +0 -31
- package/dist/crypto/ModernBrowserCrypto.mjs.map +0 -1
- package/dist/internals.d.ts +0 -23
- package/dist/internals.d.ts.map +0 -1
- package/dist/internals.mjs +0 -28
- package/dist/internals.mjs.map +0 -1
- package/dist/network/XhrClient.d.ts +0 -41
- package/dist/network/XhrClient.d.ts.map +0 -1
- package/dist/network/XhrClient.mjs +0 -125
- package/dist/network/XhrClient.mjs.map +0 -1
- package/dist/utils/MathUtils.d.ts +0 -12
- package/dist/utils/MathUtils.d.ts.map +0 -1
- package/dist/utils/MathUtils.mjs +0 -26
- package/dist/utils/MathUtils.mjs.map +0 -1
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
AccessTokenEntity,
|
|
8
|
+
ICrypto,
|
|
9
|
+
IdTokenEntity,
|
|
10
|
+
Logger,
|
|
11
|
+
ScopeSet,
|
|
12
|
+
Authority,
|
|
13
|
+
AuthorityOptions,
|
|
14
|
+
ExternalTokenResponse,
|
|
15
|
+
AccountEntity,
|
|
16
|
+
AuthToken,
|
|
17
|
+
RefreshTokenEntity,
|
|
18
|
+
Constants,
|
|
19
|
+
CacheRecord,
|
|
20
|
+
TokenClaims,
|
|
21
|
+
} from "@azure/msal-common";
|
|
22
|
+
import { BrowserConfiguration } from "../config/Configuration";
|
|
23
|
+
import { SilentRequest } from "../request/SilentRequest";
|
|
24
|
+
import { BrowserCacheManager } from "./BrowserCacheManager";
|
|
25
|
+
import { ITokenCache } from "./ITokenCache";
|
|
26
|
+
import {
|
|
27
|
+
createBrowserAuthError,
|
|
28
|
+
BrowserAuthErrorCodes,
|
|
29
|
+
} from "../error/BrowserAuthError";
|
|
30
|
+
import { AuthenticationResult } from "../response/AuthenticationResult";
|
|
31
|
+
import { base64Decode } from "../encode/Base64Decode";
|
|
32
|
+
|
|
33
|
+
export type LoadTokenOptions = {
|
|
34
|
+
clientInfo?: string;
|
|
35
|
+
expiresOn?: number;
|
|
36
|
+
extendedExpiresOn?: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Token cache manager
|
|
41
|
+
*/
|
|
42
|
+
export class TokenCache implements ITokenCache {
|
|
43
|
+
// Flag to indicate if in browser environment
|
|
44
|
+
public isBrowserEnvironment: boolean;
|
|
45
|
+
// Input configuration by developer/user
|
|
46
|
+
protected config: BrowserConfiguration;
|
|
47
|
+
// Browser cache storage
|
|
48
|
+
private storage: BrowserCacheManager;
|
|
49
|
+
// Logger
|
|
50
|
+
private logger: Logger;
|
|
51
|
+
// Crypto class
|
|
52
|
+
private cryptoObj: ICrypto;
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
configuration: BrowserConfiguration,
|
|
56
|
+
storage: BrowserCacheManager,
|
|
57
|
+
logger: Logger,
|
|
58
|
+
cryptoObj: ICrypto
|
|
59
|
+
) {
|
|
60
|
+
this.isBrowserEnvironment = typeof window !== "undefined";
|
|
61
|
+
this.config = configuration;
|
|
62
|
+
this.storage = storage;
|
|
63
|
+
this.logger = logger;
|
|
64
|
+
this.cryptoObj = cryptoObj;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Move getAllAccounts here and cache utility APIs
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* API to load tokens to msal-browser cache.
|
|
71
|
+
* @param request
|
|
72
|
+
* @param response
|
|
73
|
+
* @param options
|
|
74
|
+
* @returns `AuthenticationResult` for the response that was loaded.
|
|
75
|
+
*/
|
|
76
|
+
loadExternalTokens(
|
|
77
|
+
request: SilentRequest,
|
|
78
|
+
response: ExternalTokenResponse,
|
|
79
|
+
options: LoadTokenOptions
|
|
80
|
+
): AuthenticationResult {
|
|
81
|
+
this.logger.info("TokenCache - loadExternalTokens called");
|
|
82
|
+
|
|
83
|
+
if (!response.id_token) {
|
|
84
|
+
throw createBrowserAuthError(
|
|
85
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const idTokenClaims = AuthToken.extractTokenClaims(
|
|
90
|
+
response.id_token,
|
|
91
|
+
base64Decode
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
let cacheRecord: CacheRecord;
|
|
95
|
+
let authority: Authority | undefined;
|
|
96
|
+
let cacheRecordAccount: AccountEntity;
|
|
97
|
+
|
|
98
|
+
if (request.account) {
|
|
99
|
+
cacheRecordAccount = AccountEntity.createFromAccountInfo(
|
|
100
|
+
request.account
|
|
101
|
+
);
|
|
102
|
+
cacheRecord = new CacheRecord(
|
|
103
|
+
cacheRecordAccount,
|
|
104
|
+
this.loadIdToken(
|
|
105
|
+
response.id_token,
|
|
106
|
+
cacheRecordAccount.homeAccountId,
|
|
107
|
+
request.account.environment,
|
|
108
|
+
request.account.tenantId
|
|
109
|
+
),
|
|
110
|
+
this.loadAccessToken(
|
|
111
|
+
request,
|
|
112
|
+
response,
|
|
113
|
+
cacheRecordAccount.homeAccountId,
|
|
114
|
+
request.account.environment,
|
|
115
|
+
request.account.tenantId,
|
|
116
|
+
options
|
|
117
|
+
),
|
|
118
|
+
this.loadRefreshToken(
|
|
119
|
+
request,
|
|
120
|
+
response,
|
|
121
|
+
cacheRecordAccount.homeAccountId,
|
|
122
|
+
request.account.environment
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
} else if (request.authority) {
|
|
126
|
+
const authorityUrl = Authority.generateAuthority(
|
|
127
|
+
request.authority,
|
|
128
|
+
request.azureCloudOptions
|
|
129
|
+
);
|
|
130
|
+
const authorityOptions: AuthorityOptions = {
|
|
131
|
+
protocolMode: this.config.auth.protocolMode,
|
|
132
|
+
knownAuthorities: this.config.auth.knownAuthorities,
|
|
133
|
+
cloudDiscoveryMetadata: this.config.auth.cloudDiscoveryMetadata,
|
|
134
|
+
authorityMetadata: this.config.auth.authorityMetadata,
|
|
135
|
+
skipAuthorityMetadataCache:
|
|
136
|
+
this.config.auth.skipAuthorityMetadataCache,
|
|
137
|
+
};
|
|
138
|
+
authority = new Authority(
|
|
139
|
+
authorityUrl,
|
|
140
|
+
this.config.system.networkClient,
|
|
141
|
+
this.storage,
|
|
142
|
+
authorityOptions,
|
|
143
|
+
this.logger
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// "clientInfo" from options takes precedence over "clientInfo" in response
|
|
147
|
+
if (options.clientInfo) {
|
|
148
|
+
this.logger.trace("TokenCache - homeAccountId from options");
|
|
149
|
+
cacheRecordAccount = this.loadAccount(
|
|
150
|
+
idTokenClaims,
|
|
151
|
+
authority,
|
|
152
|
+
options.clientInfo
|
|
153
|
+
);
|
|
154
|
+
cacheRecord = new CacheRecord(
|
|
155
|
+
cacheRecordAccount,
|
|
156
|
+
this.loadIdToken(
|
|
157
|
+
response.id_token,
|
|
158
|
+
cacheRecordAccount.homeAccountId,
|
|
159
|
+
authority.hostnameAndPort,
|
|
160
|
+
authority.tenant
|
|
161
|
+
),
|
|
162
|
+
this.loadAccessToken(
|
|
163
|
+
request,
|
|
164
|
+
response,
|
|
165
|
+
cacheRecordAccount.homeAccountId,
|
|
166
|
+
authority.hostnameAndPort,
|
|
167
|
+
authority.tenant,
|
|
168
|
+
options
|
|
169
|
+
),
|
|
170
|
+
this.loadRefreshToken(
|
|
171
|
+
request,
|
|
172
|
+
response,
|
|
173
|
+
cacheRecordAccount.homeAccountId,
|
|
174
|
+
authority.hostnameAndPort
|
|
175
|
+
)
|
|
176
|
+
);
|
|
177
|
+
} else if (response.client_info) {
|
|
178
|
+
this.logger.trace("TokenCache - homeAccountId from response");
|
|
179
|
+
cacheRecordAccount = this.loadAccount(
|
|
180
|
+
idTokenClaims,
|
|
181
|
+
authority,
|
|
182
|
+
response.client_info
|
|
183
|
+
);
|
|
184
|
+
cacheRecord = new CacheRecord(
|
|
185
|
+
cacheRecordAccount,
|
|
186
|
+
this.loadIdToken(
|
|
187
|
+
response.id_token,
|
|
188
|
+
cacheRecordAccount.homeAccountId,
|
|
189
|
+
authority.hostnameAndPort,
|
|
190
|
+
authority.tenant
|
|
191
|
+
),
|
|
192
|
+
this.loadAccessToken(
|
|
193
|
+
request,
|
|
194
|
+
response,
|
|
195
|
+
cacheRecordAccount.homeAccountId,
|
|
196
|
+
authority.hostnameAndPort,
|
|
197
|
+
authority.tenant,
|
|
198
|
+
options
|
|
199
|
+
),
|
|
200
|
+
this.loadRefreshToken(
|
|
201
|
+
request,
|
|
202
|
+
response,
|
|
203
|
+
cacheRecordAccount.homeAccountId,
|
|
204
|
+
authority.hostnameAndPort
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
} else {
|
|
208
|
+
throw createBrowserAuthError(
|
|
209
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
throw createBrowserAuthError(
|
|
214
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return this.generateAuthenticationResult(
|
|
219
|
+
request,
|
|
220
|
+
idTokenClaims,
|
|
221
|
+
cacheRecord,
|
|
222
|
+
cacheRecordAccount,
|
|
223
|
+
authority
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Helper function to load account to msal-browser cache
|
|
229
|
+
* @param idToken
|
|
230
|
+
* @param environment
|
|
231
|
+
* @param clientInfo
|
|
232
|
+
* @param authorityType
|
|
233
|
+
* @param requestHomeAccountId
|
|
234
|
+
* @returns `AccountEntity`
|
|
235
|
+
*/
|
|
236
|
+
private loadAccount(
|
|
237
|
+
idTokenClaims: TokenClaims,
|
|
238
|
+
authority: Authority,
|
|
239
|
+
clientInfo?: string,
|
|
240
|
+
requestHomeAccountId?: string
|
|
241
|
+
): AccountEntity {
|
|
242
|
+
let homeAccountId;
|
|
243
|
+
if (requestHomeAccountId) {
|
|
244
|
+
homeAccountId = requestHomeAccountId;
|
|
245
|
+
} else if (authority.authorityType !== undefined && clientInfo) {
|
|
246
|
+
homeAccountId = AccountEntity.generateHomeAccountId(
|
|
247
|
+
clientInfo,
|
|
248
|
+
authority.authorityType,
|
|
249
|
+
this.logger,
|
|
250
|
+
this.cryptoObj,
|
|
251
|
+
idTokenClaims
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (!homeAccountId) {
|
|
256
|
+
throw createBrowserAuthError(
|
|
257
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const accountEntity = AccountEntity.createAccount(
|
|
262
|
+
{
|
|
263
|
+
homeAccountId,
|
|
264
|
+
idTokenClaims: idTokenClaims,
|
|
265
|
+
clientInfo,
|
|
266
|
+
environment: authority.hostnameAndPort,
|
|
267
|
+
},
|
|
268
|
+
authority
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
if (this.isBrowserEnvironment) {
|
|
272
|
+
this.logger.verbose("TokenCache - loading account");
|
|
273
|
+
|
|
274
|
+
this.storage.setAccount(accountEntity);
|
|
275
|
+
return accountEntity;
|
|
276
|
+
} else {
|
|
277
|
+
throw createBrowserAuthError(
|
|
278
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Helper function to load id tokens to msal-browser cache
|
|
285
|
+
* @param idToken
|
|
286
|
+
* @param homeAccountId
|
|
287
|
+
* @param environment
|
|
288
|
+
* @param tenantId
|
|
289
|
+
* @returns `IdTokenEntity`
|
|
290
|
+
*/
|
|
291
|
+
private loadIdToken(
|
|
292
|
+
idToken: string,
|
|
293
|
+
homeAccountId: string,
|
|
294
|
+
environment: string,
|
|
295
|
+
tenantId: string
|
|
296
|
+
): IdTokenEntity {
|
|
297
|
+
const idTokenEntity = IdTokenEntity.createIdTokenEntity(
|
|
298
|
+
homeAccountId,
|
|
299
|
+
environment,
|
|
300
|
+
idToken,
|
|
301
|
+
this.config.auth.clientId,
|
|
302
|
+
tenantId
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
if (this.isBrowserEnvironment) {
|
|
306
|
+
this.logger.verbose("TokenCache - loading id token");
|
|
307
|
+
this.storage.setIdTokenCredential(idTokenEntity);
|
|
308
|
+
return idTokenEntity;
|
|
309
|
+
} else {
|
|
310
|
+
throw createBrowserAuthError(
|
|
311
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Helper function to load access tokens to msal-browser cache
|
|
318
|
+
* @param request
|
|
319
|
+
* @param response
|
|
320
|
+
* @param homeAccountId
|
|
321
|
+
* @param environment
|
|
322
|
+
* @param tenantId
|
|
323
|
+
* @returns `AccessTokenEntity`
|
|
324
|
+
*/
|
|
325
|
+
private loadAccessToken(
|
|
326
|
+
request: SilentRequest,
|
|
327
|
+
response: ExternalTokenResponse,
|
|
328
|
+
homeAccountId: string,
|
|
329
|
+
environment: string,
|
|
330
|
+
tenantId: string,
|
|
331
|
+
options: LoadTokenOptions
|
|
332
|
+
): AccessTokenEntity | null {
|
|
333
|
+
if (!response.access_token) {
|
|
334
|
+
this.logger.verbose(
|
|
335
|
+
"TokenCache - No access token provided for caching"
|
|
336
|
+
);
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (!response.expires_in) {
|
|
341
|
+
throw createBrowserAuthError(
|
|
342
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (!options.extendedExpiresOn) {
|
|
347
|
+
throw createBrowserAuthError(
|
|
348
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const scopes = new ScopeSet(request.scopes).printScopes();
|
|
353
|
+
const expiresOn =
|
|
354
|
+
options.expiresOn ||
|
|
355
|
+
response.expires_in + new Date().getTime() / 1000;
|
|
356
|
+
const extendedExpiresOn = options.extendedExpiresOn;
|
|
357
|
+
|
|
358
|
+
const accessTokenEntity = AccessTokenEntity.createAccessTokenEntity(
|
|
359
|
+
homeAccountId,
|
|
360
|
+
environment,
|
|
361
|
+
response.access_token,
|
|
362
|
+
this.config.auth.clientId,
|
|
363
|
+
tenantId,
|
|
364
|
+
scopes,
|
|
365
|
+
expiresOn,
|
|
366
|
+
extendedExpiresOn,
|
|
367
|
+
this.cryptoObj
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
if (this.isBrowserEnvironment) {
|
|
371
|
+
this.logger.verbose("TokenCache - loading access token");
|
|
372
|
+
this.storage.setAccessTokenCredential(accessTokenEntity);
|
|
373
|
+
return accessTokenEntity;
|
|
374
|
+
} else {
|
|
375
|
+
throw createBrowserAuthError(
|
|
376
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Helper function to load refresh tokens to msal-browser cache
|
|
383
|
+
* @param request
|
|
384
|
+
* @param response
|
|
385
|
+
* @param homeAccountId
|
|
386
|
+
* @param environment
|
|
387
|
+
* @returns `RefreshTokenEntity`
|
|
388
|
+
*/
|
|
389
|
+
private loadRefreshToken(
|
|
390
|
+
request: SilentRequest,
|
|
391
|
+
response: ExternalTokenResponse,
|
|
392
|
+
homeAccountId: string,
|
|
393
|
+
environment: string
|
|
394
|
+
): RefreshTokenEntity | null {
|
|
395
|
+
if (!response.refresh_token) {
|
|
396
|
+
this.logger.verbose(
|
|
397
|
+
"TokenCache - No refresh token provided for caching"
|
|
398
|
+
);
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const refreshTokenEntity = RefreshTokenEntity.createRefreshTokenEntity(
|
|
403
|
+
homeAccountId,
|
|
404
|
+
environment,
|
|
405
|
+
response.refresh_token,
|
|
406
|
+
this.config.auth.clientId
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
if (this.isBrowserEnvironment) {
|
|
410
|
+
this.logger.verbose("TokenCache - loading refresh token");
|
|
411
|
+
this.storage.setRefreshTokenCredential(refreshTokenEntity);
|
|
412
|
+
return refreshTokenEntity;
|
|
413
|
+
} else {
|
|
414
|
+
throw createBrowserAuthError(
|
|
415
|
+
BrowserAuthErrorCodes.unableToLoadToken
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Helper function to generate an `AuthenticationResult` for the result.
|
|
422
|
+
* @param request
|
|
423
|
+
* @param idTokenObj
|
|
424
|
+
* @param cacheRecord
|
|
425
|
+
* @param authority
|
|
426
|
+
* @returns `AuthenticationResult`
|
|
427
|
+
*/
|
|
428
|
+
private generateAuthenticationResult(
|
|
429
|
+
request: SilentRequest,
|
|
430
|
+
idTokenClaims: TokenClaims,
|
|
431
|
+
cacheRecord: CacheRecord,
|
|
432
|
+
accountEntity: AccountEntity,
|
|
433
|
+
authority?: Authority
|
|
434
|
+
): AuthenticationResult {
|
|
435
|
+
let accessToken: string = Constants.EMPTY_STRING;
|
|
436
|
+
let responseScopes: Array<string> = [];
|
|
437
|
+
let expiresOn: Date | null = null;
|
|
438
|
+
let extExpiresOn: Date | undefined;
|
|
439
|
+
|
|
440
|
+
if (cacheRecord?.accessToken) {
|
|
441
|
+
accessToken = cacheRecord.accessToken.secret;
|
|
442
|
+
responseScopes = ScopeSet.fromString(
|
|
443
|
+
cacheRecord.accessToken.target
|
|
444
|
+
).asArray();
|
|
445
|
+
expiresOn = new Date(
|
|
446
|
+
Number(cacheRecord.accessToken.expiresOn) * 1000
|
|
447
|
+
);
|
|
448
|
+
extExpiresOn = new Date(
|
|
449
|
+
Number(cacheRecord.accessToken.extendedExpiresOn) * 1000
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const uid =
|
|
454
|
+
idTokenClaims.oid || idTokenClaims.sub || Constants.EMPTY_STRING;
|
|
455
|
+
const tid = idTokenClaims.tid || Constants.EMPTY_STRING;
|
|
456
|
+
|
|
457
|
+
return {
|
|
458
|
+
authority: authority
|
|
459
|
+
? authority.canonicalAuthority
|
|
460
|
+
: Constants.EMPTY_STRING,
|
|
461
|
+
uniqueId: uid,
|
|
462
|
+
tenantId: tid,
|
|
463
|
+
scopes: responseScopes,
|
|
464
|
+
account: accountEntity.getAccountInfo(),
|
|
465
|
+
idToken: cacheRecord.idToken?.secret || "",
|
|
466
|
+
idTokenClaims: idTokenClaims || {},
|
|
467
|
+
accessToken: accessToken,
|
|
468
|
+
fromCache: true,
|
|
469
|
+
expiresOn: expiresOn,
|
|
470
|
+
correlationId: request.correlationId || Constants.EMPTY_STRING,
|
|
471
|
+
requestId: Constants.EMPTY_STRING,
|
|
472
|
+
extExpiresOn: extExpiresOn,
|
|
473
|
+
familyId: Constants.EMPTY_STRING,
|
|
474
|
+
tokenType:
|
|
475
|
+
cacheRecord?.accessToken?.tokenType || Constants.EMPTY_STRING,
|
|
476
|
+
state: Constants.EMPTY_STRING,
|
|
477
|
+
cloudGraphHostName:
|
|
478
|
+
accountEntity.cloudGraphHostName || Constants.EMPTY_STRING,
|
|
479
|
+
msGraphHost: accountEntity.msGraphHost || Constants.EMPTY_STRING,
|
|
480
|
+
code: undefined,
|
|
481
|
+
fromNativeBroker: false,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
}
|