@azure/msal-browser 2.16.0 → 2.19.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/CHANGELOG.json +240 -0
- package/{changelog.md → CHANGELOG.md} +489 -430
- package/LICENSE +21 -21
- package/README.md +212 -206
- package/dist/_virtual/_tslib.js +1 -1
- package/dist/app/ClientApplication.d.ts +19 -140
- package/dist/app/ClientApplication.d.ts.map +1 -1
- package/dist/app/ClientApplication.js +115 -895
- package/dist/app/ClientApplication.js.map +1 -1
- package/dist/app/IPublicClientApplication.d.ts +6 -0
- package/dist/app/IPublicClientApplication.d.ts.map +1 -1
- package/dist/app/IPublicClientApplication.js +13 -1
- package/dist/app/IPublicClientApplication.js.map +1 -1
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.js +35 -41
- package/dist/app/PublicClientApplication.js.map +1 -1
- package/dist/cache/AsyncMemoryStorage.d.ts +46 -0
- package/dist/cache/AsyncMemoryStorage.d.ts.map +1 -0
- package/dist/cache/AsyncMemoryStorage.js +195 -0
- package/dist/cache/AsyncMemoryStorage.js.map +1 -0
- package/dist/cache/BrowserCacheManager.d.ts +19 -2
- package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
- package/dist/cache/BrowserCacheManager.js +104 -15
- package/dist/cache/BrowserCacheManager.js.map +1 -1
- package/dist/cache/BrowserStorage.d.ts +1 -1
- package/dist/cache/BrowserStorage.d.ts.map +1 -1
- package/dist/cache/BrowserStorage.js +1 -1
- package/dist/cache/BrowserStorage.js.map +1 -1
- package/dist/cache/DatabaseStorage.d.ts +29 -4
- package/dist/cache/DatabaseStorage.d.ts.map +1 -1
- package/dist/cache/DatabaseStorage.js +151 -45
- package/dist/cache/DatabaseStorage.js.map +1 -1
- package/dist/cache/IAsyncMemoryStorage.d.ts +28 -0
- package/dist/cache/IAsyncMemoryStorage.d.ts.map +1 -0
- package/dist/cache/ITokenCache.d.ts +8 -0
- package/dist/cache/ITokenCache.d.ts.map +1 -0
- package/dist/cache/IWindowStorage.d.ts +3 -3
- package/dist/cache/IWindowStorage.d.ts.map +1 -1
- package/dist/cache/MemoryStorage.d.ts +3 -3
- package/dist/cache/MemoryStorage.d.ts.map +1 -1
- package/dist/cache/MemoryStorage.js +1 -1
- package/dist/cache/MemoryStorage.js.map +1 -1
- package/dist/cache/TokenCache.d.ts +48 -0
- package/dist/cache/TokenCache.d.ts.map +1 -0
- package/dist/cache/TokenCache.js +124 -0
- package/dist/cache/TokenCache.js.map +1 -0
- package/dist/config/Configuration.js +1 -1
- package/dist/config/Configuration.js.map +1 -1
- package/dist/crypto/BrowserCrypto.d.ts +3 -1
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.js +3 -2
- package/dist/crypto/BrowserCrypto.js.map +1 -1
- package/dist/crypto/CryptoOps.d.ts +21 -6
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.js +67 -15
- package/dist/crypto/CryptoOps.js.map +1 -1
- package/dist/crypto/GuidGenerator.js +1 -1
- package/dist/crypto/GuidGenerator.js.map +1 -1
- package/dist/crypto/PkceGenerator.js +1 -1
- package/dist/crypto/PkceGenerator.js.map +1 -1
- package/dist/crypto/SignedHttpRequest.d.ts +31 -0
- package/dist/crypto/SignedHttpRequest.d.ts.map +1 -0
- package/dist/crypto/SignedHttpRequest.js +70 -0
- package/dist/crypto/SignedHttpRequest.js.map +1 -0
- package/dist/encode/Base64Decode.js +1 -1
- package/dist/encode/Base64Decode.js.map +1 -1
- package/dist/encode/Base64Encode.js +1 -1
- package/dist/encode/Base64Encode.js.map +1 -1
- package/dist/error/BrowserAuthError.d.ts +28 -4
- package/dist/error/BrowserAuthError.d.ts.map +1 -1
- package/dist/error/BrowserAuthError.js +41 -11
- package/dist/error/BrowserAuthError.js.map +1 -1
- package/dist/error/BrowserConfigurationAuthError.js +1 -1
- package/dist/error/BrowserConfigurationAuthError.js.map +1 -1
- package/dist/event/EventHandler.d.ts +13 -0
- package/dist/event/EventHandler.d.ts.map +1 -1
- package/dist/event/EventHandler.js +66 -1
- package/dist/event/EventHandler.js.map +1 -1
- package/dist/event/EventMessage.d.ts +4 -3
- package/dist/event/EventMessage.d.ts.map +1 -1
- package/dist/event/EventMessage.js +24 -5
- package/dist/event/EventMessage.js.map +1 -1
- package/dist/event/EventType.d.ts +2 -0
- package/dist/event/EventType.d.ts.map +1 -1
- package/dist/event/EventType.js +3 -1
- package/dist/event/EventType.js.map +1 -1
- package/dist/index.cjs.js +4505 -3045
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts +42 -0
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -0
- package/dist/interaction_client/BaseInteractionClient.js +131 -0
- package/dist/interaction_client/BaseInteractionClient.js.map +1 -0
- package/dist/interaction_client/PopupClient.d.ts +37 -0
- package/dist/interaction_client/PopupClient.d.ts.map +1 -0
- package/dist/interaction_client/PopupClient.js +234 -0
- package/dist/interaction_client/PopupClient.js.map +1 -0
- package/dist/interaction_client/RedirectClient.d.ts +42 -0
- package/dist/interaction_client/RedirectClient.d.ts.map +1 -0
- package/dist/interaction_client/RedirectClient.js +301 -0
- package/dist/interaction_client/RedirectClient.js.map +1 -0
- package/dist/interaction_client/SilentCacheClient.d.ts +22 -0
- package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -0
- package/dist/interaction_client/SilentCacheClient.js +85 -0
- package/dist/interaction_client/SilentCacheClient.js.map +1 -0
- package/dist/interaction_client/SilentIframeClient.d.ts +29 -0
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -0
- package/dist/interaction_client/SilentIframeClient.js +107 -0
- package/dist/interaction_client/SilentIframeClient.js.map +1 -0
- package/dist/interaction_client/SilentRefreshClient.d.ts +20 -0
- package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -0
- package/dist/interaction_client/SilentRefreshClient.js +76 -0
- package/dist/interaction_client/SilentRefreshClient.js.map +1 -0
- package/dist/interaction_client/StandardInteractionClient.d.ts +66 -0
- package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -0
- package/dist/interaction_client/StandardInteractionClient.js +249 -0
- package/dist/interaction_client/StandardInteractionClient.js.map +1 -0
- package/dist/interaction_handler/InteractionHandler.js +1 -1
- package/dist/interaction_handler/InteractionHandler.js.map +1 -1
- package/dist/interaction_handler/PopupHandler.d.ts +2 -0
- package/dist/interaction_handler/PopupHandler.d.ts.map +1 -1
- package/dist/interaction_handler/PopupHandler.js +3 -4
- package/dist/interaction_handler/PopupHandler.js.map +1 -1
- package/dist/interaction_handler/RedirectHandler.d.ts.map +1 -1
- package/dist/interaction_handler/RedirectHandler.js +6 -5
- package/dist/interaction_handler/RedirectHandler.js.map +1 -1
- package/dist/interaction_handler/SilentHandler.js +1 -1
- package/dist/interaction_handler/SilentHandler.js.map +1 -1
- package/dist/navigation/NavigationClient.js +1 -1
- package/dist/navigation/NavigationClient.js.map +1 -1
- package/dist/network/FetchClient.js +1 -1
- package/dist/network/FetchClient.js.map +1 -1
- package/dist/network/XhrClient.js +1 -1
- package/dist/network/XhrClient.js.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.js +2 -2
- package/dist/packageMetadata.js.map +1 -1
- package/dist/request/EndSessionPopupRequest.d.ts +3 -0
- package/dist/request/EndSessionPopupRequest.d.ts.map +1 -1
- package/dist/request/PopupRequest.d.ts +3 -0
- package/dist/request/PopupRequest.d.ts.map +1 -1
- package/dist/request/RedirectRequest.d.ts.map +1 -1
- package/dist/utils/BrowserConstants.d.ts +12 -1
- package/dist/utils/BrowserConstants.d.ts.map +1 -1
- package/dist/utils/BrowserConstants.js +16 -3
- package/dist/utils/BrowserConstants.js.map +1 -1
- package/dist/utils/BrowserProtocolUtils.js +1 -1
- package/dist/utils/BrowserProtocolUtils.js.map +1 -1
- package/dist/utils/BrowserStringUtils.js +1 -1
- package/dist/utils/BrowserStringUtils.js.map +1 -1
- package/dist/utils/BrowserUtils.js +1 -1
- package/dist/utils/BrowserUtils.js.map +1 -1
- package/dist/utils/MathUtils.js +1 -1
- package/dist/utils/MathUtils.js.map +1 -1
- package/dist/utils/PopupUtils.d.ts +26 -2
- package/dist/utils/PopupUtils.d.ts.map +1 -1
- package/dist/utils/PopupUtils.js +42 -15
- package/dist/utils/PopupUtils.js.map +1 -1
- package/lib/msal-browser.js +4505 -3045
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +42 -42
- package/package.json +8 -2
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/*! @azure/msal-browser v2.19.0 2021-11-02 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { __extends, __awaiter, __generator } from '../_virtual/_tslib.js';
|
|
4
|
+
import { AuthError, UrlString } from '@azure/msal-common';
|
|
5
|
+
import { StandardInteractionClient } from './StandardInteractionClient.js';
|
|
6
|
+
import { InteractionType, ApiId, TemporaryCacheKeys } from '../utils/BrowserConstants.js';
|
|
7
|
+
import { RedirectHandler } from '../interaction_handler/RedirectHandler.js';
|
|
8
|
+
import { BrowserUtils } from '../utils/BrowserUtils.js';
|
|
9
|
+
import { EventType } from '../event/EventType.js';
|
|
10
|
+
import { BrowserAuthError } from '../error/BrowserAuthError.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
14
|
+
* Licensed under the MIT License.
|
|
15
|
+
*/
|
|
16
|
+
var RedirectClient = /** @class */ (function (_super) {
|
|
17
|
+
__extends(RedirectClient, _super);
|
|
18
|
+
function RedirectClient() {
|
|
19
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Redirects the page to the /authorize endpoint of the IDP
|
|
23
|
+
* @param request
|
|
24
|
+
*/
|
|
25
|
+
RedirectClient.prototype.acquireToken = function (request) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
27
|
+
var validRequest, serverTelemetryManager, authCodeRequest, authClient, interactionHandler, navigateUrl, redirectStartPage, e_1;
|
|
28
|
+
return __generator(this, function (_a) {
|
|
29
|
+
switch (_a.label) {
|
|
30
|
+
case 0:
|
|
31
|
+
validRequest = this.preflightInteractiveRequest(request, InteractionType.Redirect);
|
|
32
|
+
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenRedirect);
|
|
33
|
+
_a.label = 1;
|
|
34
|
+
case 1:
|
|
35
|
+
_a.trys.push([1, 6, , 7]);
|
|
36
|
+
return [4 /*yield*/, this.initializeAuthorizationCodeRequest(validRequest)];
|
|
37
|
+
case 2:
|
|
38
|
+
authCodeRequest = _a.sent();
|
|
39
|
+
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, validRequest.authority)];
|
|
40
|
+
case 3:
|
|
41
|
+
authClient = _a.sent();
|
|
42
|
+
this.logger.verbose("Auth code client created");
|
|
43
|
+
interactionHandler = new RedirectHandler(authClient, this.browserStorage, authCodeRequest, this.logger, this.browserCrypto);
|
|
44
|
+
return [4 /*yield*/, authClient.getAuthCodeUrl(validRequest)];
|
|
45
|
+
case 4:
|
|
46
|
+
navigateUrl = _a.sent();
|
|
47
|
+
redirectStartPage = this.getRedirectStartPage(request.redirectStartPage);
|
|
48
|
+
this.logger.verbosePii("Redirect start page: " + redirectStartPage);
|
|
49
|
+
return [4 /*yield*/, interactionHandler.initiateAuthRequest(navigateUrl, {
|
|
50
|
+
navigationClient: this.navigationClient,
|
|
51
|
+
redirectTimeout: this.config.system.redirectNavigationTimeout,
|
|
52
|
+
redirectStartPage: redirectStartPage,
|
|
53
|
+
onRedirectNavigate: request.onRedirectNavigate
|
|
54
|
+
})];
|
|
55
|
+
case 5:
|
|
56
|
+
// Show the UI once the url has been created. Response will come back in the hash, which will be handled in the handleRedirectCallback function.
|
|
57
|
+
return [2 /*return*/, _a.sent()];
|
|
58
|
+
case 6:
|
|
59
|
+
e_1 = _a.sent();
|
|
60
|
+
if (e_1 instanceof AuthError) {
|
|
61
|
+
e_1.setCorrelationId(this.correlationId);
|
|
62
|
+
}
|
|
63
|
+
serverTelemetryManager.cacheFailedRequest(e_1);
|
|
64
|
+
this.browserStorage.cleanRequestByState(validRequest.state);
|
|
65
|
+
throw e_1;
|
|
66
|
+
case 7: return [2 /*return*/];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Checks if navigateToLoginRequestUrl is set, and:
|
|
73
|
+
* - if true, performs logic to cache and navigate
|
|
74
|
+
* - if false, handles hash string and parses response
|
|
75
|
+
* @param hash
|
|
76
|
+
*/
|
|
77
|
+
RedirectClient.prototype.handleRedirectPromise = function (hash) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var serverTelemetryManager, responseHash, state, loginRequestUrl, loginRequestUrlNormalized, currentUrlNormalized, handleHashResult, navigationOptions, processHashOnRedirect, homepage, e_2;
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.handleRedirectPromise);
|
|
84
|
+
_a.label = 1;
|
|
85
|
+
case 1:
|
|
86
|
+
_a.trys.push([1, 10, , 11]);
|
|
87
|
+
if (!this.browserStorage.isInteractionInProgress(true)) {
|
|
88
|
+
this.logger.info("handleRedirectPromise called but there is no interaction in progress, returning null.");
|
|
89
|
+
return [2 /*return*/, null];
|
|
90
|
+
}
|
|
91
|
+
responseHash = this.getRedirectResponseHash(hash || window.location.hash);
|
|
92
|
+
if (!responseHash) {
|
|
93
|
+
// Not a recognized server response hash or hash not associated with a redirect request
|
|
94
|
+
this.logger.info("handleRedirectPromise did not detect a response hash as a result of a redirect. Cleaning temporary cache.");
|
|
95
|
+
this.browserStorage.cleanRequestByInteractionType(InteractionType.Redirect);
|
|
96
|
+
return [2 /*return*/, null];
|
|
97
|
+
}
|
|
98
|
+
state = void 0;
|
|
99
|
+
try {
|
|
100
|
+
state = this.validateAndExtractStateFromHash(responseHash, InteractionType.Redirect);
|
|
101
|
+
BrowserUtils.clearHash(window);
|
|
102
|
+
this.logger.verbose("State extracted from hash");
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
this.logger.info("handleRedirectPromise was unable to extract state due to: " + e);
|
|
106
|
+
this.browserStorage.cleanRequestByInteractionType(InteractionType.Redirect);
|
|
107
|
+
return [2 /*return*/, null];
|
|
108
|
+
}
|
|
109
|
+
loginRequestUrl = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.ORIGIN_URI, true) || "";
|
|
110
|
+
loginRequestUrlNormalized = UrlString.removeHashFromUrl(loginRequestUrl);
|
|
111
|
+
currentUrlNormalized = UrlString.removeHashFromUrl(window.location.href);
|
|
112
|
+
if (!(loginRequestUrlNormalized === currentUrlNormalized && this.config.auth.navigateToLoginRequestUrl)) return [3 /*break*/, 3];
|
|
113
|
+
// We are on the page we need to navigate to - handle hash
|
|
114
|
+
this.logger.verbose("Current page is loginRequestUrl, handling hash");
|
|
115
|
+
return [4 /*yield*/, this.handleHash(responseHash, state, serverTelemetryManager)];
|
|
116
|
+
case 2:
|
|
117
|
+
handleHashResult = _a.sent();
|
|
118
|
+
if (loginRequestUrl.indexOf("#") > -1) {
|
|
119
|
+
// Replace current hash with non-msal hash, if present
|
|
120
|
+
BrowserUtils.replaceHash(loginRequestUrl);
|
|
121
|
+
}
|
|
122
|
+
return [2 /*return*/, handleHashResult];
|
|
123
|
+
case 3:
|
|
124
|
+
if (!!this.config.auth.navigateToLoginRequestUrl) return [3 /*break*/, 4];
|
|
125
|
+
this.logger.verbose("NavigateToLoginRequestUrl set to false, handling hash");
|
|
126
|
+
return [2 /*return*/, this.handleHash(responseHash, state, serverTelemetryManager)];
|
|
127
|
+
case 4:
|
|
128
|
+
if (!(!BrowserUtils.isInIframe() || this.config.system.allowRedirectInIframe)) return [3 /*break*/, 9];
|
|
129
|
+
/*
|
|
130
|
+
* Returned from authority using redirect - need to perform navigation before processing response
|
|
131
|
+
* Cache the hash to be retrieved after the next redirect
|
|
132
|
+
*/
|
|
133
|
+
this.browserStorage.setTemporaryCache(TemporaryCacheKeys.URL_HASH, responseHash, true);
|
|
134
|
+
navigationOptions = {
|
|
135
|
+
apiId: ApiId.handleRedirectPromise,
|
|
136
|
+
timeout: this.config.system.redirectNavigationTimeout,
|
|
137
|
+
noHistory: true
|
|
138
|
+
};
|
|
139
|
+
processHashOnRedirect = true;
|
|
140
|
+
if (!(!loginRequestUrl || loginRequestUrl === "null")) return [3 /*break*/, 6];
|
|
141
|
+
homepage = BrowserUtils.getHomepage();
|
|
142
|
+
// Cache the homepage under ORIGIN_URI to ensure cached hash is processed on homepage
|
|
143
|
+
this.browserStorage.setTemporaryCache(TemporaryCacheKeys.ORIGIN_URI, homepage, true);
|
|
144
|
+
this.logger.warning("Unable to get valid login request url from cache, redirecting to home page");
|
|
145
|
+
return [4 /*yield*/, this.navigationClient.navigateInternal(homepage, navigationOptions)];
|
|
146
|
+
case 5:
|
|
147
|
+
processHashOnRedirect = _a.sent();
|
|
148
|
+
return [3 /*break*/, 8];
|
|
149
|
+
case 6:
|
|
150
|
+
// Navigate to page that initiated the redirect request
|
|
151
|
+
this.logger.verbose("Navigating to loginRequestUrl: " + loginRequestUrl);
|
|
152
|
+
return [4 /*yield*/, this.navigationClient.navigateInternal(loginRequestUrl, navigationOptions)];
|
|
153
|
+
case 7:
|
|
154
|
+
processHashOnRedirect = _a.sent();
|
|
155
|
+
_a.label = 8;
|
|
156
|
+
case 8:
|
|
157
|
+
// If navigateInternal implementation returns false, handle the hash now
|
|
158
|
+
if (!processHashOnRedirect) {
|
|
159
|
+
return [2 /*return*/, this.handleHash(responseHash, state, serverTelemetryManager)];
|
|
160
|
+
}
|
|
161
|
+
_a.label = 9;
|
|
162
|
+
case 9: return [2 /*return*/, null];
|
|
163
|
+
case 10:
|
|
164
|
+
e_2 = _a.sent();
|
|
165
|
+
if (e_2 instanceof AuthError) {
|
|
166
|
+
e_2.setCorrelationId(this.correlationId);
|
|
167
|
+
}
|
|
168
|
+
serverTelemetryManager.cacheFailedRequest(e_2);
|
|
169
|
+
this.browserStorage.cleanRequestByInteractionType(InteractionType.Redirect);
|
|
170
|
+
throw e_2;
|
|
171
|
+
case 11: return [2 /*return*/];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Gets the response hash for a redirect request
|
|
178
|
+
* Returns null if interactionType in the state value is not "redirect" or the hash does not contain known properties
|
|
179
|
+
* @param hash
|
|
180
|
+
*/
|
|
181
|
+
RedirectClient.prototype.getRedirectResponseHash = function (hash) {
|
|
182
|
+
this.logger.verbose("getRedirectResponseHash called");
|
|
183
|
+
// Get current location hash from window or cache.
|
|
184
|
+
var isResponseHash = UrlString.hashContainsKnownProperties(hash);
|
|
185
|
+
var cachedHash = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.URL_HASH, true);
|
|
186
|
+
this.browserStorage.removeItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.URL_HASH));
|
|
187
|
+
if (isResponseHash) {
|
|
188
|
+
this.logger.verbose("Hash contains known properties, returning response hash");
|
|
189
|
+
return hash;
|
|
190
|
+
}
|
|
191
|
+
this.logger.verbose("Hash does not contain known properties, returning cached hash");
|
|
192
|
+
return cachedHash;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Checks if hash exists and handles in window.
|
|
196
|
+
* @param hash
|
|
197
|
+
* @param state
|
|
198
|
+
*/
|
|
199
|
+
RedirectClient.prototype.handleHash = function (hash, state, serverTelemetryManager) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
+
var cachedRequest, currentAuthority, authClient, interactionHandler;
|
|
202
|
+
return __generator(this, function (_a) {
|
|
203
|
+
switch (_a.label) {
|
|
204
|
+
case 0:
|
|
205
|
+
cachedRequest = this.browserStorage.getCachedRequest(state, this.browserCrypto);
|
|
206
|
+
this.logger.verbose("handleHash called, retrieved cached request");
|
|
207
|
+
currentAuthority = this.browserStorage.getCachedAuthority(state);
|
|
208
|
+
if (!currentAuthority) {
|
|
209
|
+
throw BrowserAuthError.createNoCachedAuthorityError();
|
|
210
|
+
}
|
|
211
|
+
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, currentAuthority)];
|
|
212
|
+
case 1:
|
|
213
|
+
authClient = _a.sent();
|
|
214
|
+
this.logger.verbose("Auth code client created");
|
|
215
|
+
interactionHandler = new RedirectHandler(authClient, this.browserStorage, cachedRequest, this.logger, this.browserCrypto);
|
|
216
|
+
return [4 /*yield*/, interactionHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient, this.config.auth.clientId)];
|
|
217
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Use to log out the current user, and redirect the user to the postLogoutRedirectUri.
|
|
224
|
+
* Default behaviour is to redirect the user to `window.location.href`.
|
|
225
|
+
* @param logoutRequest
|
|
226
|
+
*/
|
|
227
|
+
RedirectClient.prototype.logout = function (logoutRequest) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
229
|
+
var validLogoutRequest, serverTelemetryManager, navigationOptions, authClient, logoutUri, navigate, e_3;
|
|
230
|
+
return __generator(this, function (_a) {
|
|
231
|
+
switch (_a.label) {
|
|
232
|
+
case 0:
|
|
233
|
+
this.logger.verbose("logoutRedirect called");
|
|
234
|
+
validLogoutRequest = this.initializeLogoutRequest(logoutRequest);
|
|
235
|
+
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.logout);
|
|
236
|
+
_a.label = 1;
|
|
237
|
+
case 1:
|
|
238
|
+
_a.trys.push([1, 10, , 11]);
|
|
239
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_START, InteractionType.Redirect, logoutRequest);
|
|
240
|
+
// Clear cache on logout
|
|
241
|
+
return [4 /*yield*/, this.clearCacheOnLogout(validLogoutRequest.account)];
|
|
242
|
+
case 2:
|
|
243
|
+
// Clear cache on logout
|
|
244
|
+
_a.sent();
|
|
245
|
+
navigationOptions = {
|
|
246
|
+
apiId: ApiId.logout,
|
|
247
|
+
timeout: this.config.system.redirectNavigationTimeout,
|
|
248
|
+
noHistory: false
|
|
249
|
+
};
|
|
250
|
+
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, logoutRequest && logoutRequest.authority)];
|
|
251
|
+
case 3:
|
|
252
|
+
authClient = _a.sent();
|
|
253
|
+
this.logger.verbose("Auth code client created");
|
|
254
|
+
logoutUri = authClient.getLogoutUri(validLogoutRequest);
|
|
255
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, InteractionType.Redirect, validLogoutRequest);
|
|
256
|
+
if (!(logoutRequest && typeof logoutRequest.onRedirectNavigate === "function")) return [3 /*break*/, 7];
|
|
257
|
+
navigate = logoutRequest.onRedirectNavigate(logoutUri);
|
|
258
|
+
if (!(navigate !== false)) return [3 /*break*/, 5];
|
|
259
|
+
this.logger.verbose("Logout onRedirectNavigate did not return false, navigating");
|
|
260
|
+
return [4 /*yield*/, this.navigationClient.navigateExternal(logoutUri, navigationOptions)];
|
|
261
|
+
case 4:
|
|
262
|
+
_a.sent();
|
|
263
|
+
return [2 /*return*/];
|
|
264
|
+
case 5:
|
|
265
|
+
this.logger.verbose("Logout onRedirectNavigate returned false, stopping navigation");
|
|
266
|
+
_a.label = 6;
|
|
267
|
+
case 6: return [3 /*break*/, 9];
|
|
268
|
+
case 7: return [4 /*yield*/, this.navigationClient.navigateExternal(logoutUri, navigationOptions)];
|
|
269
|
+
case 8:
|
|
270
|
+
_a.sent();
|
|
271
|
+
return [2 /*return*/];
|
|
272
|
+
case 9: return [3 /*break*/, 11];
|
|
273
|
+
case 10:
|
|
274
|
+
e_3 = _a.sent();
|
|
275
|
+
if (e_3 instanceof AuthError) {
|
|
276
|
+
e_3.setCorrelationId(this.correlationId);
|
|
277
|
+
}
|
|
278
|
+
serverTelemetryManager.cacheFailedRequest(e_3);
|
|
279
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_FAILURE, InteractionType.Redirect, null, e_3);
|
|
280
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_END, InteractionType.Redirect);
|
|
281
|
+
throw e_3;
|
|
282
|
+
case 11:
|
|
283
|
+
this.eventHandler.emitEvent(EventType.LOGOUT_END, InteractionType.Redirect);
|
|
284
|
+
return [2 /*return*/];
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Use to get the redirectStartPage either from request or use current window
|
|
291
|
+
* @param requestStartPage
|
|
292
|
+
*/
|
|
293
|
+
RedirectClient.prototype.getRedirectStartPage = function (requestStartPage) {
|
|
294
|
+
var redirectStartPage = requestStartPage || window.location.href;
|
|
295
|
+
return UrlString.getAbsoluteUrl(redirectStartPage, BrowserUtils.getCurrentUri());
|
|
296
|
+
};
|
|
297
|
+
return RedirectClient;
|
|
298
|
+
}(StandardInteractionClient));
|
|
299
|
+
|
|
300
|
+
export { RedirectClient };
|
|
301
|
+
//# sourceMappingURL=RedirectClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedirectClient.js","sources":["../../src/interaction_client/RedirectClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AuthenticationResult, CommonAuthorizationCodeRequest, AuthorizationCodeClient, UrlString, AuthError, ServerTelemetryManager } from \"@azure/msal-common\";\nimport { StandardInteractionClient } from \"./StandardInteractionClient\";\nimport { AuthorizationUrlRequest } from \"../request/AuthorizationUrlRequest\";\nimport { ApiId, InteractionType, TemporaryCacheKeys } from \"../utils/BrowserConstants\";\nimport { RedirectHandler } from \"../interaction_handler/RedirectHandler\";\nimport { BrowserUtils } from \"../utils/BrowserUtils\";\nimport { EndSessionRequest } from \"../request/EndSessionRequest\";\nimport { EventType } from \"../event/EventType\";\nimport { NavigationOptions } from \"../navigation/NavigationOptions\";\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\nimport { RedirectRequest } from \"../request/RedirectRequest\";\n\nexport class RedirectClient extends StandardInteractionClient { \n /**\n * Redirects the page to the /authorize endpoint of the IDP\n * @param request \n */\n async acquireToken(request: RedirectRequest): Promise<void> {\n const validRequest: AuthorizationUrlRequest = this.preflightInteractiveRequest(request, InteractionType.Redirect);\n const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenRedirect);\n\n try {\n // Create auth code request and generate PKCE params\n const authCodeRequest: CommonAuthorizationCodeRequest = await this.initializeAuthorizationCodeRequest(validRequest);\n\n // Initialize the client\n const authClient: AuthorizationCodeClient = await this.createAuthCodeClient(serverTelemetryManager, validRequest.authority);\n this.logger.verbose(\"Auth code client created\");\n\n // Create redirect interaction handler.\n const interactionHandler = new RedirectHandler(authClient, this.browserStorage, authCodeRequest, this.logger, this.browserCrypto);\n\n // Create acquire token url.\n const navigateUrl = await authClient.getAuthCodeUrl(validRequest);\n\n const redirectStartPage = this.getRedirectStartPage(request.redirectStartPage);\n this.logger.verbosePii(`Redirect start page: ${redirectStartPage}`);\n\n // Show the UI once the url has been created. Response will come back in the hash, which will be handled in the handleRedirectCallback function.\n return await interactionHandler.initiateAuthRequest(navigateUrl, {\n navigationClient: this.navigationClient,\n redirectTimeout: this.config.system.redirectNavigationTimeout,\n redirectStartPage: redirectStartPage,\n onRedirectNavigate: request.onRedirectNavigate\n });\n } catch (e) {\n if (e instanceof AuthError) {\n e.setCorrelationId(this.correlationId);\n }\n serverTelemetryManager.cacheFailedRequest(e);\n this.browserStorage.cleanRequestByState(validRequest.state);\n throw e;\n }\n }\n\n /**\n * Checks if navigateToLoginRequestUrl is set, and:\n * - if true, performs logic to cache and navigate\n * - if false, handles hash string and parses response\n * @param hash\n */\n async handleRedirectPromise(hash?: string): Promise<AuthenticationResult | null> {\n const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.handleRedirectPromise);\n try {\n if (!this.browserStorage.isInteractionInProgress(true)) {\n this.logger.info(\"handleRedirectPromise called but there is no interaction in progress, returning null.\");\n return null;\n }\n\n const responseHash = this.getRedirectResponseHash(hash || window.location.hash);\n if (!responseHash) {\n // Not a recognized server response hash or hash not associated with a redirect request\n this.logger.info(\"handleRedirectPromise did not detect a response hash as a result of a redirect. Cleaning temporary cache.\");\n this.browserStorage.cleanRequestByInteractionType(InteractionType.Redirect);\n return null;\n }\n\n let state: string;\n try {\n state = this.validateAndExtractStateFromHash(responseHash, InteractionType.Redirect);\n BrowserUtils.clearHash(window);\n this.logger.verbose(\"State extracted from hash\");\n } catch (e) {\n this.logger.info(`handleRedirectPromise was unable to extract state due to: ${e}`);\n this.browserStorage.cleanRequestByInteractionType(InteractionType.Redirect);\n return null;\n }\n\n // If navigateToLoginRequestUrl is true, get the url where the redirect request was initiated\n const loginRequestUrl = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.ORIGIN_URI, true) || \"\";\n const loginRequestUrlNormalized = UrlString.removeHashFromUrl(loginRequestUrl);\n const currentUrlNormalized = UrlString.removeHashFromUrl(window.location.href);\n\n if (loginRequestUrlNormalized === currentUrlNormalized && this.config.auth.navigateToLoginRequestUrl) {\n // We are on the page we need to navigate to - handle hash\n this.logger.verbose(\"Current page is loginRequestUrl, handling hash\");\n const handleHashResult = await this.handleHash(responseHash, state, serverTelemetryManager);\n\n if (loginRequestUrl.indexOf(\"#\") > -1) {\n // Replace current hash with non-msal hash, if present\n BrowserUtils.replaceHash(loginRequestUrl);\n }\n\n return handleHashResult;\n } else if (!this.config.auth.navigateToLoginRequestUrl) {\n this.logger.verbose(\"NavigateToLoginRequestUrl set to false, handling hash\");\n return this.handleHash(responseHash, state, serverTelemetryManager);\n } else if (!BrowserUtils.isInIframe() || this.config.system.allowRedirectInIframe) {\n /*\n * Returned from authority using redirect - need to perform navigation before processing response\n * Cache the hash to be retrieved after the next redirect\n */\n this.browserStorage.setTemporaryCache(TemporaryCacheKeys.URL_HASH, responseHash, true);\n const navigationOptions: NavigationOptions = {\n apiId: ApiId.handleRedirectPromise,\n timeout: this.config.system.redirectNavigationTimeout,\n noHistory: true\n };\n\n /**\n * Default behavior is to redirect to the start page and not process the hash now. \n * The start page is expected to also call handleRedirectPromise which will process the hash in one of the checks above.\n */ \n let processHashOnRedirect: boolean = true;\n if (!loginRequestUrl || loginRequestUrl === \"null\") {\n // Redirect to home page if login request url is null (real null or the string null)\n const homepage = BrowserUtils.getHomepage();\n // Cache the homepage under ORIGIN_URI to ensure cached hash is processed on homepage\n this.browserStorage.setTemporaryCache(TemporaryCacheKeys.ORIGIN_URI, homepage, true);\n this.logger.warning(\"Unable to get valid login request url from cache, redirecting to home page\");\n processHashOnRedirect = await this.navigationClient.navigateInternal(homepage, navigationOptions);\n } else {\n // Navigate to page that initiated the redirect request\n this.logger.verbose(`Navigating to loginRequestUrl: ${loginRequestUrl}`);\n processHashOnRedirect = await this.navigationClient.navigateInternal(loginRequestUrl, navigationOptions);\n }\n\n // If navigateInternal implementation returns false, handle the hash now\n if (!processHashOnRedirect) {\n return this.handleHash(responseHash, state, serverTelemetryManager);\n }\n }\n\n return null;\n } catch (e) {\n if (e instanceof AuthError) {\n e.setCorrelationId(this.correlationId);\n }\n serverTelemetryManager.cacheFailedRequest(e);\n this.browserStorage.cleanRequestByInteractionType(InteractionType.Redirect);\n throw e;\n }\n }\n\n /**\n * Gets the response hash for a redirect request\n * Returns null if interactionType in the state value is not \"redirect\" or the hash does not contain known properties\n * @param hash\n */\n private getRedirectResponseHash(hash: string): string | null {\n this.logger.verbose(\"getRedirectResponseHash called\");\n // Get current location hash from window or cache.\n const isResponseHash: boolean = UrlString.hashContainsKnownProperties(hash);\n const cachedHash = this.browserStorage.getTemporaryCache(TemporaryCacheKeys.URL_HASH, true);\n this.browserStorage.removeItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.URL_HASH));\n\n if (isResponseHash) {\n this.logger.verbose(\"Hash contains known properties, returning response hash\");\n return hash;\n }\n\n this.logger.verbose(\"Hash does not contain known properties, returning cached hash\");\n return cachedHash;\n }\n\n /**\n * Checks if hash exists and handles in window.\n * @param hash\n * @param state\n */\n private async handleHash(hash: string, state: string, serverTelemetryManager: ServerTelemetryManager): Promise<AuthenticationResult> {\n const cachedRequest = this.browserStorage.getCachedRequest(state, this.browserCrypto);\n this.logger.verbose(\"handleHash called, retrieved cached request\");\n\n // Hash contains known properties - handle and return in callback\n const currentAuthority = this.browserStorage.getCachedAuthority(state);\n if (!currentAuthority) {\n throw BrowserAuthError.createNoCachedAuthorityError();\n }\n\n const authClient = await this.createAuthCodeClient(serverTelemetryManager, currentAuthority);\n this.logger.verbose(\"Auth code client created\");\n const interactionHandler = new RedirectHandler(authClient, this.browserStorage, cachedRequest, this.logger, this.browserCrypto);\n return await interactionHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient, this.config.auth.clientId);\n }\n\n /**\n * Use to log out the current user, and redirect the user to the postLogoutRedirectUri.\n * Default behaviour is to redirect the user to `window.location.href`.\n * @param logoutRequest\n */\n async logout(logoutRequest?: EndSessionRequest): Promise<void> {\n this.logger.verbose(\"logoutRedirect called\");\n const validLogoutRequest = this.initializeLogoutRequest(logoutRequest);\n const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.logout);\n\n try {\n this.eventHandler.emitEvent(EventType.LOGOUT_START, InteractionType.Redirect, logoutRequest);\n \n // Clear cache on logout\n await this.clearCacheOnLogout(validLogoutRequest.account);\n \n const navigationOptions: NavigationOptions = {\n apiId: ApiId.logout,\n timeout: this.config.system.redirectNavigationTimeout,\n noHistory: false\n };\n const authClient = await this.createAuthCodeClient(serverTelemetryManager, logoutRequest && logoutRequest.authority);\n this.logger.verbose(\"Auth code client created\");\n\n // Create logout string and navigate user window to logout.\n const logoutUri: string = authClient.getLogoutUri(validLogoutRequest);\n \n this.eventHandler.emitEvent(EventType.LOGOUT_SUCCESS, InteractionType.Redirect, validLogoutRequest);\n // Check if onRedirectNavigate is implemented, and invoke it if so\n if (logoutRequest && typeof logoutRequest.onRedirectNavigate === \"function\") {\n const navigate = logoutRequest.onRedirectNavigate(logoutUri);\n\n if (navigate !== false) {\n this.logger.verbose(\"Logout onRedirectNavigate did not return false, navigating\");\n await this.navigationClient.navigateExternal(logoutUri, navigationOptions);\n return;\n } else {\n this.logger.verbose(\"Logout onRedirectNavigate returned false, stopping navigation\");\n }\n } else {\n await this.navigationClient.navigateExternal(logoutUri, navigationOptions);\n return;\n }\n } catch(e) {\n if (e instanceof AuthError) {\n e.setCorrelationId(this.correlationId);\n }\n serverTelemetryManager.cacheFailedRequest(e);\n this.eventHandler.emitEvent(EventType.LOGOUT_FAILURE, InteractionType.Redirect, null, e);\n this.eventHandler.emitEvent(EventType.LOGOUT_END, InteractionType.Redirect);\n throw e;\n }\n\n this.eventHandler.emitEvent(EventType.LOGOUT_END, InteractionType.Redirect);\n }\n\n /**\n * Use to get the redirectStartPage either from request or use current window\n * @param requestStartPage\n */\n protected getRedirectStartPage(requestStartPage?: string): string {\n const redirectStartPage = requestStartPage || window.location.href;\n return UrlString.getAbsoluteUrl(redirectStartPage, BrowserUtils.getCurrentUri());\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;;;;;IAiBoC,kCAAyB;IAA7D;;KAwPC;;;;;IAnPS,qCAAY,GAAlB,UAAmB,OAAwB;;;;;;wBACjC,YAAY,GAA4B,IAAI,CAAC,2BAA2B,CAAC,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;wBAC5G,sBAAsB,GAAG,IAAI,CAAC,gCAAgC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;;;;wBAIrC,qBAAM,IAAI,CAAC,kCAAkC,CAAC,YAAY,C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ardInteractionClient";
|
|
2
|
+
import { CommonSilentFlowRequest, AuthenticationResult, SilentFlowClient, ServerTelemetryManager, AccountInfo } from "@azure/msal-common";
|
|
3
|
+
import { SilentRequest } from "../request/SilentRequest";
|
|
4
|
+
export declare class SilentCacheClient extends StandardInteractionClient {
|
|
5
|
+
/**
|
|
6
|
+
* Returns unexpired tokens from the cache, if available
|
|
7
|
+
* @param silentRequest
|
|
8
|
+
*/
|
|
9
|
+
acquireToken(silentRequest: CommonSilentFlowRequest): Promise<AuthenticationResult>;
|
|
10
|
+
/**
|
|
11
|
+
* Currently Unsupported
|
|
12
|
+
*/
|
|
13
|
+
logout(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an Silent Flow Client with the given authority, or the default authority.
|
|
16
|
+
* @param serverTelemetryManager
|
|
17
|
+
* @param authorityUrl
|
|
18
|
+
*/
|
|
19
|
+
protected createSilentFlowClient(serverTelemetryManager: ServerTelemetryManager, authorityUrl?: string): Promise<SilentFlowClient>;
|
|
20
|
+
initializeSilentRequest(request: SilentRequest, account: AccountInfo): CommonSilentFlowRequest;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=SilentCacheClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SilentCacheClient.d.ts","sourceRoot":"","sources":["../../src/interaction_client/SilentCacheClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1I,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,qBAAa,iBAAkB,SAAQ,yBAAyB;IAC5D;;;OAGG;IACG,YAAY,CAAC,aAAa,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAkBzF;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAKvB;;;;OAIG;cACa,sBAAsB,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAMxI,uBAAuB,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,GAAG,uBAAuB;CAQjG"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*! @azure/msal-browser v2.19.0 2021-11-02 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { __extends, __awaiter, __generator, __assign } from '../_virtual/_tslib.js';
|
|
4
|
+
import { StandardInteractionClient } from './StandardInteractionClient.js';
|
|
5
|
+
import { SilentFlowClient } from '@azure/msal-common';
|
|
6
|
+
import { EventType } from '../event/EventType.js';
|
|
7
|
+
import { InteractionType, ApiId } from '../utils/BrowserConstants.js';
|
|
8
|
+
import { BrowserAuthError, BrowserAuthErrorMessage } from '../error/BrowserAuthError.js';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
12
|
+
* Licensed under the MIT License.
|
|
13
|
+
*/
|
|
14
|
+
var SilentCacheClient = /** @class */ (function (_super) {
|
|
15
|
+
__extends(SilentCacheClient, _super);
|
|
16
|
+
function SilentCacheClient() {
|
|
17
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns unexpired tokens from the cache, if available
|
|
21
|
+
* @param silentRequest
|
|
22
|
+
*/
|
|
23
|
+
SilentCacheClient.prototype.acquireToken = function (silentRequest) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
25
|
+
var serverTelemetryManager, silentAuthClient, cachedToken, error_1;
|
|
26
|
+
return __generator(this, function (_a) {
|
|
27
|
+
switch (_a.label) {
|
|
28
|
+
case 0:
|
|
29
|
+
serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent_silentFlow);
|
|
30
|
+
return [4 /*yield*/, this.createSilentFlowClient(serverTelemetryManager, silentRequest.authority)];
|
|
31
|
+
case 1:
|
|
32
|
+
silentAuthClient = _a.sent();
|
|
33
|
+
this.logger.verbose("Silent auth client created");
|
|
34
|
+
_a.label = 2;
|
|
35
|
+
case 2:
|
|
36
|
+
_a.trys.push([2, 4, , 5]);
|
|
37
|
+
return [4 /*yield*/, silentAuthClient.acquireCachedToken(silentRequest)];
|
|
38
|
+
case 3:
|
|
39
|
+
cachedToken = _a.sent();
|
|
40
|
+
this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Silent, cachedToken);
|
|
41
|
+
return [2 /*return*/, cachedToken];
|
|
42
|
+
case 4:
|
|
43
|
+
error_1 = _a.sent();
|
|
44
|
+
if (error_1 instanceof BrowserAuthError && error_1.errorCode === BrowserAuthErrorMessage.signingKeyNotFoundInStorage.code) {
|
|
45
|
+
this.logger.verbose("Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair.");
|
|
46
|
+
}
|
|
47
|
+
throw error_1;
|
|
48
|
+
case 5: return [2 /*return*/];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Currently Unsupported
|
|
55
|
+
*/
|
|
56
|
+
SilentCacheClient.prototype.logout = function () {
|
|
57
|
+
// Synchronous so we must reject
|
|
58
|
+
return Promise.reject(BrowserAuthError.createSilentLogoutUnsupportedError());
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Creates an Silent Flow Client with the given authority, or the default authority.
|
|
62
|
+
* @param serverTelemetryManager
|
|
63
|
+
* @param authorityUrl
|
|
64
|
+
*/
|
|
65
|
+
SilentCacheClient.prototype.createSilentFlowClient = function (serverTelemetryManager, authorityUrl) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
+
var clientConfig;
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0: return [4 /*yield*/, this.getClientConfiguration(serverTelemetryManager, authorityUrl)];
|
|
71
|
+
case 1:
|
|
72
|
+
clientConfig = _a.sent();
|
|
73
|
+
return [2 /*return*/, new SilentFlowClient(clientConfig)];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
SilentCacheClient.prototype.initializeSilentRequest = function (request, account) {
|
|
79
|
+
return __assign(__assign(__assign({}, request), this.initializeBaseRequest(request)), { account: account, forceRefresh: request.forceRefresh || false });
|
|
80
|
+
};
|
|
81
|
+
return SilentCacheClient;
|
|
82
|
+
}(StandardInteractionClient));
|
|
83
|
+
|
|
84
|
+
export { SilentCacheClient };
|
|
85
|
+
//# sourceMappingURL=SilentCacheClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SilentCacheClient.js","sources":["../../src/interaction_client/SilentCacheClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { StandardInteractionClient } from \"./StandardInteractionClient\";\nimport { CommonSilentFlowRequest, AuthenticationResult, SilentFlowClient, ServerTelemetryManager, AccountInfo } from \"@azure/msal-common\";\nimport { SilentRequest } from \"../request/SilentRequest\";\nimport { EventType } from \"../event/EventType\";\nimport { InteractionType, ApiId } from \"../utils/BrowserConstants\";\nimport { BrowserAuthError, BrowserAuthErrorMessage } from \"../error/BrowserAuthError\";\n\nexport class SilentCacheClient extends StandardInteractionClient {\n /**\n * Returns unexpired tokens from the cache, if available\n * @param silentRequest \n */\n async acquireToken(silentRequest: CommonSilentFlowRequest): Promise<AuthenticationResult> {\n // Telemetry manager only used to increment cacheHits here\n const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent_silentFlow);\n const silentAuthClient = await this.createSilentFlowClient(serverTelemetryManager, silentRequest.authority);\n this.logger.verbose(\"Silent auth client created\");\n \n try {\n const cachedToken = await silentAuthClient.acquireCachedToken(silentRequest);\n this.eventHandler.emitEvent(EventType.ACQUIRE_TOKEN_SUCCESS, InteractionType.Silent, cachedToken);\n return cachedToken;\n } catch (error) {\n if (error instanceof BrowserAuthError && error.errorCode === BrowserAuthErrorMessage.signingKeyNotFoundInStorage.code) {\n this.logger.verbose(\"Signing keypair for bound access token not found. Refreshing bound access token and generating a new crypto keypair.\");\n }\n throw error;\n }\n }\n \n /**\n * Currently Unsupported\n */\n logout(): Promise<void> {\n // Synchronous so we must reject\n return Promise.reject(BrowserAuthError.createSilentLogoutUnsupportedError());\n }\n\n /**\n * Creates an Silent Flow Client with the given authority, or the default authority.\n * @param serverTelemetryManager\n * @param authorityUrl\n */\n protected async createSilentFlowClient(serverTelemetryManager: ServerTelemetryManager, authorityUrl?: string): Promise<SilentFlowClient> {\n // Create auth module.\n const clientConfig = await this.getClientConfiguration(serverTelemetryManager, authorityUrl);\n return new SilentFlowClient(clientConfig);\n }\n\n initializeSilentRequest(request: SilentRequest, account: AccountInfo): CommonSilentFlowRequest {\n return {\n ...request,\n ...this.initializeBaseRequest(request),\n account: account,\n forceRefresh: request.forceRefresh || false\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;IAYuC,qCAAyB;IAAhE;;KAkDC;;;;;IA7CS,wCAAY,GAAlB,UAAmB,aAAsC;;;;;;wBAE/C,sBAAsB,GAAG,IAAI,CAAC,gCAAgC,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;wBACjF,qBAAM,IAAI,CAAC,sBAAsB,CAAC,sBAAsB,EAAE,aAAa,CAAC,SAAS,CAAC,EAAA;;wBAArG,gBAAgB,GAAG,SAAkF;wBAC3G,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC;;;;wBAG1B,qBAAM,gBAAgB,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAA;;wBAAtE,WAAW,GAAG,SAAwD;wBAC5E,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,qBAAqB,EAAE,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;wBAClG,sBAAO,WAAW,EAAC;;;wBAEnB,IAAI,OAAK,YAAY,gBAAgB,IAAI,OAAK,CAAC,SAAS,KAAK,uBAAuB,CAAC,2BAA2B,CAAC,IAAI,EAAE;4BACnH,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,sHAAsH,CAAC,CAAC;yBAC/I;wBACD,MAAM,OAAK,CAAC;;;;;KAEnB;;;;IAKD,kCAAM,GAAN;;QAEI,OAAO,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,kCAAkC,EAAE,CAAC,CAAC;KAChF;;;;;;IAOe,kDAAsB,GAAtC,UAAuC,sBAA8C,EAAE,YAAqB;;;;;4BAEnF,qBAAM,IAAI,CAAC,sBAAsB,CAAC,sBAAsB,EAAE,YAAY,CAAC,EAAA;;wBAAtF,YAAY,GAAG,SAAuE;wBAC5F,sBAAO,IAAI,gBAAgB,CAAC,YAAY,CAAC,EAAC;;;;KAC7C;IAED,mDAAuB,GAAvB,UAAwB,OAAsB,EAAE,OAAoB;QAChE,sCACO,OAAO,GACP,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,KACtC,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,KAAK,IAC7C;KACL;IACL,wBAAC;AAAD,CAlDA,CAAuC,yBAAyB;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AuthenticationResult, ICrypto, Logger } from "@azure/msal-common";
|
|
2
|
+
import { StandardInteractionClient } from "./StandardInteractionClient";
|
|
3
|
+
import { BrowserConfiguration } from "../config/Configuration";
|
|
4
|
+
import { BrowserCacheManager } from "../cache/BrowserCacheManager";
|
|
5
|
+
import { EventHandler } from "../event/EventHandler";
|
|
6
|
+
import { INavigationClient } from "../navigation/INavigationClient";
|
|
7
|
+
import { ApiId } from "../utils/BrowserConstants";
|
|
8
|
+
import { SsoSilentRequest } from "../request/SsoSilentRequest";
|
|
9
|
+
export declare class SilentIframeClient extends StandardInteractionClient {
|
|
10
|
+
private apiId;
|
|
11
|
+
constructor(config: BrowserConfiguration, storageImpl: BrowserCacheManager, browserCrypto: ICrypto, logger: Logger, eventHandler: EventHandler, navigationClient: INavigationClient, apiId: ApiId, correlationId?: string);
|
|
12
|
+
/**
|
|
13
|
+
* Acquires a token silently by opening a hidden iframe to the /authorize endpoint with prompt=none
|
|
14
|
+
* @param request
|
|
15
|
+
*/
|
|
16
|
+
acquireToken(request: SsoSilentRequest): Promise<AuthenticationResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Currently Unsupported
|
|
19
|
+
*/
|
|
20
|
+
logout(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Helper which acquires an authorization code silently using a hidden iframe from given url
|
|
23
|
+
* using the scopes requested as part of the id, and exchanges the code for a set of OAuth tokens.
|
|
24
|
+
* @param navigateUrl
|
|
25
|
+
* @param userRequestScopes
|
|
26
|
+
*/
|
|
27
|
+
private silentTokenHelper;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=SilentIframeClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SilentIframeClient.d.ts","sourceRoot":"","sources":["../../src/interaction_client/SilentIframeClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,EAAgG,MAAM,oBAAoB,CAAC;AACzK,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAmB,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,qBAAa,kBAAmB,SAAQ,yBAAyB;IAC7D,OAAO,CAAC,KAAK,CAAQ;gBAET,MAAM,EAAE,oBAAoB,EAAE,WAAW,EAAE,mBAAmB,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,MAAM;IAKzN;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA0C5E;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAKvB;;;;;OAKG;YACW,iBAAiB;CAYlC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*! @azure/msal-browser v2.19.0 2021-11-02 */
|
|
2
|
+
'use strict';
|
|
3
|
+
import { __extends, __awaiter, __generator, __assign } from '../_virtual/_tslib.js';
|
|
4
|
+
import { AuthError, StringUtils, PromptValue } from '@azure/msal-common';
|
|
5
|
+
import { StandardInteractionClient } from './StandardInteractionClient.js';
|
|
6
|
+
import { BrowserAuthError } from '../error/BrowserAuthError.js';
|
|
7
|
+
import { InteractionType } from '../utils/BrowserConstants.js';
|
|
8
|
+
import { SilentHandler } from '../interaction_handler/SilentHandler.js';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
12
|
+
* Licensed under the MIT License.
|
|
13
|
+
*/
|
|
14
|
+
var SilentIframeClient = /** @class */ (function (_super) {
|
|
15
|
+
__extends(SilentIframeClient, _super);
|
|
16
|
+
function SilentIframeClient(config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, apiId, correlationId) {
|
|
17
|
+
var _this = _super.call(this, config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, correlationId) || this;
|
|
18
|
+
_this.apiId = apiId;
|
|
19
|
+
return _this;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Acquires a token silently by opening a hidden iframe to the /authorize endpoint with prompt=none
|
|
23
|
+
* @param request
|
|
24
|
+
*/
|
|
25
|
+
SilentIframeClient.prototype.acquireToken = function (request) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
27
|
+
var silentRequest, serverTelemetryManager, authCodeRequest, authClient, navigateUrl, e_1;
|
|
28
|
+
return __generator(this, function (_a) {
|
|
29
|
+
switch (_a.label) {
|
|
30
|
+
case 0:
|
|
31
|
+
this.logger.verbose("acquireTokenByIframe called");
|
|
32
|
+
// Check that we have some SSO data
|
|
33
|
+
if (StringUtils.isEmpty(request.loginHint) && StringUtils.isEmpty(request.sid) && (!request.account || StringUtils.isEmpty(request.account.username))) {
|
|
34
|
+
this.logger.warning("No user hint provided. The authorization server may need more information to complete this request.");
|
|
35
|
+
}
|
|
36
|
+
// Check that prompt is set to none, throw error if it is set to anything else.
|
|
37
|
+
if (request.prompt && request.prompt !== PromptValue.NONE) {
|
|
38
|
+
throw BrowserAuthError.createSilentPromptValueError(request.prompt);
|
|
39
|
+
}
|
|
40
|
+
silentRequest = this.initializeAuthorizationRequest(__assign(__assign({}, request), { prompt: PromptValue.NONE }), InteractionType.Silent);
|
|
41
|
+
serverTelemetryManager = this.initializeServerTelemetryManager(this.apiId);
|
|
42
|
+
_a.label = 1;
|
|
43
|
+
case 1:
|
|
44
|
+
_a.trys.push([1, 6, , 7]);
|
|
45
|
+
return [4 /*yield*/, this.initializeAuthorizationCodeRequest(silentRequest)];
|
|
46
|
+
case 2:
|
|
47
|
+
authCodeRequest = _a.sent();
|
|
48
|
+
return [4 /*yield*/, this.createAuthCodeClient(serverTelemetryManager, silentRequest.authority)];
|
|
49
|
+
case 3:
|
|
50
|
+
authClient = _a.sent();
|
|
51
|
+
this.logger.verbose("Auth code client created");
|
|
52
|
+
return [4 /*yield*/, authClient.getAuthCodeUrl(silentRequest)];
|
|
53
|
+
case 4:
|
|
54
|
+
navigateUrl = _a.sent();
|
|
55
|
+
return [4 /*yield*/, this.silentTokenHelper(navigateUrl, authCodeRequest, authClient, this.logger)];
|
|
56
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
57
|
+
case 6:
|
|
58
|
+
e_1 = _a.sent();
|
|
59
|
+
if (e_1 instanceof AuthError) {
|
|
60
|
+
e_1.setCorrelationId(this.correlationId);
|
|
61
|
+
}
|
|
62
|
+
serverTelemetryManager.cacheFailedRequest(e_1);
|
|
63
|
+
this.browserStorage.cleanRequestByState(silentRequest.state);
|
|
64
|
+
throw e_1;
|
|
65
|
+
case 7: return [2 /*return*/];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Currently Unsupported
|
|
72
|
+
*/
|
|
73
|
+
SilentIframeClient.prototype.logout = function () {
|
|
74
|
+
// Synchronous so we must reject
|
|
75
|
+
return Promise.reject(BrowserAuthError.createSilentLogoutUnsupportedError());
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Helper which acquires an authorization code silently using a hidden iframe from given url
|
|
79
|
+
* using the scopes requested as part of the id, and exchanges the code for a set of OAuth tokens.
|
|
80
|
+
* @param navigateUrl
|
|
81
|
+
* @param userRequestScopes
|
|
82
|
+
*/
|
|
83
|
+
SilentIframeClient.prototype.silentTokenHelper = function (navigateUrl, authCodeRequest, authClient, browserRequestLogger) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
var silentHandler, msalFrame, hash, state;
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0:
|
|
89
|
+
silentHandler = new SilentHandler(authClient, this.browserStorage, authCodeRequest, browserRequestLogger, this.config.system.navigateFrameWait);
|
|
90
|
+
return [4 /*yield*/, silentHandler.initiateAuthRequest(navigateUrl)];
|
|
91
|
+
case 1:
|
|
92
|
+
msalFrame = _a.sent();
|
|
93
|
+
return [4 /*yield*/, silentHandler.monitorIframeForHash(msalFrame, this.config.system.iframeHashTimeout)];
|
|
94
|
+
case 2:
|
|
95
|
+
hash = _a.sent();
|
|
96
|
+
state = this.validateAndExtractStateFromHash(hash, InteractionType.Silent, authCodeRequest.correlationId);
|
|
97
|
+
// Handle response from hash string
|
|
98
|
+
return [2 /*return*/, silentHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient)];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
return SilentIframeClient;
|
|
104
|
+
}(StandardInteractionClient));
|
|
105
|
+
|
|
106
|
+
export { SilentIframeClient };
|
|
107
|
+
//# sourceMappingURL=SilentIframeClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SilentIframeClient.js","sources":["../../src/interaction_client/SilentIframeClient.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { AuthenticationResult, ICrypto, Logger, StringUtils, PromptValue, CommonAuthorizationCodeRequest, AuthorizationCodeClient, AuthError } from \"@azure/msal-common\";\nimport { StandardInteractionClient } from \"./StandardInteractionClient\";\nimport { AuthorizationUrlRequest } from \"../request/AuthorizationUrlRequest\";\nimport { BrowserConfiguration } from \"../config/Configuration\";\nimport { BrowserCacheManager } from \"../cache/BrowserCacheManager\";\nimport { EventHandler } from \"../event/EventHandler\";\nimport { INavigationClient } from \"../navigation/INavigationClient\";\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\nimport { InteractionType, ApiId } from \"../utils/BrowserConstants\";\nimport { SilentHandler } from \"../interaction_handler/SilentHandler\";\nimport { SsoSilentRequest } from \"../request/SsoSilentRequest\";\n\nexport class SilentIframeClient extends StandardInteractionClient {\n private apiId: ApiId;\n\n constructor(config: BrowserConfiguration, storageImpl: BrowserCacheManager, browserCrypto: ICrypto, logger: Logger, eventHandler: EventHandler, navigationClient: INavigationClient, apiId: ApiId, correlationId?: string) {\n super(config, storageImpl, browserCrypto, logger, eventHandler, navigationClient, correlationId);\n this.apiId = apiId;\n }\n \n /**\n * Acquires a token silently by opening a hidden iframe to the /authorize endpoint with prompt=none\n * @param request \n */\n async acquireToken(request: SsoSilentRequest): Promise<AuthenticationResult> {\n this.logger.verbose(\"acquireTokenByIframe called\");\n // Check that we have some SSO data\n if (StringUtils.isEmpty(request.loginHint) && StringUtils.isEmpty(request.sid) && (!request.account || StringUtils.isEmpty(request.account.username))) {\n this.logger.warning(\"No user hint provided. The authorization server may need more information to complete this request.\");\n }\n\n // Check that prompt is set to none, throw error if it is set to anything else.\n if (request.prompt && request.prompt !== PromptValue.NONE) {\n throw BrowserAuthError.createSilentPromptValueError(request.prompt);\n }\n\n // Create silent request\n const silentRequest: AuthorizationUrlRequest = this.initializeAuthorizationRequest({\n ...request,\n prompt: PromptValue.NONE\n }, InteractionType.Silent);\n\n const serverTelemetryManager = this.initializeServerTelemetryManager(this.apiId);\n\n try {\n // Create auth code request and generate PKCE params\n const authCodeRequest: CommonAuthorizationCodeRequest = await this.initializeAuthorizationCodeRequest(silentRequest);\n\n // Initialize the client\n const authClient: AuthorizationCodeClient = await this.createAuthCodeClient(serverTelemetryManager, silentRequest.authority);\n this.logger.verbose(\"Auth code client created\");\n\n // Create authorize request url\n const navigateUrl = await authClient.getAuthCodeUrl(silentRequest);\n\n return await this.silentTokenHelper(navigateUrl, authCodeRequest, authClient, this.logger);\n } catch (e) {\n if (e instanceof AuthError) {\n e.setCorrelationId(this.correlationId);\n }\n serverTelemetryManager.cacheFailedRequest(e);\n this.browserStorage.cleanRequestByState(silentRequest.state);\n throw e;\n }\n }\n\n /**\n * Currently Unsupported\n */\n logout(): Promise<void> {\n // Synchronous so we must reject\n return Promise.reject(BrowserAuthError.createSilentLogoutUnsupportedError());\n }\n\n /**\n * Helper which acquires an authorization code silently using a hidden iframe from given url\n * using the scopes requested as part of the id, and exchanges the code for a set of OAuth tokens.\n * @param navigateUrl\n * @param userRequestScopes\n */\n private async silentTokenHelper(navigateUrl: string, authCodeRequest: CommonAuthorizationCodeRequest, authClient: AuthorizationCodeClient, browserRequestLogger: Logger): Promise<AuthenticationResult> {\n // Create silent handler\n const silentHandler = new SilentHandler(authClient, this.browserStorage, authCodeRequest, browserRequestLogger, this.config.system.navigateFrameWait);\n // Get the frame handle for the silent request\n const msalFrame = await silentHandler.initiateAuthRequest(navigateUrl);\n // Monitor the window for the hash. Return the string value and close the popup when the hash is received. Default timeout is 60 seconds.\n const hash = await silentHandler.monitorIframeForHash(msalFrame, this.config.system.iframeHashTimeout);\n const state = this.validateAndExtractStateFromHash(hash, InteractionType.Silent, authCodeRequest.correlationId);\n\n // Handle response from hash string\n return silentHandler.handleCodeResponse(hash, state, authClient.authority, this.networkClient);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;IAiBwC,sCAAyB;IAG7D,4BAAY,MAA4B,EAAE,WAAgC,EAAE,aAAsB,EAAE,MAAc,EAAE,YAA0B,EAAE,gBAAmC,EAAE,KAAY,EAAE,aAAsB;QAAzN,YACI,kBAAM,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,CAAC,SAEnG;QADG,KAAI,CAAC,KAAK,GAAG,KAAK,CAAC;;KACtB;;;;;IAMK,yCAAY,GAAlB,UAAmB,OAAyB;;;;;;wBACxC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;;wBAEnD,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE;4BACnJ,IA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