Lucky you, we have spent quite some blood, sweat and tears creating this beauty together with Danny Roest from Expert Services:
mxMobile.enableSamlLogin = function() {
var register = function(){
var samlLogin = function() {
console.log("Start SAML login");
var samlWindow = cordova.InAppBrowser.open(window.mx.remoteUrl + "SSO/", "_blank", "location=no,toolbar=no");
var cb = function(event) {
if (event.url.indexOf(window.mx.remoteUrl) == 0 && event.url.indexOf("SSO") == -1) {
console.log("User redirected to app")
//make sure this is only called once
samlWindow.removeEventListener("loadstop", cb);
console.log("Removed event listener");
samlWindow.executeScript({
code: "document.cookie;"
}, function(values) {
var value = values[0] + ";";
value = value.substring("AUTH_TOKEN=".length);
var token = value.substring(0, value.indexOf(";"));
console.log("token: " + token)
//var token = value.substring("AUTH_TOKEN=".length, value.indexOf(";"));
window.localStorage.setItem("mx-authtoken", token);
console.log("Closing window")
samlWindow.close();
if (window.mx.afterLoginAction) {
window.mx.afterLoginAction();
} else {
console.log("startup");
}
});
};
}
samlWindow.addEventListener("loadstop", cb);
}
window.dojoConfig.ui.customLoginFn = samlLogin;
}
mxMobile.waitForDojoConfig(register);
}
mxMobile.waitFor = function(fnCondition, succesCallback, errorCallBack, timeoutMs, interval) {
var waitTime = 0;
var id = setInterval(function() {
waitTime += interval;
if (waitTime > timeoutMs) {
clearInterval(id);
errorCallBack();
return;
}
if (fnCondition()) {
clearInterval(id);
succesCallback();
return;
}
}, interval);
}
mxMobile.waitForDojoConfig = function(fnCallback) {
mxMobile.waitFor(function() {
return window.dojoConfig;
}, function() {
console.log("dojoConfig available");
fnCallback();
}, function() {
console.log("dojoConfig not created");
}, 60000, 10);
}