Hybrid app: remember login in after SAML login

I have implemented a SAML login in a hybrid app. However, I cannot get the autologin functionality to work, as is also mentioned in this forum post. As an alternative I tried to set a cookie with this code: samlWindow.executeScript({ code: "document.cookie;" }, function(values) { var token = (values + ';').match(new RegExp("AUTH_TOKEN=(.*);"))[1]; window.localStorage.setItem("mx-authtoken", token); samlWindow.close(); if(window.mx.afterLoginAction) { window.mx.afterLoginAction(); } else { console.log("startup"); } }); The cookie is unfortunately also not created. Does anyone have a working way to keep a user logged in in a hybrid app? Ideally while keeping the sessions non persistent.
3 answers

Since I've received a number of requests for the code we've used, see below. This can be referred to from the index.html.


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");

                        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")

                        if (window.mx.afterLoginAction) {
                        } else {


            samlWindow.addEventListener("loadstop", cb);
        window.dojoConfig.ui.customLoginFn = samlLogin;



Not sure if it is related, but we are also having login trouble with the new functionality. In our case we found out that the problems arise when the username used in the hybrid app are different to what is finally used in the server login logic. To be more precise we add a specific multitenancy prefix on the server side so that your user name becomes "PrefixRalph" depending on de URL you use to reach the application. Then it fails to create a correct token in both 6.8 and 6.9.

Maybe you are running into a similar problem. I am already in contact with Mendix on our specific issue, but will let you know one we find the exact fix for the problem.


Hello Remco, Did you get it working with iOS mobile app? If yes can you share your solution. I am trying to open App B from App A on hybrid iOS and SAML token is not getting stored. With the current implementation User has to enter password each time he/she navigates to a different app from parent hybrid iOS app.