123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Glass
- * (C) Copyright IBM Corp. 2017, 2022
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- require(['baglass/app/AppController', 'caglass/ajax/CAAuthentication', 'baglass/nls/StringResources', 'baglass/core-client/js/core-client/utils/UrlUtils', 'caglass/utils/CAUtils', 'baglass/core-client/js/core-client/utils/BrowserUtils', 'caglass/ajax/PrepareRequest', 'caglass/ajax/HandleError', 'caglass/ajax/HandleResponse', 'underscore', 'jquery', 'jquery-ui', 'jquery-bbq', 'promise'], function (AppController, CAAuthentication, StringResources, urlUtils, CAUtils, BrowserUtils, PrepareRequest, HandleError, HandleResponse, _, $) {
- var appController = new AppController({
- '$rootPane': $('#main')
- });
- window.__glassAppController = appController;
- var glassContext = appController.glassContext;
- var ajaxSrv = appController.glassContext.getCoreSvc('.Ajax');
- ajaxSrv.addRequestHandler(new PrepareRequest(glassContext));
- ajaxSrv.setErrorHandler(new HandleError(glassContext));
- ajaxSrv.addResponseHandler(new HandleResponse(glassContext));
- var caAuthentication = new CAAuthentication();
- var state = {};
- try {
- state = JSON.parse(urlUtils.base64Decode(_.unescape($('#authState').text())));
- } catch (error) {
- appController.glassContext.getCoreSvc('.Logger').error('Cannot parse state', error);
- }
- if (state.skipCALogin === true) {
- window.opener.postMessage({
- data: {}
- }, window.location.origin);
- } else {
- state.code = _.unescape($('#authCode').text());
- caAuthentication.submitLoginTokens(appController.glassContext, state).then(function (result) {
- return doPostLoginRedirect(result, state, appController);
- })["catch"](function (error) {
- appController.glassContext.getCoreSvc('.Logger').error('Cannot login, reached dead end ', error);
- var resolvedErrorString = StringResources.get('unableLogin');
- var loginErrorDialogCallback = function loginErrorDialogCallback() {
- appController.glassContext.getCoreSvc('.Logger').error('dialog closing callback during login dead end');
- return doPostLoginRedirect(error, state, appController);
- };
- if (error.jqXHR && error.jqXHR.responseJSON && error.jqXHR.responseJSON.errorCodeString === 'camAuthUnrecoverable') {
- resolvedErrorString = '';
- if (error.jqXHR.responseJSON.promptInfo && error.jqXHR.responseJSON.promptInfo.captions) {
- var promptInfoCaptions = error.jqXHR.responseJSON.promptInfo.captions;
- for (var i = 0; i < promptInfoCaptions.length; ++i) {
- resolvedErrorString += promptInfoCaptions[i];
- }
- }
- showErrorMessage(resolvedErrorString, StringResources.get('CALoginAuthError'), loginErrorDialogCallback, true);
- } else {
- showErrorMessage(resolvedErrorString, StringResources.get('CALoginAuthError'), loginErrorDialogCallback);
- }
- });
- }
- var showErrorMessage = function showErrorMessage(error, title, callback, htmlContent) {
- var mobileService = glassContext.getSvcSync('.MobileCompleteAuthentication');
- if (state.isMobile && mobileService) {
- mobileService.onError(error);
- return;
- }
- appController.showErrorMessage(error, title, callback, htmlContent);
- };
- var isUpdateDCO = function isUpdateDCO() {
- return appController.glassContext.getCoreSvc('.Config').getConfigValue('Glass.digitalContextEnabled');
- };
- var postMessageToOriginalBrowserTab = function postMessageToOriginalBrowserTab(result, appController) {
- if (BrowserUtils.isIE()) {
- try {
- // IE11 postMessage doesn't work if the domains are different.
- // To work around this, we return the data via localStorage
- // which triggers a StorageEvent that the parent window can listen to.
- window.localStorage['externalLoginResult'] = JSON.stringify(result.data);
- setTimeout(function () {
- window.close();
- }, 1000);
- } catch (err) {
- appController.glassContext.getCoreSvc('.Logger').error(err);
- if (window.opener) {
- // One last try if localStorage is disabled...
- window.opener.postMessage(result.data, window.location.origin);
- }
- }
- } else {
- window.opener.postMessage(result.data, window.location.origin);
- }
- };
- var redirectUsingSameBrowserTab = function redirectUsingSameBrowserTab(state) {
- var mobileService = glassContext.getSvcSync('.MobileCompleteAuthentication');
- state.redirectUrl = CAUtils.removeCAMNamespaceHref(state.redirectUrl);
- state.redirectUrl = CAUtils.addUpdateDcoToQuerystring(state.redirectUrl, state.updatedco);
- if (state.isMobile && mobileService) {
- mobileService.onSuccess();
- return;
- }
- var targetWindow = glassContext.window || window;
- targetWindow.location = state.redirectUrl;
- }; // result can be a 200 response object or an error object. We pass either on to the original browser tab
- var doPostLoginRedirect = function doPostLoginRedirect(result, state, appController) {
- return isUpdateDCO().then(function (isDcoConfig) {
- if (_typeof(result) == Error) {
- result.data = false;
- }
- if (state.newWindow === true) {
- result.data = _.extend({
- updatedco: isDcoConfig
- });
- return postMessageToOriginalBrowserTab(result, appController);
- } else if (state.redirectUrl) {
- // Use same window
- state.updatedco = isDcoConfig;
- return redirectUsingSameBrowserTab(state);
- } else {
- appController.glassContext.getCoreSvc('.Logger').error('redirect fallback');
- window.location = window.location.origin;
- }
- });
- };
- });
- //# sourceMappingURL=CompleteAuthentication.js.map
|