Skip to content

Commit

Permalink
Merge pull request #3407 from RocketChat/cordova-saml
Browse files Browse the repository at this point in the history
Fix #2028 SSO redirect issue with iOS native client
  • Loading branch information
engelgabriel committed May 30, 2016
2 parents 0a09f5b + 99d405f commit 0cebe25
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions packages/meteor-accounts-saml/saml_client.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
/* globals cordova */

if (!Accounts.saml) {
Accounts.saml = {};
}

var openCenteredPopup = function(url, width, height) {
var screenX = typeof window.screenX !== 'undefined' ? window.screenX : window.screenLeft;
var screenY = typeof window.screenY !== 'undefined' ? window.screenY : window.screenTop;
var outerWidth = typeof window.outerWidth !== 'undefined' ? window.outerWidth : document.body.clientWidth;
var outerHeight = typeof window.outerHeight !== 'undefined' ? window.outerHeight : (document.body.clientHeight - 22);
// XXX what is the 22?
var newwindow;

if (typeof cordova !== 'undefined' && typeof cordova.InAppBrowser !== 'undefined') {
newwindow = cordova.InAppBrowser.open(url, '_blank');
newwindow.closed = false;

var intervalId = setInterval(function() {
newwindow.executeScript({
'code': 'document.getElementsByTagName("script")[0].textContent'
}, function(data) {
if (data && data.length > 0 && data[0] === 'window.close()') {
newwindow.close();
newwindow.closed = true;
}
});
}, 100);

// Use `outerWidth - width` and `outerHeight - height` for help in
// positioning the popup centered relative to the current window
var left = screenX + (outerWidth - width) / 2;
var top = screenY + (outerHeight - height) / 2;
var features = ('width=' + width + ',height=' + height +
',left=' + left + ',top=' + top + ',scrollbars=yes');
newwindow.addEventListener('exit', function() {
clearInterval(intervalId);
});
} else {
var screenX = typeof window.screenX !== 'undefined' ? window.screenX : window.screenLeft;
var screenY = typeof window.screenY !== 'undefined' ? window.screenY : window.screenTop;
var outerWidth = typeof window.outerWidth !== 'undefined' ? window.outerWidth : document.body.clientWidth;
var outerHeight = typeof window.outerHeight !== 'undefined' ? window.outerHeight : (document.body.clientHeight - 22);
// XXX what is the 22?

// Use `outerWidth - width` and `outerHeight - height` for help in
// positioning the popup centered relative to the current window
var left = screenX + (outerWidth - width) / 2;
var top = screenY + (outerHeight - height) / 2;
var features = ('width=' + width + ',height=' + height +
',left=' + left + ',top=' + top + ',scrollbars=yes');

var newwindow = window.open(url, 'Login', features);
if (newwindow.focus) {
newwindow.focus();
newwindow = window.open(url, 'Login', features);
if (newwindow.focus) {
newwindow.focus();
}
}
return newwindow;
};
Expand Down Expand Up @@ -72,6 +96,6 @@ Meteor.logoutWithSaml = function(options/*, callback*/) {
console.log('LOC ' + result);
// 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)));
});
};

0 comments on commit 0cebe25

Please sign in to comment.