cordovaibm-mobilefirstmobilefirst-cli

WL.Client.createSecurityCheckChallengeHandler is not a function


Hello im trying to run a security check in a MF8 new app (just download the cordova example app from the mf console and add the android platform), and when i tried to instantiate UserLoginChallengeHandler from app.init();

var UserLoginChallengeHandler = function() {
var isChallenged = false;
var securityCheckName = 'UserLogin';  
var objs = Object.getOwnPropertyNames(WL.App);
for(var i in objs ){
console.log(objs[i]);
}
var userLoginChallengeHandler = WL.Client.createSecurityCheckChallengeHandler(securityCheckName);

document.getElementById("login").addEventListener("click", login);
document.getElementById("logout").addEventListener("click", logout);

userLoginChallengeHandler.securityCheckName = securityCheckName;

userLoginChallengeHandler.handleChallenge = function(challenge) {
    WL.Logger.debug("handleChallenge");
    showLoginDiv();
    isChallenged = true;
    var statusMsg = "Remaining Attempts: " + challenge.remainingAttempts;
    if (challenge.errorMsg !== null){
        statusMsg = statusMsg + "<br/>" + challenge.errorMsg;
    }
    document.getElementById("statusMsg").innerHTML = statusMsg;
};

userLoginChallengeHandler.handleSuccess = function(data) {
    WL.Logger.debug("handleSuccess");
    isChallenged = false;
    document.getElementById ("rememberMe").checked = false;
    document.getElementById('username').value = "";
    document.getElementById('password').value = "";
    document.getElementById("helloUser").innerHTML = "Hello, " + data.user.displayName;
    showProtectedDiv();
};

userLoginChallengeHandler.handleFailure = function(error) {
    WL.Logger.debug("handleFailure: " + error.failure);
    isChallenged = false;
    if (error.failure !== null){
        if (error.failure == "Account blocked") {
            document.getElementById("loginDiv").style.display = "none";
            document.getElementById("blockedDiv").style.display = "block";
            document.getElementById("blockedMsg").innerHTML = "Your account is blocked. Try again later.";
        }
        alert(error.failure);
    } else {
        alert("Failed to login.");
    }
};

function login() {
    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;
    var rememberMeState = document.getElementById ("rememberMe").checked;
    if (username === "" || password === ""){
        alert("Username and password are required");
        return;
    }
    if (isChallenged){
        userLoginChallengeHandler.submitChallengeAnswer({'username':username, 'password':password, rememberMe: rememberMeState});
    } else {
        WLAuthorizationManager.login(securityCheckName,{'username':username, 'password':password, rememberMe: rememberMeState}).then(
            function () {
                WL.Logger.debug("login onSuccess");
            },
            function (response) {
                WL.Logger.debug("login onFailure: " + JSON.stringify(response));
            });
    }
}

function logout() {
WLAuthorizationManager.logout(securityCheckName).then(
    function () {
        WL.Logger.debug("logout onSuccess");
        location.reload();
    },
    function (response) {
        WL.Logger.debug("logout onFailure: " + JSON.stringify(response));
    });
}

return userLoginChallengeHandler;

};

then all the time, from my mfpdev app preview, throws this error Uncaught TypeError: WL.Client.createSecurityCheckChallengeHandler is not a function at (compiled_code)

Is there some configuration that im missing? or this method is just deprecated (because i just log all methods from WL.Client and this method is missing), and, i dont find where is all the api documentation in the knowledge center, is there any URl that im missing


Solution

  • The example app from the mf8 developer server (mfp-app-scaffolds-cordova) had the cordova-plugin-mfp with 7.1 methods, just remove all the plugin of mf and add them manually with cordova plugin add cordova-plugin-mfp