1 |
|
2 |
|
3 |
|
4 |
|
5 | import { __assign, __awaiter, __generator } from "tslib";
|
6 | import { AccessTokenKey } from "./cache/AccessTokenKey";
|
7 | import { AccessTokenValue } from "./cache/AccessTokenValue";
|
8 | import { ServerRequestParameters } from "./ServerRequestParameters";
|
9 | import { AuthorityType } from "./authority/Authority";
|
10 | import { ClientInfo } from "./ClientInfo";
|
11 | import { IdToken } from "./IdToken";
|
12 | import { AuthCache } from "./cache/AuthCache";
|
13 | import { Account } from "./Account";
|
14 | import { ScopeSet } from "./ScopeSet";
|
15 | import { StringUtils } from "./utils/StringUtils";
|
16 | import { WindowUtils } from "./utils/WindowUtils";
|
17 | import { TokenUtils } from "./utils/TokenUtils";
|
18 | import { TimeUtils } from "./utils/TimeUtils";
|
19 | import { UrlUtils } from "./utils/UrlUtils";
|
20 | import { RequestUtils } from "./utils/RequestUtils";
|
21 | import { ResponseUtils } from "./utils/ResponseUtils";
|
22 | import { AuthorityFactory } from "./authority/AuthorityFactory";
|
23 | import { buildConfiguration } from "./Configuration";
|
24 | import { ClientConfigurationError } from "./error/ClientConfigurationError";
|
25 | import { AuthError } from "./error/AuthError";
|
26 | import { ClientAuthError, ClientAuthErrorMessage } from "./error/ClientAuthError";
|
27 | import { ServerError } from "./error/ServerError";
|
28 | import { InteractionRequiredAuthError } from "./error/InteractionRequiredAuthError";
|
29 | import { buildResponseStateOnly } from "./AuthResponse";
|
30 | import TelemetryManager from "./telemetry/TelemetryManager";
|
31 | import { API_EVENT_IDENTIFIER } from "./telemetry/ApiEvent";
|
32 | import { Constants, ServerHashParamKeys, ResponseTypes, TemporaryCacheKeys, PersistentCacheKeys, ErrorCacheKeys, FramePrefix } from "./utils/Constants";
|
33 | import { CryptoUtils } from "./utils/CryptoUtils";
|
34 | import { TrustedAuthority } from "./authority/TrustedAuthority";
|
35 | import { AuthCacheUtils } from "./utils/AuthCacheUtils";
|
36 |
|
37 | var DEFAULT_AUTHORITY = "https://login.microsoftonline.com/common";
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | var UserAgentApplication = (function () {
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | function UserAgentApplication(configuration) {
|
66 |
|
67 | this.authResponseCallback = null;
|
68 | this.tokenReceivedCallback = null;
|
69 | this.errorReceivedCallback = null;
|
70 |
|
71 | this.config = buildConfiguration(configuration);
|
72 | this.logger = this.config.system.logger;
|
73 | this.clientId = this.config.auth.clientId;
|
74 | this.inCookie = this.config.cache.storeAuthStateInCookie;
|
75 | this.telemetryManager = this.getTelemetryManagerFromConfig(this.config.system.telemetry, this.clientId);
|
76 | TrustedAuthority.setTrustedAuthoritiesFromConfig(this.config.auth.validateAuthority, this.config.auth.knownAuthorities);
|
77 | AuthorityFactory.saveMetadataFromConfig(this.config.auth.authority, this.config.auth.authorityMetadata);
|
78 |
|
79 | this.authority = this.config.auth.authority || DEFAULT_AUTHORITY;
|
80 |
|
81 | this.cacheStorage = new AuthCache(this.clientId, this.config.cache.cacheLocation, this.inCookie);
|
82 |
|
83 | if (!window.activeRenewals) {
|
84 | window.activeRenewals = {};
|
85 | }
|
86 | if (!window.renewStates) {
|
87 | window.renewStates = [];
|
88 | }
|
89 | if (!window.callbackMappedToRenewStates) {
|
90 | window.callbackMappedToRenewStates = {};
|
91 | }
|
92 | if (!window.promiseMappedToRenewStates) {
|
93 | window.promiseMappedToRenewStates = {};
|
94 | }
|
95 | window.msal = this;
|
96 | var urlHash = window.location.hash;
|
97 | var urlContainsHash = UrlUtils.urlContainsHash(urlHash);
|
98 |
|
99 | WindowUtils.checkIfBackButtonIsPressed(this.cacheStorage);
|
100 |
|
101 | if (urlContainsHash && this.cacheStorage.isInteractionInProgress(true)) {
|
102 | var stateInfo = this.getResponseState(urlHash);
|
103 | if (stateInfo.method === Constants.interactionTypeRedirect) {
|
104 | this.handleRedirectAuthenticationResponse(urlHash);
|
105 | }
|
106 | }
|
107 | }
|
108 | Object.defineProperty(UserAgentApplication.prototype, "authority", {
|
109 | |
110 |
|
111 |
|
112 |
|
113 |
|
114 | get: function () {
|
115 | return this.authorityInstance.CanonicalAuthority;
|
116 | },
|
117 | |
118 |
|
119 |
|
120 |
|
121 |
|
122 | set: function (val) {
|
123 | this.authorityInstance = AuthorityFactory.CreateInstance(val, this.config.auth.validateAuthority);
|
124 | },
|
125 | enumerable: false,
|
126 | configurable: true
|
127 | });
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 | UserAgentApplication.prototype.getAuthorityInstance = function () {
|
134 | return this.authorityInstance;
|
135 | };
|
136 | UserAgentApplication.prototype.handleRedirectCallback = function (authOrTokenCallback, errorReceivedCallback) {
|
137 | if (!authOrTokenCallback) {
|
138 | throw ClientConfigurationError.createInvalidCallbackObjectError(authOrTokenCallback);
|
139 | }
|
140 |
|
141 | if (errorReceivedCallback) {
|
142 | this.tokenReceivedCallback = authOrTokenCallback;
|
143 | this.errorReceivedCallback = errorReceivedCallback;
|
144 | this.logger.warning("This overload for callback is deprecated - please change the format of the callbacks to a single callback as shown: (err: AuthError, response: AuthResponse).");
|
145 | }
|
146 | else {
|
147 | this.authResponseCallback = authOrTokenCallback;
|
148 | }
|
149 | if (this.redirectError) {
|
150 | this.authErrorHandler(Constants.interactionTypeRedirect, this.redirectError, this.redirectResponse);
|
151 | }
|
152 | else if (this.redirectResponse) {
|
153 | this.authResponseHandler(Constants.interactionTypeRedirect, this.redirectResponse);
|
154 | }
|
155 | };
|
156 | |
157 |
|
158 |
|
159 |
|
160 | UserAgentApplication.prototype.urlContainsHash = function (hash) {
|
161 | this.logger.verbose("UrlContainsHash has been called");
|
162 | return UrlUtils.urlContainsHash(hash);
|
163 | };
|
164 | UserAgentApplication.prototype.authResponseHandler = function (interactionType, response, resolve) {
|
165 | this.logger.verbose("AuthResponseHandler has been called");
|
166 | this.cacheStorage.setInteractionInProgress(false);
|
167 | if (interactionType === Constants.interactionTypeRedirect) {
|
168 | this.logger.verbose("Interaction type is redirect");
|
169 | if (this.errorReceivedCallback) {
|
170 | this.logger.verbose("Two callbacks were provided to handleRedirectCallback, calling success callback with response");
|
171 | this.tokenReceivedCallback(response);
|
172 | }
|
173 | else if (this.authResponseCallback) {
|
174 | this.logger.verbose("One callback was provided to handleRedirectCallback, calling authResponseCallback with response");
|
175 | this.authResponseCallback(null, response);
|
176 | }
|
177 | }
|
178 | else if (interactionType === Constants.interactionTypePopup) {
|
179 | this.logger.verbose("Interaction type is popup, resolving");
|
180 | resolve(response);
|
181 | }
|
182 | else {
|
183 | throw ClientAuthError.createInvalidInteractionTypeError();
|
184 | }
|
185 | };
|
186 | UserAgentApplication.prototype.authErrorHandler = function (interactionType, authErr, response, reject) {
|
187 | this.logger.verbose("AuthErrorHandler has been called");
|
188 |
|
189 | this.cacheStorage.setInteractionInProgress(false);
|
190 | if (interactionType === Constants.interactionTypeRedirect) {
|
191 | this.logger.verbose("Interaction type is redirect");
|
192 | if (this.errorReceivedCallback) {
|
193 | this.logger.verbose("Two callbacks were provided to handleRedirectCallback, calling error callback");
|
194 | this.errorReceivedCallback(authErr, response.accountState);
|
195 | }
|
196 | else if (this.authResponseCallback) {
|
197 | this.logger.verbose("One callback was provided to handleRedirectCallback, calling authResponseCallback with error");
|
198 | this.authResponseCallback(authErr, response);
|
199 | }
|
200 | else {
|
201 | this.logger.verbose("handleRedirectCallback has not been called and no callbacks are registered, throwing error");
|
202 | throw authErr;
|
203 | }
|
204 | }
|
205 | else if (interactionType === Constants.interactionTypePopup) {
|
206 | this.logger.verbose("Interaction type is popup, rejecting");
|
207 | reject(authErr);
|
208 | }
|
209 | else {
|
210 | throw ClientAuthError.createInvalidInteractionTypeError();
|
211 | }
|
212 | };
|
213 |
|
214 | |
215 |
|
216 |
|
217 |
|
218 | UserAgentApplication.prototype.loginRedirect = function (userRequest) {
|
219 | this.logger.verbose("LoginRedirect has been called");
|
220 |
|
221 | var request = RequestUtils.validateRequest(userRequest, true, this.clientId, Constants.interactionTypeRedirect);
|
222 | this.acquireTokenInteractive(Constants.interactionTypeRedirect, true, request, null, null);
|
223 | };
|
224 | |
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | UserAgentApplication.prototype.acquireTokenRedirect = function (userRequest) {
|
231 | this.logger.verbose("AcquireTokenRedirect has been called");
|
232 |
|
233 | var request = RequestUtils.validateRequest(userRequest, false, this.clientId, Constants.interactionTypeRedirect);
|
234 | this.acquireTokenInteractive(Constants.interactionTypeRedirect, false, request, null, null);
|
235 | };
|
236 | |
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | UserAgentApplication.prototype.loginPopup = function (userRequest) {
|
244 | var _this = this;
|
245 | this.logger.verbose("LoginPopup has been called");
|
246 |
|
247 | var request = RequestUtils.validateRequest(userRequest, true, this.clientId, Constants.interactionTypePopup);
|
248 | var apiEvent = this.telemetryManager.createAndStartApiEvent(request.correlationId, API_EVENT_IDENTIFIER.LoginPopup);
|
249 | return new Promise(function (resolve, reject) {
|
250 | _this.acquireTokenInteractive(Constants.interactionTypePopup, true, request, resolve, reject);
|
251 | })
|
252 | .then(function (resp) {
|
253 | _this.logger.verbose("Successfully logged in");
|
254 | _this.telemetryManager.stopAndFlushApiEvent(request.correlationId, apiEvent, true);
|
255 | return resp;
|
256 | })
|
257 | .catch(function (error) {
|
258 | _this.cacheStorage.resetTempCacheItems(request.state);
|
259 | _this.telemetryManager.stopAndFlushApiEvent(request.correlationId, apiEvent, false, error.errorCode);
|
260 | throw error;
|
261 | });
|
262 | };
|
263 | |
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | UserAgentApplication.prototype.acquireTokenPopup = function (userRequest) {
|
271 | var _this = this;
|
272 | this.logger.verbose("AcquireTokenPopup has been called");
|
273 |
|
274 | var request = RequestUtils.validateRequest(userRequest, false, this.clientId, Constants.interactionTypePopup);
|
275 | var apiEvent = this.telemetryManager.createAndStartApiEvent(request.correlationId, API_EVENT_IDENTIFIER.AcquireTokenPopup);
|
276 | return new Promise(function (resolve, reject) {
|
277 | _this.acquireTokenInteractive(Constants.interactionTypePopup, false, request, resolve, reject);
|
278 | })
|
279 | .then(function (resp) {
|
280 | _this.logger.verbose("Successfully acquired token");
|
281 | _this.telemetryManager.stopAndFlushApiEvent(request.correlationId, apiEvent, true);
|
282 | return resp;
|
283 | })
|
284 | .catch(function (error) {
|
285 | _this.cacheStorage.resetTempCacheItems(request.state);
|
286 | _this.telemetryManager.stopAndFlushApiEvent(request.correlationId, apiEvent, false, error.errorCode);
|
287 | throw error;
|
288 | });
|
289 | };
|
290 |
|
291 | |
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 | UserAgentApplication.prototype.acquireTokenInteractive = function (interactionType, isLoginCall, request, resolve, reject) {
|
299 | var _this = this;
|
300 | this.logger.verbose("AcquireTokenInteractive has been called");
|
301 |
|
302 | WindowUtils.blockReloadInHiddenIframes();
|
303 | try {
|
304 | this.cacheStorage.setInteractionInProgress(true);
|
305 | }
|
306 | catch (e) {
|
307 |
|
308 | var thrownError = isLoginCall ? ClientAuthError.createLoginInProgressError() : ClientAuthError.createAcquireTokenInProgressError();
|
309 | var stateOnlyResponse = buildResponseStateOnly(this.getAccountState(request.state));
|
310 | this.cacheStorage.resetTempCacheItems(request.state);
|
311 | this.authErrorHandler(interactionType, thrownError, stateOnlyResponse, reject);
|
312 | return;
|
313 | }
|
314 | if (interactionType === Constants.interactionTypeRedirect) {
|
315 | this.cacheStorage.setItem(TemporaryCacheKeys.REDIRECT_REQUEST, "" + Constants.inProgress + Constants.resourceDelimiter + request.state);
|
316 | }
|
317 |
|
318 | var account;
|
319 | if (request && request.account && !isLoginCall) {
|
320 | account = request.account;
|
321 | this.logger.verbose("Account set from request");
|
322 | }
|
323 | else {
|
324 | account = this.getAccount();
|
325 | this.logger.verbose("Account set from MSAL Cache");
|
326 | }
|
327 |
|
328 | if (!account && !ServerRequestParameters.isSSOParam(request)) {
|
329 | if (isLoginCall) {
|
330 |
|
331 | var adalIdToken = this.extractADALIdToken();
|
332 |
|
333 | if (adalIdToken && !request.scopes) {
|
334 | this.logger.info("ADAL's idToken exists. Extracting login information from ADAL's idToken");
|
335 | var tokenRequest = this.buildIDTokenRequest(request);
|
336 | this.silentLogin = true;
|
337 | this.acquireTokenSilent(tokenRequest).then(function (response) {
|
338 | _this.silentLogin = false;
|
339 | _this.logger.info("Unified cache call is successful");
|
340 | _this.authResponseHandler(interactionType, response, resolve);
|
341 | return;
|
342 | }, function (error) {
|
343 | _this.silentLogin = false;
|
344 | _this.logger.error("Error occurred during unified cache ATS: " + error);
|
345 |
|
346 | _this.acquireTokenHelper(null, interactionType, isLoginCall, request, resolve, reject);
|
347 | });
|
348 | }
|
349 |
|
350 | else {
|
351 | this.logger.verbose("Login call but no token found, proceed to login");
|
352 | this.acquireTokenHelper(null, interactionType, isLoginCall, request, resolve, reject);
|
353 | }
|
354 | }
|
355 |
|
356 | else {
|
357 | this.logger.verbose("AcquireToken call, no context or account given");
|
358 | this.logger.info("User login is required");
|
359 | var stateOnlyResponse = buildResponseStateOnly(this.getAccountState(request.state));
|
360 | this.cacheStorage.resetTempCacheItems(request.state);
|
361 | this.authErrorHandler(interactionType, ClientAuthError.createUserLoginRequiredError(), stateOnlyResponse, reject);
|
362 | return;
|
363 | }
|
364 | }
|
365 |
|
366 | else {
|
367 | this.logger.verbose("User session exists, login not required");
|
368 | this.acquireTokenHelper(account, interactionType, isLoginCall, request, resolve, reject);
|
369 | }
|
370 | };
|
371 | |
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 | UserAgentApplication.prototype.acquireTokenHelper = function (account, interactionType, isLoginCall, request, resolve, reject) {
|
378 | return __awaiter(this, void 0, void 0, function () {
|
379 | var requestSignature, serverAuthenticationRequest, acquireTokenAuthority, popUpWindow, responseType, loginStartPage, urlNavigate, hash, error_1, navigate, err_1;
|
380 | return __generator(this, function (_a) {
|
381 | switch (_a.label) {
|
382 | case 0:
|
383 | this.logger.verbose("AcquireTokenHelper has been called");
|
384 | this.logger.verbose("Interaction type: " + interactionType + ". isLoginCall: " + isLoginCall);
|
385 | requestSignature = request.scopes ? request.scopes.join(" ").toLowerCase() : Constants.oidcScopes.join(" ");
|
386 | this.logger.verbosePii("Request signature: " + requestSignature);
|
387 | acquireTokenAuthority = (request && request.authority) ? AuthorityFactory.CreateInstance(request.authority, this.config.auth.validateAuthority, request.authorityMetadata) : this.authorityInstance;
|
388 | _a.label = 1;
|
389 | case 1:
|
390 | _a.trys.push([1, 11, , 12]);
|
391 | if (!!acquireTokenAuthority.hasCachedMetadata()) return [3 , 3];
|
392 | this.logger.verbose("No cached metadata for authority");
|
393 | return [4 , AuthorityFactory.saveMetadataFromNetwork(acquireTokenAuthority, this.telemetryManager, request.correlationId)];
|
394 | case 2:
|
395 | _a.sent();
|
396 | return [3 , 4];
|
397 | case 3:
|
398 | this.logger.verbose("Cached metadata found for authority");
|
399 | _a.label = 4;
|
400 | case 4:
|
401 | responseType = isLoginCall ? ResponseTypes.id_token : this.getTokenType(account, request.scopes);
|
402 | loginStartPage = request.redirectStartPage || window.location.href;
|
403 | serverAuthenticationRequest = new ServerRequestParameters(acquireTokenAuthority, this.clientId, responseType, this.getRedirectUri(request && request.redirectUri), request.scopes, request.state, request.correlationId);
|
404 | this.logger.verbose("Finished building server authentication request");
|
405 | this.updateCacheEntries(serverAuthenticationRequest, account, isLoginCall, loginStartPage);
|
406 | this.logger.verbose("Updating cache entries");
|
407 |
|
408 | serverAuthenticationRequest.populateQueryParams(account, request);
|
409 | this.logger.verbose("Query parameters populated from account");
|
410 | urlNavigate = UrlUtils.createNavigateUrl(serverAuthenticationRequest) + Constants.response_mode_fragment;
|
411 |
|
412 | if (interactionType === Constants.interactionTypeRedirect) {
|
413 | if (!isLoginCall) {
|
414 | this.cacheStorage.setItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.STATE_ACQ_TOKEN, request.state), serverAuthenticationRequest.state, this.inCookie);
|
415 | this.logger.verbose("State cached for redirect");
|
416 | this.logger.verbosePii("State cached: " + serverAuthenticationRequest.state);
|
417 | }
|
418 | else {
|
419 | this.logger.verbose("Interaction type redirect but login call is true. State not cached");
|
420 | }
|
421 | }
|
422 | else if (interactionType === Constants.interactionTypePopup) {
|
423 | window.renewStates.push(serverAuthenticationRequest.state);
|
424 | window.requestType = isLoginCall ? Constants.login : Constants.renewToken;
|
425 | this.logger.verbose("State saved to window");
|
426 | this.logger.verbosePii("State saved: " + serverAuthenticationRequest.state);
|
427 |
|
428 | this.registerCallback(serverAuthenticationRequest.state, requestSignature, resolve, reject);
|
429 | }
|
430 | else {
|
431 | this.logger.verbose("Invalid interaction error. State not cached");
|
432 | throw ClientAuthError.createInvalidInteractionTypeError();
|
433 | }
|
434 | if (!(interactionType === Constants.interactionTypePopup)) return [3 , 9];
|
435 | this.logger.verbose("Interaction type is popup. Generating popup window");
|
436 |
|
437 | try {
|
438 | popUpWindow = this.openPopup(urlNavigate, "msal", Constants.popUpWidth, Constants.popUpHeight);
|
439 |
|
440 | WindowUtils.trackPopup(popUpWindow);
|
441 | }
|
442 | catch (e) {
|
443 | this.logger.info(ClientAuthErrorMessage.popUpWindowError.code + ":" + ClientAuthErrorMessage.popUpWindowError.desc);
|
444 | this.cacheStorage.setItem(ErrorCacheKeys.ERROR, ClientAuthErrorMessage.popUpWindowError.code);
|
445 | this.cacheStorage.setItem(ErrorCacheKeys.ERROR_DESC, ClientAuthErrorMessage.popUpWindowError.desc);
|
446 | if (reject) {
|
447 | reject(ClientAuthError.createPopupWindowError());
|
448 | return [2 ];
|
449 | }
|
450 | }
|
451 | if (!popUpWindow) return [3 , 8];
|
452 | _a.label = 5;
|
453 | case 5:
|
454 | _a.trys.push([5, 7, , 8]);
|
455 | return [4 , WindowUtils.monitorPopupForHash(popUpWindow, this.config.system.loadFrameTimeout, urlNavigate, this.logger)];
|
456 | case 6:
|
457 | hash = _a.sent();
|
458 | this.handleAuthenticationResponse(hash);
|
459 |
|
460 | this.cacheStorage.setInteractionInProgress(false);
|
461 | this.logger.info("Closing popup window");
|
462 |
|
463 | if (this.config.framework.isAngular) {
|
464 | this.broadcast("msal:popUpHashChanged", hash);
|
465 | }
|
466 | WindowUtils.closePopups();
|
467 | return [3 , 8];
|
468 | case 7:
|
469 | error_1 = _a.sent();
|
470 | if (reject) {
|
471 | reject(error_1);
|
472 | }
|
473 | if (this.config.framework.isAngular) {
|
474 | this.broadcast("msal:popUpClosed", error_1.errorCode + Constants.resourceDelimiter + error_1.errorMessage);
|
475 | }
|
476 | else {
|
477 |
|
478 | this.cacheStorage.setInteractionInProgress(false);
|
479 | popUpWindow.close();
|
480 | }
|
481 | return [3 , 8];
|
482 | case 8: return [3 , 10];
|
483 | case 9:
|
484 |
|
485 | if (request.onRedirectNavigate) {
|
486 | this.logger.verbose("Invoking onRedirectNavigate callback");
|
487 | navigate = request.onRedirectNavigate(urlNavigate);
|
488 |
|
489 | if (navigate !== false) {
|
490 | this.logger.verbose("onRedirectNavigate did not return false, navigating");
|
491 | this.navigateWindow(urlNavigate);
|
492 | }
|
493 | else {
|
494 | this.logger.verbose("onRedirectNavigate returned false, stopping navigation");
|
495 | }
|
496 | }
|
497 | else {
|
498 |
|
499 | this.logger.verbose("Navigating window to urlNavigate");
|
500 | this.navigateWindow(urlNavigate);
|
501 | }
|
502 | _a.label = 10;
|
503 | case 10: return [3 , 12];
|
504 | case 11:
|
505 | err_1 = _a.sent();
|
506 | this.logger.error(err_1);
|
507 | this.cacheStorage.resetTempCacheItems(request.state);
|
508 | this.authErrorHandler(interactionType, ClientAuthError.createEndpointResolutionError(err_1.toString), buildResponseStateOnly(request.state), reject);
|
509 | if (popUpWindow) {
|
510 | popUpWindow.close();
|
511 | }
|
512 | return [3 , 12];
|
513 | case 12: return [2 ];
|
514 | }
|
515 | });
|
516 | });
|
517 | };
|
518 | |
519 |
|
520 |
|
521 |
|
522 | UserAgentApplication.prototype.ssoSilent = function (request) {
|
523 | this.logger.verbose("ssoSilent has been called");
|
524 |
|
525 | if (!request) {
|
526 | throw ClientConfigurationError.createEmptyRequestError();
|
527 | }
|
528 |
|
529 | if (!request.sid && !request.loginHint) {
|
530 | throw ClientConfigurationError.createSsoSilentError();
|
531 | }
|
532 | return this.acquireTokenSilent(__assign(__assign({}, request), { scopes: Constants.oidcScopes }));
|
533 | };
|
534 | |
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 | UserAgentApplication.prototype.acquireTokenSilent = function (userRequest) {
|
547 | var _this = this;
|
548 | this.logger.verbose("AcquireTokenSilent has been called");
|
549 |
|
550 | var request = RequestUtils.validateRequest(userRequest, false, this.clientId, Constants.interactionTypeSilent);
|
551 | var apiEvent = this.telemetryManager.createAndStartApiEvent(request.correlationId, API_EVENT_IDENTIFIER.AcquireTokenSilent);
|
552 | var requestSignature = RequestUtils.createRequestSignature(request);
|
553 | return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
554 | var scope, account, adalIdToken, responseType, serverAuthenticationRequest, adalIdTokenObject, userContainedClaims, authErr, cacheResultResponse, logMessage, err_2;
|
555 | return __generator(this, function (_a) {
|
556 | switch (_a.label) {
|
557 | case 0:
|
558 |
|
559 | WindowUtils.blockReloadInHiddenIframes();
|
560 | scope = request.scopes.join(" ").toLowerCase();
|
561 | this.logger.verbosePii("Serialized scopes: " + scope);
|
562 | if (request.account) {
|
563 | account = request.account;
|
564 | this.logger.verbose("Account set from request");
|
565 | }
|
566 | else {
|
567 | account = this.getAccount();
|
568 | this.logger.verbose("Account set from MSAL Cache");
|
569 | }
|
570 | adalIdToken = this.cacheStorage.getItem(Constants.adalIdToken);
|
571 |
|
572 | if (!account && !(request.sid || request.loginHint) && StringUtils.isEmpty(adalIdToken)) {
|
573 | this.logger.info("User login is required");
|
574 |
|
575 | return [2 , reject(ClientAuthError.createUserLoginRequiredError())];
|
576 | }
|
577 | responseType = this.getTokenType(account, request.scopes);
|
578 | this.logger.verbose("Response type: " + responseType);
|
579 | serverAuthenticationRequest = new ServerRequestParameters(AuthorityFactory.CreateInstance(request.authority, this.config.auth.validateAuthority, request.authorityMetadata), this.clientId, responseType, this.getRedirectUri(request.redirectUri), request.scopes, request.state, request.correlationId);
|
580 | this.logger.verbose("Finished building server authentication request");
|
581 |
|
582 | if (ServerRequestParameters.isSSOParam(request) || account) {
|
583 | serverAuthenticationRequest.populateQueryParams(account, request, null, true);
|
584 | this.logger.verbose("Query parameters populated from existing SSO or account");
|
585 | }
|
586 |
|
587 | else if (!account && !StringUtils.isEmpty(adalIdToken)) {
|
588 | adalIdTokenObject = TokenUtils.extractIdToken(adalIdToken);
|
589 | this.logger.verbose("ADAL's idToken exists. Extracting login information from ADAL's idToken to populate query parameters");
|
590 | serverAuthenticationRequest.populateQueryParams(account, null, adalIdTokenObject, true);
|
591 | }
|
592 | else {
|
593 | this.logger.verbose("No additional query parameters added");
|
594 | }
|
595 | userContainedClaims = request.claimsRequest || serverAuthenticationRequest.claimsValue;
|
596 |
|
597 | if (!userContainedClaims && !request.forceRefresh) {
|
598 | try {
|
599 | cacheResultResponse = this.getCachedToken(serverAuthenticationRequest, account);
|
600 | }
|
601 | catch (e) {
|
602 | authErr = e;
|
603 | }
|
604 | }
|
605 | if (!cacheResultResponse) return [3 , 1];
|
606 | this.logger.verbose("Token found in cache lookup");
|
607 | this.logger.verbosePii("Scopes found: " + JSON.stringify(cacheResultResponse.scopes));
|
608 | resolve(cacheResultResponse);
|
609 | return [2 , null];
|
610 | case 1:
|
611 | if (!authErr) return [3 , 2];
|
612 | this.logger.infoPii(authErr.errorCode + ":" + authErr.errorMessage);
|
613 | reject(authErr);
|
614 | return [2 , null];
|
615 | case 2:
|
616 | logMessage = void 0;
|
617 | if (userContainedClaims) {
|
618 | logMessage = "Skipped cache lookup since claims were given";
|
619 | }
|
620 | else if (request.forceRefresh) {
|
621 | logMessage = "Skipped cache lookup since request.forceRefresh option was set to true";
|
622 | }
|
623 | else {
|
624 | logMessage = "No valid token found in cache lookup";
|
625 | }
|
626 | this.logger.verbose(logMessage);
|
627 |
|
628 | if (!serverAuthenticationRequest.authorityInstance) {
|
629 | serverAuthenticationRequest.authorityInstance = request.authority ?
|
630 | AuthorityFactory.CreateInstance(request.authority, this.config.auth.validateAuthority, request.authorityMetadata)
|
631 | : this.authorityInstance;
|
632 | }
|
633 | this.logger.verbosePii("Authority instance: " + serverAuthenticationRequest.authority);
|
634 | _a.label = 3;
|
635 | case 3:
|
636 | _a.trys.push([3, 7, , 8]);
|
637 | if (!!serverAuthenticationRequest.authorityInstance.hasCachedMetadata()) return [3 , 5];
|
638 | this.logger.verbose("No cached metadata for authority");
|
639 | return [4 , AuthorityFactory.saveMetadataFromNetwork(serverAuthenticationRequest.authorityInstance, this.telemetryManager, request.correlationId)];
|
640 | case 4:
|
641 | _a.sent();
|
642 | this.logger.verbose("Authority has been updated with endpoint discovery response");
|
643 | return [3 , 6];
|
644 | case 5:
|
645 | this.logger.verbose("Cached metadata found for authority");
|
646 | _a.label = 6;
|
647 | case 6:
|
648 | |
649 |
|
650 |
|
651 |
|
652 | if (window.activeRenewals[requestSignature]) {
|
653 | this.logger.verbose("Renewing token in progress. Registering callback");
|
654 |
|
655 | this.registerCallback(window.activeRenewals[requestSignature], requestSignature, resolve, reject);
|
656 | }
|
657 | else {
|
658 | if (request.scopes && ScopeSet.onlyContainsOidcScopes(request.scopes)) {
|
659 | |
660 |
|
661 |
|
662 |
|
663 | this.logger.verbose("OpenID Connect scopes only, renewing idToken");
|
664 | this.silentLogin = true;
|
665 | this.renewIdToken(requestSignature, resolve, reject, account, serverAuthenticationRequest);
|
666 | }
|
667 | else {
|
668 |
|
669 | this.logger.verbose("Renewing access token");
|
670 | this.renewToken(requestSignature, resolve, reject, account, serverAuthenticationRequest);
|
671 | }
|
672 | }
|
673 | return [3 , 8];
|
674 | case 7:
|
675 | err_2 = _a.sent();
|
676 | this.logger.error(err_2);
|
677 | reject(ClientAuthError.createEndpointResolutionError(err_2.toString()));
|
678 | return [2 , null];
|
679 | case 8: return [2 ];
|
680 | }
|
681 | });
|
682 | }); })
|
683 | .then(function (res) {
|
684 | _this.logger.verbose("Successfully acquired token");
|
685 | _this.telemetryManager.stopAndFlushApiEvent(request.correlationId, apiEvent, true);
|
686 | return res;
|
687 | })
|
688 | .catch(function (error) {
|
689 | _this.cacheStorage.resetTempCacheItems(request.state);
|
690 | _this.telemetryManager.stopAndFlushApiEvent(request.correlationId, apiEvent, false, error.errorCode);
|
691 | throw error;
|
692 | });
|
693 | };
|
694 |
|
695 |
|
696 | |
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 | UserAgentApplication.prototype.openPopup = function (urlNavigate, title, popUpWidth, popUpHeight) {
|
709 | this.logger.verbose("OpenPopup has been called");
|
710 | try {
|
711 | |
712 |
|
713 |
|
714 |
|
715 | var winLeft = window.screenLeft ? window.screenLeft : window.screenX;
|
716 | var winTop = window.screenTop ? window.screenTop : window.screenY;
|
717 | |
718 |
|
719 |
|
720 |
|
721 | var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
722 | var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
723 | var left = ((width / 2) - (popUpWidth / 2)) + winLeft;
|
724 | var top_1 = ((height / 2) - (popUpHeight / 2)) + winTop;
|
725 |
|
726 | var popupWindow = window.open(urlNavigate, title, "width=" + popUpWidth + ", height=" + popUpHeight + ", top=" + top_1 + ", left=" + left + ", scrollbars=yes");
|
727 | if (!popupWindow) {
|
728 | throw ClientAuthError.createPopupWindowError();
|
729 | }
|
730 | if (popupWindow.focus) {
|
731 | popupWindow.focus();
|
732 | }
|
733 | return popupWindow;
|
734 | }
|
735 | catch (e) {
|
736 | this.cacheStorage.setInteractionInProgress(false);
|
737 | throw ClientAuthError.createPopupWindowError(e.toString());
|
738 | }
|
739 | };
|
740 |
|
741 |
|
742 | |
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 | UserAgentApplication.prototype.loadIframeTimeout = function (urlNavigate, frameName, requestSignature) {
|
749 | return __awaiter(this, void 0, void 0, function () {
|
750 | var expectedState, iframe, _a, hash, error_2;
|
751 | return __generator(this, function (_b) {
|
752 | switch (_b.label) {
|
753 | case 0:
|
754 | expectedState = window.activeRenewals[requestSignature];
|
755 | this.logger.verbosePii("Set loading state to pending for: " + requestSignature + ":" + expectedState);
|
756 | this.cacheStorage.setItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.RENEW_STATUS, expectedState), Constants.inProgress);
|
757 | if (!this.config.system.navigateFrameWait) return [3 , 2];
|
758 | return [4 , WindowUtils.loadFrame(urlNavigate, frameName, this.config.system.navigateFrameWait, this.logger)];
|
759 | case 1:
|
760 | _a = _b.sent();
|
761 | return [3 , 3];
|
762 | case 2:
|
763 | _a = WindowUtils.loadFrameSync(urlNavigate, frameName, this.logger);
|
764 | _b.label = 3;
|
765 | case 3:
|
766 | iframe = _a;
|
767 | _b.label = 4;
|
768 | case 4:
|
769 | _b.trys.push([4, 6, , 7]);
|
770 | return [4 , WindowUtils.monitorIframeForHash(iframe.contentWindow, this.config.system.loadFrameTimeout, urlNavigate, this.logger)];
|
771 | case 5:
|
772 | hash = _b.sent();
|
773 | if (hash) {
|
774 | this.handleAuthenticationResponse(hash);
|
775 | }
|
776 | return [3 , 7];
|
777 | case 6:
|
778 | error_2 = _b.sent();
|
779 | if (this.cacheStorage.getItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.RENEW_STATUS, expectedState)) === Constants.inProgress) {
|
780 |
|
781 | this.logger.verbose("Loading frame has timed out after: " + (this.config.system.loadFrameTimeout / 1000) + " seconds for scope/authority " + requestSignature + ":" + expectedState);
|
782 |
|
783 | if (expectedState && window.callbackMappedToRenewStates[expectedState]) {
|
784 | window.callbackMappedToRenewStates[expectedState](null, error_2);
|
785 | }
|
786 | this.cacheStorage.removeItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.RENEW_STATUS, expectedState));
|
787 | }
|
788 | WindowUtils.removeHiddenIframe(iframe);
|
789 | throw error_2;
|
790 | case 7:
|
791 | WindowUtils.removeHiddenIframe(iframe);
|
792 | return [2 ];
|
793 | }
|
794 | });
|
795 | });
|
796 | };
|
797 |
|
798 |
|
799 | |
800 |
|
801 |
|
802 |
|
803 |
|
804 | UserAgentApplication.prototype.navigateWindow = function (urlNavigate, popupWindow) {
|
805 |
|
806 | if (urlNavigate && !StringUtils.isEmpty(urlNavigate)) {
|
807 | var navigateWindow = popupWindow ? popupWindow : window;
|
808 | var logMessage = popupWindow ? "Navigated Popup window to:" + urlNavigate : "Navigate to:" + urlNavigate;
|
809 | this.logger.infoPii(logMessage);
|
810 | navigateWindow.location.assign(urlNavigate);
|
811 | }
|
812 | else {
|
813 | this.logger.info("Navigate url is empty");
|
814 | throw AuthError.createUnexpectedError("Navigate url is empty");
|
815 | }
|
816 | };
|
817 | |
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 | UserAgentApplication.prototype.registerCallback = function (expectedState, requestSignature, resolve, reject) {
|
827 | var _this = this;
|
828 |
|
829 | window.activeRenewals[requestSignature] = expectedState;
|
830 |
|
831 | if (!window.promiseMappedToRenewStates[expectedState]) {
|
832 | window.promiseMappedToRenewStates[expectedState] = [];
|
833 | }
|
834 |
|
835 | window.promiseMappedToRenewStates[expectedState].push({ resolve: resolve, reject: reject });
|
836 |
|
837 | if (!window.callbackMappedToRenewStates[expectedState]) {
|
838 | window.callbackMappedToRenewStates[expectedState] = function (response, error) {
|
839 |
|
840 | delete window.activeRenewals[requestSignature];
|
841 |
|
842 | for (var i = 0; i < window.promiseMappedToRenewStates[expectedState].length; ++i) {
|
843 | try {
|
844 | if (error) {
|
845 | window.promiseMappedToRenewStates[expectedState][i].reject(error);
|
846 | }
|
847 | else if (response) {
|
848 | window.promiseMappedToRenewStates[expectedState][i].resolve(response);
|
849 | }
|
850 | else {
|
851 | _this.cacheStorage.resetTempCacheItems(expectedState);
|
852 | throw AuthError.createUnexpectedError("Error and response are both null");
|
853 | }
|
854 | }
|
855 | catch (e) {
|
856 | _this.logger.warning(e);
|
857 | }
|
858 | }
|
859 |
|
860 | delete window.promiseMappedToRenewStates[expectedState];
|
861 | delete window.callbackMappedToRenewStates[expectedState];
|
862 | };
|
863 | }
|
864 | };
|
865 |
|
866 |
|
867 | |
868 |
|
869 |
|
870 |
|
871 | UserAgentApplication.prototype.logout = function (correlationId) {
|
872 | this.logger.verbose("Logout has been called");
|
873 | this.logoutAsync(correlationId);
|
874 | };
|
875 | |
876 |
|
877 |
|
878 |
|
879 | UserAgentApplication.prototype.logoutAsync = function (correlationId) {
|
880 | return __awaiter(this, void 0, void 0, function () {
|
881 | var requestCorrelationId, apiEvent, correlationIdParam, postLogoutQueryParam, urlNavigate, error_3;
|
882 | return __generator(this, function (_a) {
|
883 | switch (_a.label) {
|
884 | case 0:
|
885 | requestCorrelationId = correlationId || CryptoUtils.createNewGuid();
|
886 | apiEvent = this.telemetryManager.createAndStartApiEvent(requestCorrelationId, API_EVENT_IDENTIFIER.Logout);
|
887 | this.clearCache();
|
888 | this.account = null;
|
889 | _a.label = 1;
|
890 | case 1:
|
891 | _a.trys.push([1, 5, , 6]);
|
892 | if (!!this.authorityInstance.hasCachedMetadata()) return [3 , 3];
|
893 | this.logger.verbose("No cached metadata for authority");
|
894 | return [4 , AuthorityFactory.saveMetadataFromNetwork(this.authorityInstance, this.telemetryManager, correlationId)];
|
895 | case 2:
|
896 | _a.sent();
|
897 | return [3 , 4];
|
898 | case 3:
|
899 | this.logger.verbose("Cached metadata found for authority");
|
900 | _a.label = 4;
|
901 | case 4:
|
902 | correlationIdParam = "client-request-id=" + requestCorrelationId;
|
903 | postLogoutQueryParam = void 0;
|
904 | if (this.getPostLogoutRedirectUri()) {
|
905 | postLogoutQueryParam = "&post_logout_redirect_uri=" + encodeURIComponent(this.getPostLogoutRedirectUri());
|
906 | this.logger.verbose("redirectUri found and set");
|
907 | }
|
908 | else {
|
909 | postLogoutQueryParam = "";
|
910 | this.logger.verbose("No redirectUri set for app. postLogoutQueryParam is empty");
|
911 | }
|
912 | urlNavigate = void 0;
|
913 | if (this.authorityInstance.EndSessionEndpoint) {
|
914 | urlNavigate = this.authorityInstance.EndSessionEndpoint + "?" + correlationIdParam + postLogoutQueryParam;
|
915 | this.logger.verbose("EndSessionEndpoint found and urlNavigate set");
|
916 | this.logger.verbosePii("urlNavigate set to: " + this.authorityInstance.EndSessionEndpoint);
|
917 | }
|
918 | else {
|
919 | urlNavigate = this.authority + "oauth2/v2.0/logout?" + correlationIdParam + postLogoutQueryParam;
|
920 | this.logger.verbose("No endpoint, urlNavigate set to default");
|
921 | }
|
922 | this.telemetryManager.stopAndFlushApiEvent(requestCorrelationId, apiEvent, true);
|
923 | this.logger.verbose("Navigating window to urlNavigate");
|
924 | this.navigateWindow(urlNavigate);
|
925 | return [3 , 6];
|
926 | case 5:
|
927 | error_3 = _a.sent();
|
928 | this.telemetryManager.stopAndFlushApiEvent(requestCorrelationId, apiEvent, false, error_3.errorCode);
|
929 | return [3 , 6];
|
930 | case 6: return [2 ];
|
931 | }
|
932 | });
|
933 | });
|
934 | };
|
935 | |
936 |
|
937 |
|
938 |
|
939 |
|
940 | UserAgentApplication.prototype.clearCache = function () {
|
941 | this.logger.verbose("Clearing cache");
|
942 | window.renewStates = [];
|
943 | var tokenCacheItems = this.cacheStorage.getAllTokens(Constants.clientId, Constants.homeAccountIdentifier);
|
944 | for (var i = 0; i < tokenCacheItems.length; i++) {
|
945 | this.cacheStorage.removeItem(JSON.stringify(tokenCacheItems[i].key));
|
946 | }
|
947 | this.cacheStorage.resetCacheItems();
|
948 | this.cacheStorage.clearMsalCookie();
|
949 | this.logger.verbose("Cache cleared");
|
950 | };
|
951 | |
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 | UserAgentApplication.prototype.clearCacheForScope = function (accessToken) {
|
958 | this.logger.verbose("Clearing access token from cache");
|
959 | var accessTokenItems = this.cacheStorage.getAllAccessTokens(Constants.clientId, Constants.homeAccountIdentifier);
|
960 | for (var i = 0; i < accessTokenItems.length; i++) {
|
961 | var token = accessTokenItems[i];
|
962 | if (token.value.accessToken === accessToken) {
|
963 | this.cacheStorage.removeItem(JSON.stringify(token.key));
|
964 | this.logger.verbosePii("Access token removed: " + token.key);
|
965 | }
|
966 | }
|
967 | };
|
968 |
|
969 |
|
970 | |
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 | UserAgentApplication.prototype.isCallback = function (hash) {
|
978 | this.logger.info("isCallback will be deprecated in favor of urlContainsHash in MSAL.js v2.0.");
|
979 | this.logger.verbose("isCallback has been called");
|
980 | return UrlUtils.urlContainsHash(hash);
|
981 | };
|
982 | |
983 |
|
984 |
|
985 |
|
986 |
|
987 | UserAgentApplication.prototype.processCallBack = function (hash, respStateInfo, parentCallback) {
|
988 | this.logger.info("ProcessCallBack has been called. Processing callback from redirect response");
|
989 |
|
990 | var stateInfo = respStateInfo;
|
991 | if (!stateInfo) {
|
992 | this.logger.verbose("StateInfo is null, getting stateInfo from hash");
|
993 | stateInfo = this.getResponseState(hash);
|
994 | }
|
995 | var response;
|
996 | var authErr;
|
997 |
|
998 | try {
|
999 | response = this.saveTokenFromHash(hash, stateInfo);
|
1000 | }
|
1001 | catch (err) {
|
1002 | authErr = err;
|
1003 | }
|
1004 | try {
|
1005 |
|
1006 | this.cacheStorage.clearMsalCookie(stateInfo.state);
|
1007 | var accountState = this.getAccountState(stateInfo.state);
|
1008 | if (response) {
|
1009 | if ((stateInfo.requestType === Constants.renewToken) || response.accessToken) {
|
1010 | if (window.parent !== window) {
|
1011 | this.logger.verbose("Window is in iframe, acquiring token silently");
|
1012 | }
|
1013 | else {
|
1014 | this.logger.verbose("Acquiring token interactive in progress");
|
1015 | }
|
1016 | this.logger.verbose("Response tokenType set to " + ServerHashParamKeys.ACCESS_TOKEN);
|
1017 | response.tokenType = ServerHashParamKeys.ACCESS_TOKEN;
|
1018 | }
|
1019 | else if (stateInfo.requestType === Constants.login) {
|
1020 | this.logger.verbose("Response tokenType set to " + ServerHashParamKeys.ID_TOKEN);
|
1021 | response.tokenType = ServerHashParamKeys.ID_TOKEN;
|
1022 | }
|
1023 | if (!parentCallback) {
|
1024 | this.logger.verbose("Setting redirectResponse");
|
1025 | this.redirectResponse = response;
|
1026 | return;
|
1027 | }
|
1028 | }
|
1029 | else if (!parentCallback) {
|
1030 | this.logger.verbose("Response is null, setting redirectResponse with state");
|
1031 | this.redirectResponse = buildResponseStateOnly(accountState);
|
1032 | this.redirectError = authErr;
|
1033 | this.cacheStorage.resetTempCacheItems(stateInfo.state);
|
1034 | return;
|
1035 | }
|
1036 | this.logger.verbose("Calling callback provided to processCallback");
|
1037 | parentCallback(response, authErr);
|
1038 | }
|
1039 | catch (err) {
|
1040 | this.logger.error("Error occurred in token received callback function: " + err);
|
1041 | throw ClientAuthError.createErrorInCallbackFunction(err.toString());
|
1042 | }
|
1043 | };
|
1044 | |
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 | UserAgentApplication.prototype.handleAuthenticationResponse = function (hash) {
|
1051 | this.logger.verbose("HandleAuthenticationResponse has been called");
|
1052 |
|
1053 | var locationHash = hash || window.location.hash;
|
1054 |
|
1055 | var stateInfo = this.getResponseState(locationHash);
|
1056 | this.logger.verbose("Obtained state from response");
|
1057 | var tokenResponseCallback = window.callbackMappedToRenewStates[stateInfo.state];
|
1058 | this.processCallBack(locationHash, stateInfo, tokenResponseCallback);
|
1059 | };
|
1060 | |
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 | UserAgentApplication.prototype.handleRedirectAuthenticationResponse = function (hash) {
|
1067 | this.logger.info("Returned from redirect url");
|
1068 | this.logger.verbose("HandleRedirectAuthenticationResponse has been called");
|
1069 |
|
1070 | WindowUtils.clearUrlFragment(window);
|
1071 | this.logger.verbose("Window.location.hash cleared");
|
1072 |
|
1073 | var stateInfo = this.getResponseState(hash);
|
1074 |
|
1075 | if (this.config.auth.navigateToLoginRequestUrl && window.parent === window) {
|
1076 | this.logger.verbose("Window.parent is equal to window, not in popup or iframe. Navigation to login request url after login turned on");
|
1077 | var loginRequestUrl = this.cacheStorage.getItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.LOGIN_REQUEST, stateInfo.state), this.inCookie);
|
1078 |
|
1079 | if (!loginRequestUrl || loginRequestUrl === "null") {
|
1080 | this.logger.error("Unable to get valid login request url from cache, redirecting to home page");
|
1081 | window.location.assign("/");
|
1082 | return;
|
1083 | }
|
1084 | else {
|
1085 | this.logger.verbose("Valid login request url obtained from cache");
|
1086 | var currentUrl = UrlUtils.removeHashFromUrl(window.location.href);
|
1087 | var finalRedirectUrl = UrlUtils.removeHashFromUrl(loginRequestUrl);
|
1088 | if (currentUrl !== finalRedirectUrl) {
|
1089 | this.logger.verbose("Current url is not login request url, navigating");
|
1090 | this.logger.verbosePii("CurrentUrl: " + currentUrl + ", finalRedirectUrl: " + finalRedirectUrl);
|
1091 | window.location.assign("" + finalRedirectUrl + hash);
|
1092 | return;
|
1093 | }
|
1094 | else {
|
1095 | this.logger.verbose("Current url matches login request url");
|
1096 | var loginRequestUrlComponents = UrlUtils.GetUrlComponents(loginRequestUrl);
|
1097 | if (loginRequestUrlComponents.Hash) {
|
1098 | this.logger.verbose("Login request url contains hash, resetting non-msal hash");
|
1099 | window.location.hash = loginRequestUrlComponents.Hash;
|
1100 | }
|
1101 | }
|
1102 | }
|
1103 | }
|
1104 | else if (!this.config.auth.navigateToLoginRequestUrl) {
|
1105 | this.logger.verbose("Default navigation to start page after login turned off");
|
1106 | }
|
1107 | this.processCallBack(hash, stateInfo, null);
|
1108 | };
|
1109 | |
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 | UserAgentApplication.prototype.getResponseState = function (hash) {
|
1117 | this.logger.verbose("GetResponseState has been called");
|
1118 | var parameters = UrlUtils.deserializeHash(hash);
|
1119 | var stateResponse;
|
1120 | if (!parameters) {
|
1121 | throw AuthError.createUnexpectedError("Hash was not parsed correctly.");
|
1122 | }
|
1123 | if (parameters.hasOwnProperty(ServerHashParamKeys.STATE)) {
|
1124 | this.logger.verbose("Hash contains state. Creating stateInfo object");
|
1125 | var parsedState = RequestUtils.parseLibraryState(parameters["state"]);
|
1126 | stateResponse = {
|
1127 | requestType: Constants.unknown,
|
1128 | state: parameters["state"],
|
1129 | timestamp: parsedState.ts,
|
1130 | method: parsedState.method,
|
1131 | stateMatch: false
|
1132 | };
|
1133 | }
|
1134 | else {
|
1135 | throw AuthError.createUnexpectedError("Hash does not contain state.");
|
1136 | }
|
1137 | |
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 | if (stateResponse.state === this.cacheStorage.getItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.STATE_LOGIN, stateResponse.state), this.inCookie) || stateResponse.state === this.silentAuthenticationState) {
|
1143 | this.logger.verbose("State matches cached state, setting requestType to login");
|
1144 | stateResponse.requestType = Constants.login;
|
1145 | stateResponse.stateMatch = true;
|
1146 | return stateResponse;
|
1147 | }
|
1148 |
|
1149 | else if (stateResponse.state === this.cacheStorage.getItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.STATE_ACQ_TOKEN, stateResponse.state), this.inCookie)) {
|
1150 | this.logger.verbose("State matches cached state, setting requestType to renewToken");
|
1151 | stateResponse.requestType = Constants.renewToken;
|
1152 | stateResponse.stateMatch = true;
|
1153 | return stateResponse;
|
1154 | }
|
1155 |
|
1156 | if (!stateResponse.stateMatch) {
|
1157 | this.logger.verbose("State does not match cached state, setting requestType to type from window");
|
1158 | stateResponse.requestType = window.requestType;
|
1159 | var statesInParentContext = window.renewStates;
|
1160 | for (var i = 0; i < statesInParentContext.length; i++) {
|
1161 | if (statesInParentContext[i] === stateResponse.state) {
|
1162 | this.logger.verbose("Matching state found for request");
|
1163 | stateResponse.stateMatch = true;
|
1164 | break;
|
1165 | }
|
1166 | }
|
1167 | if (!stateResponse.stateMatch) {
|
1168 | this.logger.verbose("Matching state not found for request");
|
1169 | }
|
1170 | }
|
1171 | return stateResponse;
|
1172 | };
|
1173 |
|
1174 |
|
1175 | |
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 | UserAgentApplication.prototype.getCachedToken = function (serverAuthenticationRequest, account) {
|
1182 | this.logger.verbose("GetCachedToken has been called");
|
1183 | var scopes = serverAuthenticationRequest.scopes;
|
1184 | |
1185 |
|
1186 |
|
1187 |
|
1188 | var idToken = this.getCachedIdToken(serverAuthenticationRequest, account);
|
1189 | var authResponse = this.getCachedAccessToken(serverAuthenticationRequest, account, scopes);
|
1190 | var accountState = this.getAccountState(serverAuthenticationRequest.state);
|
1191 | return ResponseUtils.buildAuthResponse(idToken, authResponse, serverAuthenticationRequest, account, scopes, accountState);
|
1192 | };
|
1193 | |
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 | UserAgentApplication.prototype.getTokenCacheItemByAuthority = function (authority, tokenCacheItems, requestScopes, tokenType) {
|
1206 | var _this = this;
|
1207 | var filteredAuthorityItems;
|
1208 | if (UrlUtils.isCommonAuthority(authority) || UrlUtils.isOrganizationsAuthority(authority) || UrlUtils.isConsumersAuthority(authority)) {
|
1209 | filteredAuthorityItems = AuthCacheUtils.filterTokenCacheItemsByDomain(tokenCacheItems, UrlUtils.GetUrlComponents(authority).HostNameAndPort);
|
1210 | }
|
1211 | else {
|
1212 | filteredAuthorityItems = AuthCacheUtils.filterTokenCacheItemsByAuthority(tokenCacheItems, authority);
|
1213 | }
|
1214 | if (filteredAuthorityItems.length === 1) {
|
1215 | return filteredAuthorityItems[0];
|
1216 | }
|
1217 | else if (filteredAuthorityItems.length > 1) {
|
1218 | this.logger.warning("Multiple matching tokens found. Cleaning cache and requesting a new token.");
|
1219 | filteredAuthorityItems.forEach(function (accessTokenCacheItem) {
|
1220 | _this.cacheStorage.removeItem(JSON.stringify(accessTokenCacheItem.key));
|
1221 | });
|
1222 | return null;
|
1223 | }
|
1224 | else {
|
1225 | this.logger.verbose("No matching tokens of type " + tokenType + " found");
|
1226 | return null;
|
1227 | }
|
1228 | };
|
1229 | |
1230 |
|
1231 |
|
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 | UserAgentApplication.prototype.getCachedIdToken = function (serverAuthenticationRequest, account) {
|
1239 | this.logger.verbose("Getting all cached tokens of type ID Token");
|
1240 | var idTokenCacheItems = this.cacheStorage.getAllIdTokens(this.clientId, account ? account.homeAccountIdentifier : null);
|
1241 | var matchAuthority = serverAuthenticationRequest.authority || this.authority;
|
1242 | var idTokenCacheItem = this.getTokenCacheItemByAuthority(matchAuthority, idTokenCacheItems, null, ServerHashParamKeys.ID_TOKEN);
|
1243 | if (idTokenCacheItem) {
|
1244 | this.logger.verbose("Evaluating ID token found");
|
1245 | var idTokenIsStillValid = this.evaluateTokenExpiration(idTokenCacheItem);
|
1246 | if (idTokenIsStillValid) {
|
1247 | this.logger.verbose("ID token expiration is within offset, using ID token found in cache");
|
1248 | var idTokenValue = idTokenCacheItem.value;
|
1249 | if (idTokenValue) {
|
1250 | this.logger.verbose("ID Token found in cache is valid and unexpired");
|
1251 | }
|
1252 | else {
|
1253 | this.logger.verbose("ID Token found in cache is invalid");
|
1254 | }
|
1255 | return (idTokenValue) ? new IdToken(idTokenValue.idToken) : null;
|
1256 | }
|
1257 | else {
|
1258 | this.logger.verbose("Cached ID token is expired, removing from cache");
|
1259 | this.cacheStorage.removeItem(JSON.stringify(idTokenCacheItem.key));
|
1260 | return null;
|
1261 | }
|
1262 | }
|
1263 | else {
|
1264 | this.logger.verbose("No tokens found");
|
1265 | return null;
|
1266 | }
|
1267 | };
|
1268 | |
1269 |
|
1270 |
|
1271 |
|
1272 |
|
1273 |
|
1274 |
|
1275 |
|
1276 |
|
1277 |
|
1278 | UserAgentApplication.prototype.getCachedAccessToken = function (serverAuthenticationRequest, account, scopes) {
|
1279 | this.logger.verbose("Getting all cached tokens of type Access Token");
|
1280 | var tokenCacheItems = this.cacheStorage.getAllAccessTokens(this.clientId, account ? account.homeAccountIdentifier : null);
|
1281 | var scopeFilteredTokenCacheItems = AuthCacheUtils.filterTokenCacheItemsByScope(tokenCacheItems, scopes);
|
1282 | var matchAuthority = serverAuthenticationRequest.authority || this.authority;
|
1283 |
|
1284 | var accessTokenCacheItem = this.getTokenCacheItemByAuthority(matchAuthority, scopeFilteredTokenCacheItems, scopes, ServerHashParamKeys.ACCESS_TOKEN);
|
1285 | if (!accessTokenCacheItem) {
|
1286 | this.logger.verbose("No matching token found when filtering by scope and authority");
|
1287 | return null;
|
1288 | }
|
1289 | else {
|
1290 | serverAuthenticationRequest.authorityInstance = AuthorityFactory.CreateInstance(accessTokenCacheItem.key.authority, this.config.auth.validateAuthority);
|
1291 | this.logger.verbose("Evaluating access token found");
|
1292 | var tokenIsStillValid = this.evaluateTokenExpiration(accessTokenCacheItem);
|
1293 |
|
1294 | if (tokenIsStillValid) {
|
1295 | this.logger.verbose("Access token expiration is within offset, using access token found in cache");
|
1296 | var responseAccount = account || this.getAccount();
|
1297 | if (!responseAccount) {
|
1298 | throw AuthError.createUnexpectedError("Account should not be null here.");
|
1299 | }
|
1300 | var aState = this.getAccountState(serverAuthenticationRequest.state);
|
1301 | var response = {
|
1302 | uniqueId: "",
|
1303 | tenantId: "",
|
1304 | tokenType: ServerHashParamKeys.ACCESS_TOKEN,
|
1305 | idToken: null,
|
1306 | idTokenClaims: null,
|
1307 | accessToken: accessTokenCacheItem.value.accessToken,
|
1308 | scopes: accessTokenCacheItem.key.scopes.split(" "),
|
1309 | expiresOn: new Date(Number(accessTokenCacheItem.value.expiresIn) * 1000),
|
1310 | account: responseAccount,
|
1311 | accountState: aState,
|
1312 | fromCache: true
|
1313 | };
|
1314 | return response;
|
1315 | }
|
1316 | else {
|
1317 | this.logger.verbose("Access token expired, removing from cache");
|
1318 | this.cacheStorage.removeItem(JSON.stringify(accessTokenCacheItem.key));
|
1319 | return null;
|
1320 | }
|
1321 | }
|
1322 | };
|
1323 | |
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 | UserAgentApplication.prototype.evaluateTokenExpiration = function (tokenCacheItem) {
|
1329 | var expiration = Number(tokenCacheItem.value.expiresIn);
|
1330 | return TokenUtils.validateExpirationIsWithinOffset(expiration, this.config.system.tokenRenewalOffsetSeconds);
|
1331 | };
|
1332 | |
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 | UserAgentApplication.prototype.extractADALIdToken = function () {
|
1338 | this.logger.verbose("ExtractADALIdToken has been called");
|
1339 | var adalIdToken = this.cacheStorage.getItem(Constants.adalIdToken);
|
1340 | return (!StringUtils.isEmpty(adalIdToken)) ? TokenUtils.extractIdToken(adalIdToken) : null;
|
1341 | };
|
1342 | |
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 | UserAgentApplication.prototype.renewToken = function (requestSignature, resolve, reject, account, serverAuthenticationRequest) {
|
1348 | this.logger.verbose("RenewToken has been called");
|
1349 | this.logger.verbosePii("RenewToken scope and authority: " + requestSignature);
|
1350 | var frameName = WindowUtils.generateFrameName(FramePrefix.TOKEN_FRAME, requestSignature);
|
1351 | WindowUtils.addHiddenIFrame(frameName, this.logger);
|
1352 | this.updateCacheEntries(serverAuthenticationRequest, account, false);
|
1353 | this.logger.verbosePii("RenewToken expected state: " + serverAuthenticationRequest.state);
|
1354 |
|
1355 | var urlNavigate = UrlUtils.urlRemoveQueryStringParameter(UrlUtils.createNavigateUrl(serverAuthenticationRequest), Constants.prompt) + Constants.prompt_none + Constants.response_mode_fragment;
|
1356 | window.renewStates.push(serverAuthenticationRequest.state);
|
1357 | window.requestType = Constants.renewToken;
|
1358 | this.logger.verbose("Set window.renewState and requestType");
|
1359 | this.registerCallback(serverAuthenticationRequest.state, requestSignature, resolve, reject);
|
1360 | this.logger.infoPii("Navigate to: " + urlNavigate);
|
1361 | this.loadIframeTimeout(urlNavigate, frameName, requestSignature).catch(function (error) { return reject(error); });
|
1362 | };
|
1363 | |
1364 |
|
1365 |
|
1366 |
|
1367 |
|
1368 | UserAgentApplication.prototype.renewIdToken = function (requestSignature, resolve, reject, account, serverAuthenticationRequest) {
|
1369 | this.logger.info("RenewIdToken has been called");
|
1370 | var frameName = WindowUtils.generateFrameName(FramePrefix.ID_TOKEN_FRAME, requestSignature);
|
1371 | WindowUtils.addHiddenIFrame(frameName, this.logger);
|
1372 | this.updateCacheEntries(serverAuthenticationRequest, account, false);
|
1373 | this.logger.verbose("RenewIdToken expected state: " + serverAuthenticationRequest.state);
|
1374 |
|
1375 | var urlNavigate = UrlUtils.urlRemoveQueryStringParameter(UrlUtils.createNavigateUrl(serverAuthenticationRequest), Constants.prompt) + Constants.prompt_none + Constants.response_mode_fragment;
|
1376 | if (this.silentLogin) {
|
1377 | this.logger.verbose("Silent login is true, set silentAuthenticationState");
|
1378 | window.requestType = Constants.login;
|
1379 | this.silentAuthenticationState = serverAuthenticationRequest.state;
|
1380 | }
|
1381 | else {
|
1382 | this.logger.verbose("Not silent login, set window.renewState and requestType");
|
1383 | window.requestType = Constants.renewToken;
|
1384 | window.renewStates.push(serverAuthenticationRequest.state);
|
1385 | }
|
1386 |
|
1387 | this.registerCallback(serverAuthenticationRequest.state, requestSignature, resolve, reject);
|
1388 | this.logger.infoPii("Navigate to:\" " + urlNavigate);
|
1389 | this.loadIframeTimeout(urlNavigate, frameName, requestSignature).catch(function (error) { return reject(error); });
|
1390 | };
|
1391 | |
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 |
|
1401 |
|
1402 |
|
1403 | UserAgentApplication.prototype.saveToken = function (response, authority, scopes, clientInfo, expiration) {
|
1404 | var accessTokenKey = new AccessTokenKey(authority, this.clientId, scopes, clientInfo.uid, clientInfo.utid);
|
1405 | var accessTokenValue = new AccessTokenValue(response.accessToken, response.idToken.rawIdToken, expiration.toString(), clientInfo.encodeClientInfo());
|
1406 | this.cacheStorage.setItem(JSON.stringify(accessTokenKey), JSON.stringify(accessTokenValue));
|
1407 | if (expiration) {
|
1408 | this.logger.verbose("New expiration set for token");
|
1409 | response.expiresOn = new Date(expiration * 1000);
|
1410 | }
|
1411 | else {
|
1412 | this.logger.error("Could not parse expiresIn parameter for access token");
|
1413 | }
|
1414 | return response;
|
1415 | };
|
1416 | |
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 | UserAgentApplication.prototype.saveIdToken = function (response, authority, parameters, clientInfo, idTokenObj) {
|
1430 | this.logger.verbose("SaveIdToken has been called");
|
1431 | var idTokenResponse = __assign({}, response);
|
1432 |
|
1433 | var scopes;
|
1434 | idTokenResponse.scopes = Constants.oidcScopes;
|
1435 | idTokenResponse.accessToken = parameters[ServerHashParamKeys.ID_TOKEN];
|
1436 | var expiration = Number(idTokenObj.expiration);
|
1437 |
|
1438 | this.logger.verbose("Saving ID token to cache");
|
1439 | return this.saveToken(idTokenResponse, authority, scopes, clientInfo, expiration);
|
1440 | };
|
1441 | |
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 | UserAgentApplication.prototype.saveAccessToken = function (response, authority, parameters, clientInfo) {
|
1453 | this.logger.verbose("SaveAccessToken has been called");
|
1454 | var accessTokenResponse = __assign({}, response);
|
1455 |
|
1456 | var scope = parameters[ServerHashParamKeys.SCOPE];
|
1457 | var consentedScopes = scope.split(" ");
|
1458 |
|
1459 | var accessTokenCacheItems = this.cacheStorage.getAllAccessTokens(this.clientId, authority);
|
1460 | this.logger.verbose("Retrieving all access tokens from cache and removing duplicates");
|
1461 | for (var i = 0; i < accessTokenCacheItems.length; i++) {
|
1462 | var accessTokenCacheItem = accessTokenCacheItems[i];
|
1463 | if (accessTokenCacheItem.key.homeAccountIdentifier === response.account.homeAccountIdentifier) {
|
1464 | var cachedScopes = accessTokenCacheItem.key.scopes.split(" ");
|
1465 | if (ScopeSet.isIntersectingScopes(cachedScopes, consentedScopes)) {
|
1466 | this.cacheStorage.removeItem(JSON.stringify(accessTokenCacheItem.key));
|
1467 | }
|
1468 | }
|
1469 | }
|
1470 | accessTokenResponse.accessToken = parameters[ServerHashParamKeys.ACCESS_TOKEN];
|
1471 | accessTokenResponse.scopes = consentedScopes;
|
1472 | var expiresIn = TimeUtils.parseExpiresIn(parameters[ServerHashParamKeys.EXPIRES_IN]);
|
1473 | var parsedState = RequestUtils.parseLibraryState(parameters[ServerHashParamKeys.STATE]);
|
1474 | var expiration = parsedState.ts + expiresIn;
|
1475 | this.logger.verbose("Saving access token to cache");
|
1476 | return this.saveToken(accessTokenResponse, authority, scope, clientInfo, expiration);
|
1477 | };
|
1478 | |
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 | UserAgentApplication.prototype.saveTokenFromHash = function (hash, stateInfo) {
|
1484 | this.logger.verbose("SaveTokenFromHash has been called");
|
1485 | this.logger.info("State status: " + stateInfo.stateMatch + "; Request type: " + stateInfo.requestType);
|
1486 | var response = {
|
1487 | uniqueId: "",
|
1488 | tenantId: "",
|
1489 | tokenType: "",
|
1490 | idToken: null,
|
1491 | idTokenClaims: null,
|
1492 | accessToken: null,
|
1493 | scopes: [],
|
1494 | expiresOn: null,
|
1495 | account: null,
|
1496 | accountState: "",
|
1497 | fromCache: false
|
1498 | };
|
1499 | var error;
|
1500 | var hashParams = UrlUtils.deserializeHash(hash);
|
1501 | var authorityKey = "";
|
1502 | var acquireTokenAccountKey = "";
|
1503 | var idTokenObj = null;
|
1504 |
|
1505 | if (hashParams.hasOwnProperty(ServerHashParamKeys.ERROR_DESCRIPTION) || hashParams.hasOwnProperty(ServerHashParamKeys.ERROR)) {
|
1506 | this.logger.verbose("Server returned an error");
|
1507 | this.logger.infoPii("Error : " + hashParams[ServerHashParamKeys.ERROR] + "; Error description: " + hashParams[ServerHashParamKeys.ERROR_DESCRIPTION]);
|
1508 | this.cacheStorage.setItem(ErrorCacheKeys.ERROR, hashParams[ServerHashParamKeys.ERROR]);
|
1509 | this.cacheStorage.setItem(ErrorCacheKeys.ERROR_DESC, hashParams[ServerHashParamKeys.ERROR_DESCRIPTION]);
|
1510 |
|
1511 | if (stateInfo.requestType === Constants.login) {
|
1512 | this.logger.verbose("RequestType is login, caching login error, generating authorityKey");
|
1513 | this.cacheStorage.setItem(ErrorCacheKeys.LOGIN_ERROR, hashParams[ServerHashParamKeys.ERROR_DESCRIPTION] + ":" + hashParams[ServerHashParamKeys.ERROR]);
|
1514 | authorityKey = AuthCache.generateAuthorityKey(stateInfo.state);
|
1515 | }
|
1516 |
|
1517 | if (stateInfo.requestType === Constants.renewToken) {
|
1518 | this.logger.verbose("RequestType is renewToken, generating acquireTokenAccountKey");
|
1519 | authorityKey = AuthCache.generateAuthorityKey(stateInfo.state);
|
1520 | var account = this.getAccount();
|
1521 | var accountId = void 0;
|
1522 | if (account && !StringUtils.isEmpty(account.homeAccountIdentifier)) {
|
1523 | accountId = account.homeAccountIdentifier;
|
1524 | this.logger.verbose("AccountId is set");
|
1525 | }
|
1526 | else {
|
1527 | accountId = Constants.no_account;
|
1528 | this.logger.verbose("AccountId is set as no_account");
|
1529 | }
|
1530 | acquireTokenAccountKey = AuthCache.generateAcquireTokenAccountKey(accountId, stateInfo.state);
|
1531 | }
|
1532 | var hashErr = hashParams[ServerHashParamKeys.ERROR];
|
1533 | var hashErrDesc = hashParams[ServerHashParamKeys.ERROR_DESCRIPTION];
|
1534 | if (InteractionRequiredAuthError.isInteractionRequiredError(hashErr) ||
|
1535 | InteractionRequiredAuthError.isInteractionRequiredError(hashErrDesc)) {
|
1536 | error = new InteractionRequiredAuthError(hashParams[ServerHashParamKeys.ERROR], hashParams[ServerHashParamKeys.ERROR_DESCRIPTION]);
|
1537 | }
|
1538 | else {
|
1539 | error = new ServerError(hashParams[ServerHashParamKeys.ERROR], hashParams[ServerHashParamKeys.ERROR_DESCRIPTION]);
|
1540 | }
|
1541 | }
|
1542 |
|
1543 | else {
|
1544 | this.logger.verbose("Server returns success");
|
1545 |
|
1546 | if (stateInfo.stateMatch) {
|
1547 | this.logger.info("State is right");
|
1548 | if (hashParams.hasOwnProperty(ServerHashParamKeys.SESSION_STATE)) {
|
1549 | this.logger.verbose("Fragment has session state, caching");
|
1550 | this.cacheStorage.setItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.SESSION_STATE, stateInfo.state), hashParams[ServerHashParamKeys.SESSION_STATE]);
|
1551 | }
|
1552 | response.accountState = this.getAccountState(stateInfo.state);
|
1553 | var clientInfo = void 0;
|
1554 |
|
1555 | if (hashParams.hasOwnProperty(ServerHashParamKeys.ACCESS_TOKEN)) {
|
1556 | this.logger.info("Fragment has access token");
|
1557 | response.accessToken = hashParams[ServerHashParamKeys.ACCESS_TOKEN];
|
1558 | if (hashParams.hasOwnProperty(ServerHashParamKeys.SCOPE)) {
|
1559 | response.scopes = hashParams[ServerHashParamKeys.SCOPE].split(" ");
|
1560 | }
|
1561 |
|
1562 | if (hashParams.hasOwnProperty(ServerHashParamKeys.ID_TOKEN)) {
|
1563 | this.logger.verbose("Fragment has id_token");
|
1564 | idTokenObj = new IdToken(hashParams[ServerHashParamKeys.ID_TOKEN]);
|
1565 | }
|
1566 | else {
|
1567 | this.logger.verbose("No idToken on fragment, getting idToken from cache");
|
1568 | idTokenObj = new IdToken(this.cacheStorage.getItem(PersistentCacheKeys.IDTOKEN));
|
1569 | }
|
1570 | response = ResponseUtils.setResponseIdToken(response, idTokenObj);
|
1571 |
|
1572 | var authority = this.populateAuthority(stateInfo.state, this.inCookie, this.cacheStorage, idTokenObj);
|
1573 | this.logger.verbose("Got authority from cache");
|
1574 |
|
1575 | if (hashParams.hasOwnProperty(ServerHashParamKeys.CLIENT_INFO)) {
|
1576 | this.logger.verbose("Fragment has clientInfo");
|
1577 | clientInfo = new ClientInfo(hashParams[ServerHashParamKeys.CLIENT_INFO], authority);
|
1578 | }
|
1579 | else if (this.authorityInstance.AuthorityType === AuthorityType.Adfs) {
|
1580 | clientInfo = ClientInfo.createClientInfoFromIdToken(idTokenObj, authority);
|
1581 | }
|
1582 | else {
|
1583 | this.logger.warning("ClientInfo not received in the response from AAD");
|
1584 | }
|
1585 | response.account = Account.createAccount(idTokenObj, clientInfo);
|
1586 | this.logger.verbose("Account object created from response");
|
1587 | var accountKey = void 0;
|
1588 | if (response.account && !StringUtils.isEmpty(response.account.homeAccountIdentifier)) {
|
1589 | this.logger.verbose("AccountKey set");
|
1590 | accountKey = response.account.homeAccountIdentifier;
|
1591 | }
|
1592 | else {
|
1593 | this.logger.verbose("AccountKey set as no_account");
|
1594 | accountKey = Constants.no_account;
|
1595 | }
|
1596 | acquireTokenAccountKey = AuthCache.generateAcquireTokenAccountKey(accountKey, stateInfo.state);
|
1597 | var acquireTokenAccountKey_noaccount = AuthCache.generateAcquireTokenAccountKey(Constants.no_account, stateInfo.state);
|
1598 | this.logger.verbose("AcquireTokenAccountKey generated");
|
1599 | var cachedAccount = this.cacheStorage.getItem(acquireTokenAccountKey);
|
1600 | var acquireTokenAccount = void 0;
|
1601 |
|
1602 | if (!StringUtils.isEmpty(cachedAccount)) {
|
1603 | acquireTokenAccount = JSON.parse(cachedAccount);
|
1604 | this.logger.verbose("AcquireToken request account retrieved from cache");
|
1605 | if (response.account && acquireTokenAccount && Account.compareAccounts(response.account, acquireTokenAccount)) {
|
1606 | response = this.saveAccessToken(response, authority, hashParams, clientInfo);
|
1607 | this.logger.info("The user object received in the response is the same as the one passed in the acquireToken request");
|
1608 | }
|
1609 | else {
|
1610 | this.logger.warning("The account object created from the response is not the same as the one passed in the acquireToken request");
|
1611 | }
|
1612 | }
|
1613 | else if (!StringUtils.isEmpty(this.cacheStorage.getItem(acquireTokenAccountKey_noaccount))) {
|
1614 | this.logger.verbose("No acquireToken account retrieved from cache");
|
1615 | response = this.saveAccessToken(response, authority, hashParams, clientInfo);
|
1616 | }
|
1617 | }
|
1618 |
|
1619 | if (hashParams.hasOwnProperty(ServerHashParamKeys.ID_TOKEN)) {
|
1620 | this.logger.info("Fragment has idToken");
|
1621 |
|
1622 | idTokenObj = new IdToken(hashParams[ServerHashParamKeys.ID_TOKEN]);
|
1623 |
|
1624 | var authority = this.populateAuthority(stateInfo.state, this.inCookie, this.cacheStorage, idTokenObj);
|
1625 | response = ResponseUtils.setResponseIdToken(response, idTokenObj);
|
1626 | if (hashParams.hasOwnProperty(ServerHashParamKeys.CLIENT_INFO)) {
|
1627 | this.logger.verbose("Fragment has clientInfo");
|
1628 | clientInfo = new ClientInfo(hashParams[ServerHashParamKeys.CLIENT_INFO], authority);
|
1629 | }
|
1630 | else if (this.authorityInstance.AuthorityType === AuthorityType.Adfs) {
|
1631 | clientInfo = ClientInfo.createClientInfoFromIdToken(idTokenObj, authority);
|
1632 | }
|
1633 | else {
|
1634 | this.logger.warning("ClientInfo not received in the response from AAD");
|
1635 | }
|
1636 | this.account = Account.createAccount(idTokenObj, clientInfo);
|
1637 | response.account = this.account;
|
1638 | this.logger.verbose("Account object created from response");
|
1639 | if (idTokenObj && idTokenObj.nonce) {
|
1640 | this.logger.verbose("IdToken has nonce");
|
1641 |
|
1642 | var cachedNonce = this.cacheStorage.getItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.NONCE_IDTOKEN, stateInfo.state), this.inCookie);
|
1643 | if (idTokenObj.nonce !== cachedNonce) {
|
1644 | this.account = null;
|
1645 | this.cacheStorage.setItem(ErrorCacheKeys.LOGIN_ERROR, "Nonce Mismatch. Expected Nonce: " + cachedNonce + "," + "Actual Nonce: " + idTokenObj.nonce);
|
1646 | this.logger.error("Nonce Mismatch. Expected Nonce: " + cachedNonce + ", Actual Nonce: " + idTokenObj.nonce);
|
1647 | error = ClientAuthError.createNonceMismatchError(cachedNonce, idTokenObj.nonce);
|
1648 | }
|
1649 |
|
1650 | else {
|
1651 | this.logger.verbose("Nonce matches, saving idToken to cache");
|
1652 | this.cacheStorage.setItem(PersistentCacheKeys.IDTOKEN, hashParams[ServerHashParamKeys.ID_TOKEN], this.inCookie);
|
1653 | this.cacheStorage.setItem(PersistentCacheKeys.CLIENT_INFO, clientInfo.encodeClientInfo(), this.inCookie);
|
1654 |
|
1655 | this.saveIdToken(response, authority, hashParams, clientInfo, idTokenObj);
|
1656 | }
|
1657 | }
|
1658 | else {
|
1659 | this.logger.verbose("No idToken or no nonce. Cache key for Authority set as state");
|
1660 | authorityKey = stateInfo.state;
|
1661 | acquireTokenAccountKey = stateInfo.state;
|
1662 | this.logger.error("Invalid id_token received in the response");
|
1663 | error = ClientAuthError.createInvalidIdTokenError(idTokenObj);
|
1664 | this.cacheStorage.setItem(ErrorCacheKeys.ERROR, error.errorCode);
|
1665 | this.cacheStorage.setItem(ErrorCacheKeys.ERROR_DESC, error.errorMessage);
|
1666 | }
|
1667 | }
|
1668 | }
|
1669 |
|
1670 | else {
|
1671 | this.logger.verbose("State mismatch");
|
1672 | authorityKey = stateInfo.state;
|
1673 | acquireTokenAccountKey = stateInfo.state;
|
1674 | var expectedState = this.cacheStorage.getItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.STATE_LOGIN, stateInfo.state), this.inCookie);
|
1675 | this.logger.error("State Mismatch. Expected State: " + expectedState + ", Actual State: " + stateInfo.state);
|
1676 | error = ClientAuthError.createInvalidStateError(stateInfo.state, expectedState);
|
1677 | this.cacheStorage.setItem(ErrorCacheKeys.ERROR, error.errorCode);
|
1678 | this.cacheStorage.setItem(ErrorCacheKeys.ERROR_DESC, error.errorMessage);
|
1679 | }
|
1680 | }
|
1681 |
|
1682 | this.cacheStorage.removeItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.RENEW_STATUS, stateInfo.state));
|
1683 | this.cacheStorage.resetTempCacheItems(stateInfo.state);
|
1684 | this.logger.verbose("Status set to complete, temporary cache cleared");
|
1685 |
|
1686 | if (this.inCookie) {
|
1687 | this.logger.verbose("InCookie is true, setting authorityKey in cookie");
|
1688 | this.cacheStorage.setItemCookie(authorityKey, "", -1);
|
1689 | this.cacheStorage.clearMsalCookie(stateInfo.state);
|
1690 | }
|
1691 | if (error) {
|
1692 |
|
1693 | throw error;
|
1694 | }
|
1695 | if (!response) {
|
1696 | throw AuthError.createUnexpectedError("Response is null");
|
1697 | }
|
1698 | return response;
|
1699 | };
|
1700 | |
1701 |
|
1702 |
|
1703 |
|
1704 |
|
1705 |
|
1706 |
|
1707 |
|
1708 | UserAgentApplication.prototype.populateAuthority = function (state, inCookie, cacheStorage, idTokenObj) {
|
1709 | this.logger.verbose("PopulateAuthority has been called");
|
1710 | var authorityKey = AuthCache.generateAuthorityKey(state);
|
1711 | var cachedAuthority = cacheStorage.getItem(authorityKey, inCookie);
|
1712 |
|
1713 | return StringUtils.isEmpty(cachedAuthority) ? cachedAuthority : UrlUtils.replaceTenantPath(cachedAuthority, idTokenObj.tenantId);
|
1714 | };
|
1715 |
|
1716 |
|
1717 |
|
1718 | |
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 | UserAgentApplication.prototype.getAccount = function () {
|
1725 |
|
1726 | if (this.account) {
|
1727 | return this.account;
|
1728 | }
|
1729 |
|
1730 | var rawIdToken = this.cacheStorage.getItem(PersistentCacheKeys.IDTOKEN, this.inCookie);
|
1731 | var rawClientInfo = this.cacheStorage.getItem(PersistentCacheKeys.CLIENT_INFO, this.inCookie);
|
1732 | if (!StringUtils.isEmpty(rawIdToken) && !StringUtils.isEmpty(rawClientInfo)) {
|
1733 | var idToken = new IdToken(rawIdToken);
|
1734 | var clientInfo = new ClientInfo(rawClientInfo, "");
|
1735 | this.account = Account.createAccount(idToken, clientInfo);
|
1736 | return this.account;
|
1737 | }
|
1738 |
|
1739 | return null;
|
1740 | };
|
1741 | |
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 | UserAgentApplication.prototype.getAccountState = function (state) {
|
1749 | if (state) {
|
1750 | var splitIndex = state.indexOf(Constants.resourceDelimiter);
|
1751 | if (splitIndex > -1 && splitIndex + 1 < state.length) {
|
1752 | return state.substring(splitIndex + 1);
|
1753 | }
|
1754 | }
|
1755 | return state;
|
1756 | };
|
1757 | |
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 | UserAgentApplication.prototype.getAllAccounts = function () {
|
1763 | var accounts = [];
|
1764 | var accessTokenCacheItems = this.cacheStorage.getAllAccessTokens(Constants.clientId, Constants.homeAccountIdentifier);
|
1765 | for (var i = 0; i < accessTokenCacheItems.length; i++) {
|
1766 | var idToken = new IdToken(accessTokenCacheItems[i].value.idToken);
|
1767 | var clientInfo = new ClientInfo(accessTokenCacheItems[i].value.homeAccountIdentifier, "");
|
1768 | var account = Account.createAccount(idToken, clientInfo);
|
1769 | accounts.push(account);
|
1770 | }
|
1771 | return this.getUniqueAccounts(accounts);
|
1772 | };
|
1773 | |
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 | UserAgentApplication.prototype.getUniqueAccounts = function (accounts) {
|
1781 | if (!accounts || accounts.length <= 1) {
|
1782 | return accounts;
|
1783 | }
|
1784 | var flags = [];
|
1785 | var uniqueAccounts = [];
|
1786 | for (var index = 0; index < accounts.length; ++index) {
|
1787 | if (accounts[index].homeAccountIdentifier && flags.indexOf(accounts[index].homeAccountIdentifier) === -1) {
|
1788 | flags.push(accounts[index].homeAccountIdentifier);
|
1789 | uniqueAccounts.push(accounts[index]);
|
1790 | }
|
1791 | }
|
1792 | return uniqueAccounts;
|
1793 | };
|
1794 |
|
1795 |
|
1796 | |
1797 |
|
1798 |
|
1799 |
|
1800 |
|
1801 |
|
1802 |
|
1803 | UserAgentApplication.prototype.broadcast = function (eventName, data) {
|
1804 | var evt = new CustomEvent(eventName, { detail: data });
|
1805 | window.dispatchEvent(evt);
|
1806 | };
|
1807 | |
1808 |
|
1809 |
|
1810 |
|
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 | UserAgentApplication.prototype.getCachedTokenInternal = function (scopes, account, state, correlationId) {
|
1818 |
|
1819 | var accountObject = account || this.getAccount();
|
1820 | if (!accountObject) {
|
1821 | return null;
|
1822 | }
|
1823 |
|
1824 | var newAuthority = this.authorityInstance ? this.authorityInstance : AuthorityFactory.CreateInstance(this.authority, this.config.auth.validateAuthority);
|
1825 | var responseType = this.getTokenType(accountObject, scopes);
|
1826 | var serverAuthenticationRequest = new ServerRequestParameters(newAuthority, this.clientId, responseType, this.getRedirectUri(), scopes, state, correlationId);
|
1827 |
|
1828 | return this.getCachedToken(serverAuthenticationRequest, account);
|
1829 | };
|
1830 | |
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 | UserAgentApplication.prototype.getScopesForEndpoint = function (endpoint) {
|
1839 |
|
1840 | if (this.config.framework.unprotectedResources.length > 0) {
|
1841 | for (var i = 0; i < this.config.framework.unprotectedResources.length; i++) {
|
1842 | if (endpoint.indexOf(this.config.framework.unprotectedResources[i]) > -1) {
|
1843 | return null;
|
1844 | }
|
1845 | }
|
1846 | }
|
1847 |
|
1848 | if (this.config.framework.protectedResourceMap.size > 0) {
|
1849 | for (var _i = 0, _a = Array.from(this.config.framework.protectedResourceMap.keys()); _i < _a.length; _i++) {
|
1850 | var key = _a[_i];
|
1851 |
|
1852 | if (endpoint.indexOf(key) > -1) {
|
1853 | return this.config.framework.protectedResourceMap.get(key);
|
1854 | }
|
1855 | }
|
1856 | }
|
1857 | |
1858 |
|
1859 |
|
1860 |
|
1861 |
|
1862 | if (endpoint.indexOf("http://") > -1 || endpoint.indexOf("https://") > -1) {
|
1863 | if (UrlUtils.getHostFromUri(endpoint) === UrlUtils.getHostFromUri(this.getRedirectUri())) {
|
1864 | return new Array(this.clientId);
|
1865 | }
|
1866 | }
|
1867 | else {
|
1868 | |
1869 |
|
1870 |
|
1871 |
|
1872 | return new Array(this.clientId);
|
1873 | }
|
1874 |
|
1875 | return null;
|
1876 | };
|
1877 | |
1878 |
|
1879 |
|
1880 |
|
1881 | UserAgentApplication.prototype.getLoginInProgress = function () {
|
1882 | return this.cacheStorage.isInteractionInProgress(true);
|
1883 | };
|
1884 | |
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 |
|
1890 | UserAgentApplication.prototype.setInteractionInProgress = function (inProgress) {
|
1891 | this.cacheStorage.setInteractionInProgress(inProgress);
|
1892 | };
|
1893 | |
1894 |
|
1895 |
|
1896 |
|
1897 |
|
1898 |
|
1899 | UserAgentApplication.prototype.setloginInProgress = function (loginInProgress) {
|
1900 | this.setInteractionInProgress(loginInProgress);
|
1901 | };
|
1902 | |
1903 |
|
1904 |
|
1905 |
|
1906 |
|
1907 |
|
1908 | UserAgentApplication.prototype.getAcquireTokenInProgress = function () {
|
1909 | return this.cacheStorage.isInteractionInProgress(true);
|
1910 | };
|
1911 | |
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 | UserAgentApplication.prototype.setAcquireTokenInProgress = function (acquireTokenInProgress) {
|
1918 | this.setInteractionInProgress(acquireTokenInProgress);
|
1919 | };
|
1920 | |
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 | UserAgentApplication.prototype.getLogger = function () {
|
1927 | return this.logger;
|
1928 | };
|
1929 | |
1930 |
|
1931 |
|
1932 |
|
1933 | UserAgentApplication.prototype.setLogger = function (logger) {
|
1934 | this.logger = logger;
|
1935 | };
|
1936 |
|
1937 |
|
1938 | |
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 |
|
1944 | UserAgentApplication.prototype.getRedirectUri = function (reqRedirectUri) {
|
1945 | if (reqRedirectUri) {
|
1946 | return reqRedirectUri;
|
1947 | }
|
1948 | else if (typeof this.config.auth.redirectUri === "function") {
|
1949 | return this.config.auth.redirectUri();
|
1950 | }
|
1951 | return this.config.auth.redirectUri;
|
1952 | };
|
1953 | |
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 |
|
1959 | UserAgentApplication.prototype.getPostLogoutRedirectUri = function () {
|
1960 | if (typeof this.config.auth.postLogoutRedirectUri === "function") {
|
1961 | return this.config.auth.postLogoutRedirectUri();
|
1962 | }
|
1963 | return this.config.auth.postLogoutRedirectUri;
|
1964 | };
|
1965 | |
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 | UserAgentApplication.prototype.getCurrentConfiguration = function () {
|
1971 | if (!this.config) {
|
1972 | throw ClientConfigurationError.createNoSetConfigurationError();
|
1973 | }
|
1974 | return this.config;
|
1975 | };
|
1976 | |
1977 |
|
1978 |
|
1979 |
|
1980 |
|
1981 |
|
1982 |
|
1983 |
|
1984 |
|
1985 |
|
1986 | UserAgentApplication.prototype.getTokenType = function (accountObject, scopes) {
|
1987 | var accountsMatch = Account.compareAccounts(accountObject, this.getAccount());
|
1988 | return ServerRequestParameters.determineResponseType(accountsMatch, scopes);
|
1989 | };
|
1990 | |
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 |
|
1999 | UserAgentApplication.prototype.setAccountCache = function (account, state) {
|
2000 |
|
2001 | var accountId = account ? this.getAccountId(account) : Constants.no_account;
|
2002 | var acquireTokenAccountKey = AuthCache.generateAcquireTokenAccountKey(accountId, state);
|
2003 | this.cacheStorage.setItem(acquireTokenAccountKey, JSON.stringify(account));
|
2004 | };
|
2005 | |
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 |
|
2014 | UserAgentApplication.prototype.setAuthorityCache = function (state, authority) {
|
2015 |
|
2016 | var authorityKey = AuthCache.generateAuthorityKey(state);
|
2017 | this.cacheStorage.setItem(authorityKey, UrlUtils.CanonicalizeUri(authority), this.inCookie);
|
2018 | };
|
2019 | |
2020 |
|
2021 |
|
2022 |
|
2023 |
|
2024 |
|
2025 |
|
2026 | UserAgentApplication.prototype.updateCacheEntries = function (serverAuthenticationRequest, account, isLoginCall, loginStartPage) {
|
2027 |
|
2028 | if (loginStartPage) {
|
2029 | this.cacheStorage.setItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.LOGIN_REQUEST, serverAuthenticationRequest.state), loginStartPage, this.inCookie);
|
2030 | }
|
2031 |
|
2032 | if (isLoginCall) {
|
2033 |
|
2034 | this.cacheStorage.setItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.STATE_LOGIN, serverAuthenticationRequest.state), serverAuthenticationRequest.state, this.inCookie);
|
2035 | }
|
2036 | else {
|
2037 | this.setAccountCache(account, serverAuthenticationRequest.state);
|
2038 | }
|
2039 |
|
2040 | this.setAuthorityCache(serverAuthenticationRequest.state, serverAuthenticationRequest.authority);
|
2041 |
|
2042 | this.cacheStorage.setItem(AuthCache.generateTemporaryCacheKey(TemporaryCacheKeys.NONCE_IDTOKEN, serverAuthenticationRequest.state), serverAuthenticationRequest.nonce, this.inCookie);
|
2043 | };
|
2044 | |
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 | UserAgentApplication.prototype.getAccountId = function (account) {
|
2051 |
|
2052 | var accountId;
|
2053 | if (!StringUtils.isEmpty(account.homeAccountIdentifier)) {
|
2054 | accountId = account.homeAccountIdentifier;
|
2055 | }
|
2056 | else {
|
2057 | accountId = Constants.no_account;
|
2058 | }
|
2059 | return accountId;
|
2060 | };
|
2061 | |
2062 |
|
2063 |
|
2064 |
|
2065 |
|
2066 |
|
2067 | UserAgentApplication.prototype.buildIDTokenRequest = function (request) {
|
2068 | var tokenRequest = {
|
2069 | scopes: Constants.oidcScopes,
|
2070 | authority: this.authority,
|
2071 | account: this.getAccount(),
|
2072 | extraQueryParameters: request.extraQueryParameters,
|
2073 | correlationId: request.correlationId
|
2074 | };
|
2075 | return tokenRequest;
|
2076 | };
|
2077 | |
2078 |
|
2079 |
|
2080 |
|
2081 |
|
2082 |
|
2083 |
|
2084 | UserAgentApplication.prototype.getTelemetryManagerFromConfig = function (config, clientId) {
|
2085 | if (!config) {
|
2086 | return TelemetryManager.getTelemetrymanagerStub(clientId, this.logger);
|
2087 | }
|
2088 |
|
2089 | var applicationName = config.applicationName, applicationVersion = config.applicationVersion, telemetryEmitter = config.telemetryEmitter;
|
2090 | if (!applicationName || !applicationVersion || !telemetryEmitter) {
|
2091 | throw ClientConfigurationError.createTelemetryConfigError(config);
|
2092 | }
|
2093 |
|
2094 | var telemetryPlatform = {
|
2095 | applicationName: applicationName,
|
2096 | applicationVersion: applicationVersion
|
2097 | };
|
2098 | var telemetryManagerConfig = {
|
2099 | platform: telemetryPlatform,
|
2100 | clientId: clientId
|
2101 | };
|
2102 | return new TelemetryManager(telemetryManagerConfig, telemetryEmitter, this.logger);
|
2103 | };
|
2104 | return UserAgentApplication;
|
2105 | }());
|
2106 | export { UserAgentApplication };
|
2107 |
|
\ | No newline at end of file |