From 79d4dbf0cffbe278bb93c10ff2fdd0a8ab8d6c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20J=C3=A4gle?= Date: Fri, 2 Feb 2018 12:54:07 +0100 Subject: [PATCH] Fix logout for non-saml-accounts --- packages/meteor-accounts-saml/saml_client.js | 46 ++++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/meteor-accounts-saml/saml_client.js b/packages/meteor-accounts-saml/saml_client.js index dc8a7110ee1..d6ce6795d94 100644 --- a/packages/meteor-accounts-saml/saml_client.js +++ b/packages/meteor-accounts-saml/saml_client.js @@ -16,12 +16,12 @@ if (!Accounts.saml) { const MeteorLogout = Meteor.logout; const logoutBehaviour = { - TERMINATE_SAML: 'SAML', - ONLY_RC: 'Local' -}; + TERMINATE_SAML: "SAML", + ONLY_RC: "Local" +} -Meteor.logout = function() { - const samlService = ServiceConfiguration.configurations.findOne({service: 'saml'}); +Meteor.logout = function () { + const samlService = ServiceConfiguration.configurations.findOne({ service: 'saml' }); if (samlService) { const provider = samlService.clientConfig && samlService.clientConfig.provider; if (provider && samlService.logoutBehaviour === logoutBehaviour.TERMINATE_SAML) { @@ -29,24 +29,24 @@ Meteor.logout = function() { return Meteor.logoutWithSaml({ provider }); } } - } - if (samlService.logoutBehaviour === logoutBehaviour.ONLY_RC) { - console.info('SAML session not terminated, only the Rocket.Chat session is going to be killed'); + if (samlService.logoutBehaviour === logoutBehaviour.ONLY_RC) { + console.info('SAML session not terminated, only the Rocket.Chat session is going to be killed'); + } } return MeteorLogout.apply(Meteor, arguments); }; -const openCenteredPopup = function(url, width, height) { +const openCenteredPopup = function (url, width, height) { let newwindow; if (typeof cordova !== 'undefined' && typeof cordova.InAppBrowser !== 'undefined') { newwindow = cordova.InAppBrowser.open(url, '_blank'); newwindow.closed = false; - const intervalId = setInterval(function() { + const intervalId = setInterval(function () { newwindow.executeScript({ 'code': 'document.getElementsByTagName("script")[0].textContent' - }, function(data) { + }, function (data) { if (data && data.length > 0 && data[0] === 'window.close()') { newwindow.close(); newwindow.closed = true; @@ -54,7 +54,7 @@ const openCenteredPopup = function(url, width, height) { }); }, 100); - newwindow.addEventListener('exit', function() { + newwindow.addEventListener('exit', function () { clearInterval(intervalId); }); } else { @@ -68,8 +68,8 @@ const openCenteredPopup = function(url, width, height) { // positioning the popup centered relative to the current window const left = screenX + (outerWidth - width) / 2; const top = screenY + (outerHeight - height) / 2; - const features = (`width=${ width },height=${ height - },left=${ left },top=${ top },scrollbars=yes`); + const features = (`width=${width},height=${height + },left=${left},top=${top},scrollbars=yes`); newwindow = window.open(url, 'Login', features); if (newwindow.focus) { @@ -79,12 +79,12 @@ const openCenteredPopup = function(url, width, height) { return newwindow; }; -Accounts.saml.initiateLogin = function(options, callback, dimensions) { +Accounts.saml.initiateLogin = function (options, callback, dimensions) { // default dimensions that worked well for facebook and google const popup = openCenteredPopup( - Meteor.absoluteUrl(`_saml/authorize/${ options.provider }/${ options.credentialToken }`), (dimensions && dimensions.width) || 650, (dimensions && dimensions.height) || 500); + Meteor.absoluteUrl(`_saml/authorize/${options.provider}/${options.credentialToken}`), (dimensions && dimensions.width) || 650, (dimensions && dimensions.height) || 500); - const checkPopupOpen = setInterval(function() { + const checkPopupOpen = setInterval(function () { let popupClosed; try { // Fix for #328 - added a second test criteria (popup.closed === undefined) @@ -107,12 +107,12 @@ Accounts.saml.initiateLogin = function(options, callback, dimensions) { }; -Meteor.loginWithSaml = function(options, callback) { +Meteor.loginWithSaml = function (options, callback) { options = options || {}; - const credentialToken = `id-${ Random.id() }`; + const credentialToken = `id-${Random.id()}`; options.credentialToken = credentialToken; - Accounts.saml.initiateLogin(options, function(/*error, result*/) { + Accounts.saml.initiateLogin(options, function (/*error, result*/) { Accounts.callLoginMethod({ methodArguments: [{ saml: true, @@ -123,15 +123,15 @@ Meteor.loginWithSaml = function(options, callback) { }); }; -Meteor.logoutWithSaml = function(options/*, callback*/) { +Meteor.logoutWithSaml = function (options/*, callback*/) { //Accounts.saml.idpInitiatedSLO(options, callback); - Meteor.call('samlLogout', options.provider, function(err, result) { + Meteor.call('samlLogout', options.provider, function (err, result) { if (err || !result) { MeteorLogout.apply(Meteor); return; } // A nasty bounce: 'result' has the SAML LogoutRequest but we need a proper 302 to redirected from the server. //window.location.replace(Meteor.absoluteUrl('_saml/sloRedirect/' + options.provider + '/?redirect='+result)); - window.location.replace(Meteor.absoluteUrl(`_saml/sloRedirect/${ options.provider }/?redirect=${ encodeURIComponent(result) }`)); + window.location.replace(Meteor.absoluteUrl(`_saml/sloRedirect/${options.provider}/?redirect=${encodeURIComponent(result)}`)); }); };