|
|
@ -16,12 +16,12 @@ if (!Accounts.saml) { |
|
|
|
|
|
|
|
|
|
|
|
const MeteorLogout = Meteor.logout; |
|
|
|
const MeteorLogout = Meteor.logout; |
|
|
|
const logoutBehaviour = { |
|
|
|
const logoutBehaviour = { |
|
|
|
TERMINATE_SAML: 'SAML', |
|
|
|
TERMINATE_SAML: "SAML", |
|
|
|
ONLY_RC: 'Local' |
|
|
|
ONLY_RC: "Local" |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Meteor.logout = function() { |
|
|
|
Meteor.logout = function () { |
|
|
|
const samlService = ServiceConfiguration.configurations.findOne({service: 'saml'}); |
|
|
|
const samlService = ServiceConfiguration.configurations.findOne({ service: 'saml' }); |
|
|
|
if (samlService) { |
|
|
|
if (samlService) { |
|
|
|
const provider = samlService.clientConfig && samlService.clientConfig.provider; |
|
|
|
const provider = samlService.clientConfig && samlService.clientConfig.provider; |
|
|
|
if (provider && samlService.logoutBehaviour === logoutBehaviour.TERMINATE_SAML) { |
|
|
|
if (provider && samlService.logoutBehaviour === logoutBehaviour.TERMINATE_SAML) { |
|
|
@ -29,24 +29,24 @@ Meteor.logout = function() { |
|
|
|
return Meteor.logoutWithSaml({ provider }); |
|
|
|
return Meteor.logoutWithSaml({ provider }); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (samlService.logoutBehaviour === logoutBehaviour.ONLY_RC) { |
|
|
|
if (samlService.logoutBehaviour === logoutBehaviour.ONLY_RC) { |
|
|
|
console.info('SAML session not terminated, only the Rocket.Chat session is going to be killed'); |
|
|
|
console.info('SAML session not terminated, only the Rocket.Chat session is going to be killed'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return MeteorLogout.apply(Meteor, arguments); |
|
|
|
return MeteorLogout.apply(Meteor, arguments); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const openCenteredPopup = function(url, width, height) { |
|
|
|
const openCenteredPopup = function (url, width, height) { |
|
|
|
let newwindow; |
|
|
|
let newwindow; |
|
|
|
|
|
|
|
|
|
|
|
if (typeof cordova !== 'undefined' && typeof cordova.InAppBrowser !== 'undefined') { |
|
|
|
if (typeof cordova !== 'undefined' && typeof cordova.InAppBrowser !== 'undefined') { |
|
|
|
newwindow = cordova.InAppBrowser.open(url, '_blank'); |
|
|
|
newwindow = cordova.InAppBrowser.open(url, '_blank'); |
|
|
|
newwindow.closed = false; |
|
|
|
newwindow.closed = false; |
|
|
|
|
|
|
|
|
|
|
|
const intervalId = setInterval(function() { |
|
|
|
const intervalId = setInterval(function () { |
|
|
|
newwindow.executeScript({ |
|
|
|
newwindow.executeScript({ |
|
|
|
'code': 'document.getElementsByTagName("script")[0].textContent' |
|
|
|
'code': 'document.getElementsByTagName("script")[0].textContent' |
|
|
|
}, function(data) { |
|
|
|
}, function (data) { |
|
|
|
if (data && data.length > 0 && data[0] === 'window.close()') { |
|
|
|
if (data && data.length > 0 && data[0] === 'window.close()') { |
|
|
|
newwindow.close(); |
|
|
|
newwindow.close(); |
|
|
|
newwindow.closed = true; |
|
|
|
newwindow.closed = true; |
|
|
@ -54,7 +54,7 @@ const openCenteredPopup = function(url, width, height) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, 100); |
|
|
|
}, 100); |
|
|
|
|
|
|
|
|
|
|
|
newwindow.addEventListener('exit', function() { |
|
|
|
newwindow.addEventListener('exit', function () { |
|
|
|
clearInterval(intervalId); |
|
|
|
clearInterval(intervalId); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -68,8 +68,8 @@ const openCenteredPopup = function(url, width, height) { |
|
|
|
// positioning the popup centered relative to the current window
|
|
|
|
// positioning the popup centered relative to the current window
|
|
|
|
const left = screenX + (outerWidth - width) / 2; |
|
|
|
const left = screenX + (outerWidth - width) / 2; |
|
|
|
const top = screenY + (outerHeight - height) / 2; |
|
|
|
const top = screenY + (outerHeight - height) / 2; |
|
|
|
const features = (`width=${ width },height=${ height |
|
|
|
const features = (`width=${width},height=${height |
|
|
|
},left=${ left },top=${ top },scrollbars=yes`);
|
|
|
|
},left=${left},top=${top},scrollbars=yes`);
|
|
|
|
|
|
|
|
|
|
|
|
newwindow = window.open(url, 'Login', features); |
|
|
|
newwindow = window.open(url, 'Login', features); |
|
|
|
if (newwindow.focus) { |
|
|
|
if (newwindow.focus) { |
|
|
@ -79,12 +79,12 @@ const openCenteredPopup = function(url, width, height) { |
|
|
|
return newwindow; |
|
|
|
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
|
|
|
|
// default dimensions that worked well for facebook and google
|
|
|
|
const popup = openCenteredPopup( |
|
|
|
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; |
|
|
|
let popupClosed; |
|
|
|
try { |
|
|
|
try { |
|
|
|
// Fix for #328 - added a second test criteria (popup.closed === undefined)
|
|
|
|
// 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 || {}; |
|
|
|
options = options || {}; |
|
|
|
const credentialToken = `id-${ Random.id() }`; |
|
|
|
const credentialToken = `id-${Random.id()}`; |
|
|
|
options.credentialToken = credentialToken; |
|
|
|
options.credentialToken = credentialToken; |
|
|
|
|
|
|
|
|
|
|
|
Accounts.saml.initiateLogin(options, function(/*error, result*/) { |
|
|
|
Accounts.saml.initiateLogin(options, function (/*error, result*/) { |
|
|
|
Accounts.callLoginMethod({ |
|
|
|
Accounts.callLoginMethod({ |
|
|
|
methodArguments: [{ |
|
|
|
methodArguments: [{ |
|
|
|
saml: true, |
|
|
|
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);
|
|
|
|
//Accounts.saml.idpInitiatedSLO(options, callback);
|
|
|
|
Meteor.call('samlLogout', options.provider, function(err, result) { |
|
|
|
Meteor.call('samlLogout', options.provider, function (err, result) { |
|
|
|
if (err || !result) { |
|
|
|
if (err || !result) { |
|
|
|
MeteorLogout.apply(Meteor); |
|
|
|
MeteorLogout.apply(Meteor); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// A nasty bounce: 'result' has the SAML LogoutRequest but we need a proper 302 to redirected from the server.
|
|
|
|
// 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='+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)}`)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|