"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MsalTokenProvider = void 0;
var tslib_1 = require("tslib");
var sp_diagnostics_1 = require("@microsoft/sp-diagnostics");
var AadTokenProvider_1 = tslib_1.__importDefault(require("../../AadTokenProvider"));
var AadTokenProvider_2 = require("../../AadTokenProvider");
var sp_core_library_1 = require("@microsoft/sp-core-library");
var AadConstants_1 = tslib_1.__importDefault(require("../../AadConstants"));
var AadErrorHandler_1 = require("../../AadErrorHandler");
var AadKillSwitches_1 = require("../../AadKillSwitches");
var msal = tslib_1.__importStar(require("msal"));
var msalLegacy = tslib_1.__importStar(require("msalLegacy"));
/**
 * Class that wraps the MSAL's authentication class
 * @internal
 */
var MsalTokenProvider = /** @class */ (function () {
    function MsalTokenProvider(configuration) {
        this._defaultConfiguration = configuration;
        this._requestMap = new Map();
        this._msalInstance = this._initializeMsalJs();
    }
    MsalTokenProvider.prototype.getToken = function (resourceEndpoint, useCachedToken) {
        var _this = this;
        if (useCachedToken === void 0) { useCachedToken = true; }
        if (AadKillSwitches_1.AadKillSwitches.isReturnTokenDataEnabled()) {
            return this.getTokenData(resourceEndpoint, useCachedToken).then(function (tokenData) { return tokenData.accessToken; });
        }
        var acquireAccessTokenQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.GetToken');
        var extraData = this._generateTelemetryExtraData();
        if (AadKillSwitches_1.AadKillSwitches.isLogAadAdditionalTelemetryEnabled() && extraData.isInternal) {
            extraData.name = resourceEndpoint;
        }
        // If you try to fetch a token without "logging in", MSAL will make a request to fetch both
        // an ID and ACCESS token in parallel. The problem with this is that the URL containing the tokens
        // will exceed 4K characters. IE and EDGE do not support this and will automatically drop off
        // trailing query parameters. MSAL team plans to eventually fix this on their end.
        var currentBrowser = sp_core_library_1._BrowserDetection.getBrowserInformation().browser;
        var acquireTokenPromise;
        if (currentBrowser === sp_core_library_1._Browser.IE || currentBrowser === sp_core_library_1._Browser.Edge) {
            acquireTokenPromise = this._loginSilent().then(function () { return _this._acquireToken(resourceEndpoint); });
        }
        else {
            acquireTokenPromise = this._acquireToken(resourceEndpoint);
        }
        extraData.CorrelationId = this._defaultConfiguration.spRequestGuid || sp_core_library_1.Guid.newGuid().toString();
        return acquireTokenPromise
            .then(function (accessToken) {
            acquireAccessTokenQosMonitor.writeSuccess(extraData);
            return accessToken;
        })
            .catch(function (error) {
            if (AadKillSwitches_1.AadKillSwitches.isRemoveDuplicateHandleAuthErrorsCallEnabled()) {
                if (_this._isExpectedFailure(error)) {
                    acquireAccessTokenQosMonitor.writeExpectedFailure(error.errorCode, error, extraData);
                }
                else {
                    acquireAccessTokenQosMonitor.writeUnexpectedFailure(error.errorCode, error, extraData);
                }
                throw error;
            }
            else {
                _this._handleAuthErrors(acquireAccessTokenQosMonitor, error, extraData, resourceEndpoint);
            }
        });
    };
    MsalTokenProvider.prototype.getTokenData = function (resourceEndpoint, useCachedToken, skipLoggingAndDisableRedirects) {
        var _this = this;
        if (useCachedToken === void 0) { useCachedToken = true; }
        if (skipLoggingAndDisableRedirects === void 0) { skipLoggingAndDisableRedirects = false; }
        var acquireAccessTokenDataQosMonitor;
        var extraData = this._generateTelemetryExtraData();
        if (!skipLoggingAndDisableRedirects) {
            acquireAccessTokenDataQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.GetTokenData');
        }
        if (AadKillSwitches_1.AadKillSwitches.isLogAadAdditionalTelemetryEnabled() && extraData.isInternal) {
            extraData.name = resourceEndpoint;
        }
        // If you try to fetch a token without "logging in", MSAL will make a request to fetch both
        // an ID and ACCESS token in parallel. The problem with this is that the URL containing the tokens
        // will exceed 4K characters. IE and EDGE do not support this and will automatically drop off
        // trailing query parameters. MSAL team plans to eventually fix this on their end.
        var currentBrowser = sp_core_library_1._BrowserDetection.getBrowserInformation().browser;
        var acquireTokenDataPromise;
        if (currentBrowser === sp_core_library_1._Browser.IE || currentBrowser === sp_core_library_1._Browser.Edge) {
            acquireTokenDataPromise = this._loginSilent().then(function () {
                return _this._acquireTokenData(resourceEndpoint, skipLoggingAndDisableRedirects);
            });
        }
        else {
            acquireTokenDataPromise = this._acquireTokenData(resourceEndpoint, skipLoggingAndDisableRedirects);
        }
        extraData.CorrelationId = this._defaultConfiguration.spRequestGuid || sp_core_library_1.Guid.newGuid().toString();
        return acquireTokenDataPromise
            .then(function (tokenData) {
            acquireAccessTokenDataQosMonitor === null || acquireAccessTokenDataQosMonitor === void 0 ? void 0 : acquireAccessTokenDataQosMonitor.writeSuccess(extraData);
            return tokenData;
        })
            .catch(function (error) {
            if (skipLoggingAndDisableRedirects) {
                throw error;
            }
            else if (AadKillSwitches_1.AadKillSwitches.isRemoveDuplicateHandleAuthErrorsCallEnabled() &&
                acquireAccessTokenDataQosMonitor) {
                if (_this._isExpectedFailure(error)) {
                    acquireAccessTokenDataQosMonitor.writeExpectedFailure(error.errorCode, error, extraData);
                }
                else {
                    acquireAccessTokenDataQosMonitor.writeUnexpectedFailure(error.errorCode, error, extraData);
                }
                throw error;
            }
            else {
                _this._handleAuthErrors(acquireAccessTokenDataQosMonitor, error, extraData, resourceEndpoint);
            }
        });
    };
    MsalTokenProvider.prototype._loginSilent = function () {
        // Represents the time it takes to fetch an id token.
        var getIdTokenQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.GetIdToken');
        return this._loginSilentHelper(0, getIdTokenQosMonitor);
    };
    MsalTokenProvider.prototype._loginSilentHelper = function (attempt, getIdTokenQosMonitor) {
        var _this = this;
        var retryQosMonitor;
        if (attempt > 0) {
            retryQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.RetryGetIdToken');
        }
        var extraData = this._generateTelemetryExtraData();
        var requestData = {
            authority: this._defaultConfiguration.aadInstanceUrl + '/' + this._defaultConfiguration.aadTenantId,
            correlationId: extraData.CorrelationId,
            loginHint: this._defaultConfiguration.userPrincipalName,
            scopes: [this._defaultConfiguration.servicePrincipalId]
        };
        if (attempt === 0) {
            requestData.sid = this._defaultConfiguration.aadSessionId;
            requestData.loginHint = undefined;
        }
        return this._msalInstance
            .acquireTokenSilent(requestData)
            .then(function (response) {
            // Using alias column to mark cache hits
            extraData.alias = response.fromCache.toString();
            if (AadKillSwitches_1.AadKillSwitches.isAdditionalMsalTelemetryEnabled()) {
                extraData.jsonExtraData = JSON.stringify(_this._requestMap.get(extraData.CorrelationId));
            }
            getIdTokenQosMonitor.writeSuccess(extraData);
            return response.accessToken;
        })
            .catch(function (e) {
            if (AadKillSwitches_1.AadKillSwitches.isAdditionalMsalTelemetryEnabled()) {
                extraData.jsonExtraData = JSON.stringify(_this._requestMap.get(extraData.CorrelationId));
            }
            retryQosMonitor === null || retryQosMonitor === void 0 ? void 0 : retryQosMonitor.writeUnexpectedFailure(e.errorCode, e, extraData);
            if (AadKillSwitches_1.AadKillSwitches.isRetryIdTokenWithLoginHintEnabled() &&
                AadErrorHandler_1.AadErrorHandler._isInteractionRequired(e.message, e.errorCode) &&
                attempt < 1) {
                return _this._loginSilentHelper(++attempt, getIdTokenQosMonitor);
            }
            else {
                _this._handleAuthErrors(getIdTokenQosMonitor, e, extraData, _this._defaultConfiguration.servicePrincipalId);
            }
        });
    };
    MsalTokenProvider.prototype._acquireToken = function (resourceEndpoint) {
        // Represents the time it takes to fetch an access token.
        var getAccessTokenQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.GetAccessToken');
        return this._acquireTokenHelper(resourceEndpoint, 0, getAccessTokenQosMonitor);
    };
    MsalTokenProvider.prototype._acquireTokenHelper = function (resourceEndpoint, attempt, getAccessTokenQosMonitor, useLoginHint) {
        var _this = this;
        if (useLoginHint === void 0) { useLoginHint = false; }
        var retryQosMonitor;
        if (attempt > 0) {
            if (useLoginHint) {
                retryQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.RetryLoginHintGetAccessToken');
            }
            else {
                retryQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.RetryGetAccessToken');
            }
        }
        var extraData = this._generateTelemetryExtraData();
        var requestData = {
            authority: this._defaultConfiguration.aadInstanceUrl + '/' + this._defaultConfiguration.aadTenantId,
            correlationId: extraData.CorrelationId,
            loginHint: this._defaultConfiguration.userPrincipalName,
            scopes: [resourceEndpoint + '/.default']
        };
        if (!useLoginHint) {
            requestData.sid = this._defaultConfiguration.aadSessionId;
            requestData.loginHint = undefined;
        }
        return this._msalInstance
            .acquireTokenSilent(requestData)
            .then(function (response) {
            // Using alias column to mark cache hits
            extraData.alias = response.fromCache.toString();
            if (AadKillSwitches_1.AadKillSwitches.isAdditionalMsalTelemetryEnabled()) {
                extraData.jsonExtraData = JSON.stringify(_this._requestMap.get(extraData.CorrelationId));
            }
            getAccessTokenQosMonitor.writeSuccess(extraData);
            retryQosMonitor === null || retryQosMonitor === void 0 ? void 0 : retryQosMonitor.writeSuccess(extraData);
            return response.accessToken;
        })
            .catch(function (e) {
            if (AadKillSwitches_1.AadKillSwitches.isAdditionalMsalTelemetryEnabled()) {
                extraData.jsonExtraData = JSON.stringify(_this._requestMap.get(extraData.CorrelationId));
            }
            retryQosMonitor === null || retryQosMonitor === void 0 ? void 0 : retryQosMonitor.writeUnexpectedFailure(e.errorCode, e, extraData);
            // We only want to retry once for network issues as the failure could be due to many different reasons
            // and retry could help fix the issue
            if ((AadKillSwitches_1.AadKillSwitches.isRetryTimeoutsEnabled() &&
                AadErrorHandler_1.AadErrorHandler._isTokenRenewalTimeout(e.errorCode) &&
                attempt < 1) ||
                (AadKillSwitches_1.AadKillSwitches.isRetryOnResolveEndpointsFailureEnabled() &&
                    AadErrorHandler_1.AadErrorHandler._isEndpointsResolutionError(e.errorCode) &&
                    attempt < 1)) {
                return _this._acquireTokenHelper(resourceEndpoint, ++attempt, getAccessTokenQosMonitor);
            }
            else if (AadKillSwitches_1.AadKillSwitches.isRetryWithLoginHintEnabled() &&
                (!AadKillSwitches_1.AadKillSwitches.isBlockLoginHintForGuestsEnabled() ||
                    _this._defaultConfiguration.userPrincipalName) &&
                AadErrorHandler_1.AadErrorHandler._isInteractionRequired(e.message, e.errorCode) &&
                attempt < 1) {
                return _this._acquireTokenHelper(resourceEndpoint, ++attempt, getAccessTokenQosMonitor, true);
            }
            else {
                _this._handleAuthErrors(getAccessTokenQosMonitor, e, extraData, resourceEndpoint);
            }
        });
    };
    MsalTokenProvider.prototype._acquireTokenData = function (resourceEndpoint, skipLoggingAndDisableRedirects) {
        if (skipLoggingAndDisableRedirects === void 0) { skipLoggingAndDisableRedirects = false; }
        // Represents the time it takes to fetch an access token.
        var getAccessTokenQosMonitor;
        if (!skipLoggingAndDisableRedirects) {
            getAccessTokenQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.GetAccessTokenData');
        }
        return this._acquireTokenDataHelper(resourceEndpoint, 0, getAccessTokenQosMonitor);
    };
    MsalTokenProvider.prototype._acquireTokenDataHelper = function (resourceEndpoint, attempt, getAccessTokenQosMonitor, useLoginHint) {
        var _this = this;
        if (useLoginHint === void 0) { useLoginHint = false; }
        var retryQosMonitor;
        if (attempt > 0) {
            if (useLoginHint) {
                retryQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.RetryLoginHintGetAccessToken');
            }
            else {
                retryQosMonitor = new sp_diagnostics_1._QosMonitor('MsalTokenProvider.RetryGetAccessToken');
            }
        }
        var extraData = this._generateTelemetryExtraData();
        var requestData = {
            authority: this._defaultConfiguration.aadInstanceUrl + '/' + this._defaultConfiguration.aadTenantId,
            correlationId: extraData.CorrelationId,
            loginHint: this._defaultConfiguration.userPrincipalName,
            scopes: [resourceEndpoint + '/.default']
        };
        if (!useLoginHint) {
            requestData.sid = this._defaultConfiguration.aadSessionId;
            requestData.loginHint = undefined;
        }
        return this._msalInstance
            .acquireTokenSilent(requestData)
            .then(function (response) {
            // Using alias column to mark cache hits
            extraData.alias = response.fromCache.toString();
            if (AadKillSwitches_1.AadKillSwitches.isAdditionalMsalTelemetryEnabled()) {
                extraData.jsonExtraData = JSON.stringify(_this._requestMap.get(extraData.CorrelationId));
            }
            getAccessTokenQosMonitor === null || getAccessTokenQosMonitor === void 0 ? void 0 : getAccessTokenQosMonitor.writeSuccess(extraData);
            retryQosMonitor === null || retryQosMonitor === void 0 ? void 0 : retryQosMonitor.writeSuccess(extraData);
            return response;
        })
            .catch(function (e) {
            if (AadKillSwitches_1.AadKillSwitches.isAdditionalMsalTelemetryEnabled()) {
                extraData.jsonExtraData = JSON.stringify(_this._requestMap.get(extraData.CorrelationId));
            }
            retryQosMonitor === null || retryQosMonitor === void 0 ? void 0 : retryQosMonitor.writeUnexpectedFailure(e.errorCode, e, extraData);
            // We only want to retry once for network issues as the failure could be due to many different reasons
            // and retry could help fix the issue
            if ((AadKillSwitches_1.AadKillSwitches.isRetryTimeoutsEnabled() &&
                AadErrorHandler_1.AadErrorHandler._isTokenRenewalTimeout(e.errorCode) &&
                attempt < 1) ||
                (AadKillSwitches_1.AadKillSwitches.isRetryOnResolveEndpointsFailureEnabled() &&
                    AadErrorHandler_1.AadErrorHandler._isEndpointsResolutionError(e.errorCode) &&
                    attempt < 1)) {
                return _this._acquireTokenDataHelper(resourceEndpoint, ++attempt, getAccessTokenQosMonitor);
            }
            else if (AadKillSwitches_1.AadKillSwitches.isRetryWithLoginHintEnabled() &&
                (!AadKillSwitches_1.AadKillSwitches.isBlockLoginHintForGuestsEnabled() ||
                    _this._defaultConfiguration.userPrincipalName) &&
                AadErrorHandler_1.AadErrorHandler._isInteractionRequired(e.message, e.errorCode) &&
                attempt < 1) {
                return _this._acquireTokenDataHelper(resourceEndpoint, ++attempt, getAccessTokenQosMonitor, true);
            }
            else {
                if (getAccessTokenQosMonitor) {
                    _this._handleAuthErrors(getAccessTokenQosMonitor, e, extraData, resourceEndpoint);
                }
                else {
                    throw e;
                }
            }
        });
    };
    MsalTokenProvider.prototype._initializeMsalJs = function () {
        var _this = this;
        var configuration;
        if (sp_core_library_1._SPFlight.isEnabled(467)) {
            configuration = {
                auth: {
                    clientId: this._defaultConfiguration.servicePrincipalId,
                    navigateToLoginRequestUrl: true,
                    redirectUri: this._defaultConfiguration.redirectUri,
                    validateAuthority: false,
                    authority: this._defaultConfiguration.aadInstanceUrl + '/' + this._defaultConfiguration.aadTenantId
                },
                system: {
                    loadFrameTimeout: 10000,
                    navigateFrameWait: 0
                }
            };
        }
        else {
            configuration = {
                auth: {
                    clientId: this._defaultConfiguration.servicePrincipalId,
                    navigateToLoginRequestUrl: false,
                    redirectUri: this._defaultConfiguration.redirectUri,
                    validateAuthority: false
                },
                system: {
                    loadFrameTimeout: 10000,
                    navigateFrameWait: 0
                }
            };
        }
        if (AadKillSwitches_1.AadKillSwitches.isAdditionalMsalTelemetryEnabled()) {
            configuration.system.telemetry = {
                applicationName: this._defaultConfiguration.servicePrincipalId,
                applicationVersion: '1.0',
                telemetryEmitter: function (events) {
                    var key = '';
                    var value = {};
                    events.forEach(function (event) {
                        if (event['msal.event_name'] === 'msal.api_event') {
                            key = event['Microsoft.MSAL.correlation_id'];
                            value = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, value), _this._requestMap.get(key)), event);
                        }
                        else if (event['msal.event_name'] === 'msal.default_event') {
                            value = tslib_1.__assign(tslib_1.__assign({}, value), { 'msal.effective_connection_speed': event['msal.effective_connection_speed'] });
                        }
                    });
                    _this._requestMap.set(key, value);
                }
            };
        }
        if (sp_core_library_1._SPFlight.isEnabled(60297)) {
            return new msal.UserAgentApplication(configuration);
        }
        else {
            return new msalLegacy.UserAgentApplication(configuration);
        }
    };
    MsalTokenProvider.prototype._generateTelemetryExtraData = function () {
        // alias is being used to detect cache hits
        // manifestId is used to save msal perf data
        return {
            alias: 'false',
            CorrelationId: sp_core_library_1.Guid.newGuid().toString(),
            isInternal: this._defaultConfiguration.servicePrincipalId === AadConstants_1.default.PRE_AUTHORIZED_APP_PRINCIPAL_ID,
            jsonExtraData: ''
        };
    };
    MsalTokenProvider.prototype._cancelRedirect = function () {
        this._redirectCancelled = true;
    };
    MsalTokenProvider.prototype._handleAuthErrors = function (monitor, error, extraData, resourceEndpoint) {
        var _this = this;
        var userAgentString = sp_core_library_1._BrowserDetection.getBrowserInformation().userAgent || '';
        // Will remove this flight check when MSAL provides an API for handling MFA.
        if (sp_core_library_1._SPFlight.isEnabled(467) /* Allow MSAL to prompt the end user for MFA errors */ &&
            AadErrorHandler_1.AadErrorHandler._isInteractionRequired(error.message, error.errorCode) &&
            sp_core_library_1._Browser.IE !== sp_core_library_1._BrowserDetection.getBrowserInformation().browser) {
            // To prevent infinite redirect loops we want to only allow 3 redirects with 1 minute
            var currDate = new Date();
            var attemptNumber = 1;
            var foundPreviousAttempt = false;
            if (AadKillSwitches_1.AadKillSwitches.isRemoveDuplicateHandleAuthErrorsCallEnabled()) {
                attemptNumber = this._getNumberOfAttemptsInLastMinute() + 1;
                if (attemptNumber > 1) {
                    foundPreviousAttempt = true;
                }
            }
            else {
                var firstRedirectTime = window.sessionStorage.getItem('msalRedirectFirstAttempTime');
                var oneMinuteInMs = 60 * 1000;
                if (firstRedirectTime) {
                    var firstRedirectDate = new Date(firstRedirectTime);
                    if (currDate.getTime() - firstRedirectDate.getTime() < oneMinuteInMs) {
                        var attemptCount = window.sessionStorage.getItem('msalRedirectAttempNumber');
                        if (attemptCount) {
                            attemptNumber = parseInt(attemptCount, 10);
                            attemptNumber++;
                            foundPreviousAttempt = true;
                        }
                    }
                }
            }
            if (!foundPreviousAttempt) {
                window.sessionStorage.setItem('msalRedirectFirstAttempTime', currDate.toString());
            }
            // We want a maxium of 6 attempts, and have already incremented from 1 for previous attempts
            if (attemptNumber < 7) {
                monitor.writeExpectedFailure(error.errorCode, error, extraData);
                window.sessionStorage.setItem('msalRedirectAttempNumber', attemptNumber.toString());
                window.sessionStorage.setItem('msalRedirectClientId', this._defaultConfiguration.servicePrincipalId);
                var msalAuthParameters = {
                    authority: this._defaultConfiguration.aadInstanceUrl + '/' + this._defaultConfiguration.aadTenantId,
                    correlationId: extraData.CorrelationId,
                    scopes: [resourceEndpoint + '/.default'],
                    state: window.location.href,
                    onRedirectNavigate: function (url) {
                        _this._redirectCancelled = false;
                        sp_core_library_1._SPEventManager.instance.raiseEvent(AadTokenProvider_1.default._onBeforeRedirectEventId, new AadTokenProvider_2.BeforeRedirectEventArgs(url, _this._cancelRedirect.bind(_this)));
                        // If we are in tab cancel the redirect.
                        if (window.sessionStorage.getItem('_isRunningTABTest') === 'true') {
                            _this._redirectCancelled = true;
                        }
                        return !_this._redirectCancelled;
                    }
                };
                if (!AadKillSwitches_1.AadKillSwitches.isBlockLoginHintForGuestsEnabled() ||
                    this._defaultConfiguration.userPrincipalName) {
                    msalAuthParameters.loginHint = this._defaultConfiguration.userPrincipalName;
                }
                if (AadKillSwitches_1.AadKillSwitches.isBlockLoginHintForGuestsEnabled() &&
                    !this._defaultConfiguration.userPrincipalName &&
                    !this._msalInstance.getAccount()) {
                    var loginAuthParameters = {
                        authority: this._defaultConfiguration.aadInstanceUrl + '/' + this._defaultConfiguration.aadTenantId,
                        correlationId: extraData.CorrelationId,
                        scopes: [resourceEndpoint + '/.default'],
                        redirectUri: this._defaultConfiguration.redirectUri,
                        state: window.location.href
                    };
                    this._msalInstance.loginRedirect(loginAuthParameters);
                }
                else {
                    this._msalInstance.acquireTokenRedirect(msalAuthParameters);
                }
            }
            else {
                monitor.writeUnexpectedFailure(error.errorCode, error, extraData);
            }
        }
        else if (AadErrorHandler_1.AadErrorHandler._doesAadErrorCodeExist(error.message, AadConstants_1.default.EXPECTED_AAD_ERRORS) ||
            userAgentString.indexOf('TabStop/1.0') > -1 // MSAL Implicit seems to have issues with test infra.
        ) {
            monitor.writeExpectedFailure(error.errorCode, error, extraData);
        }
        else {
            monitor.writeUnexpectedFailure(error.errorCode, error, extraData);
        }
        throw error;
    };
    MsalTokenProvider.prototype._isExpectedFailure = function (error) {
        var userAgentString = sp_core_library_1._BrowserDetection.getBrowserInformation().userAgent || '';
        var isTabStopTest = userAgentString.indexOf('TabStop/1.0') > -1;
        var hasMoreRetries = this._getNumberOfAttemptsInLastMinute() < 7;
        var isInteractionRequired = AadErrorHandler_1.AadErrorHandler._isInteractionRequired(error.message, error.errorCode);
        var doesAadErrorCodeExist = AadErrorHandler_1.AadErrorHandler._doesAadErrorCodeExist(error.message, AadConstants_1.default.EXPECTED_AAD_ERRORS);
        return (hasMoreRetries && isInteractionRequired) || isTabStopTest || doesAadErrorCodeExist;
    };
    MsalTokenProvider.prototype._getNumberOfAttemptsInLastMinute = function () {
        var numberOfAttempts = 0;
        var oneMinuteInMs = 60 * 1000;
        var firstRedirectTime = window.sessionStorage.getItem('msalRedirectFirstAttempTime');
        if (firstRedirectTime) {
            var currDate = new Date();
            var firstRedirectDate = new Date(firstRedirectTime);
            if (currDate.getTime() - firstRedirectDate.getTime() < oneMinuteInMs) {
                var attemptCountString = window.sessionStorage.getItem('msalRedirectAttempNumber') || '0';
                numberOfAttempts = parseInt(attemptCountString, 10);
            }
        }
        return numberOfAttempts;
    };
    return MsalTokenProvider;
}());
exports.MsalTokenProvider = MsalTokenProvider;
//# sourceMappingURL=MsalTokenProvider.js.map