1

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

user2449016
  • 169
  • 1
  • 13

4 Answers4

2

You have to remove the core SDK plugin and reinstall to obtain the last version. From the root folder of your project:

  1. cordova plugin remove cordova-plugin-mfp
  2. cordova plugin add cordova-plugin-mfp
Stefano
  • 39
  • 1
  • 8
1

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

user2449016
  • 169
  • 1
  • 13
0
  1. The OAuth flow currently will not work if trying to preview the app in the browser using the CLI preview function. For now use an emulator or physical device

  2. It is not clear which sample you've download. Now sample from the console looks like your code. What is this?

  3. Assuming this is a Cordova sample, you need to call the APIs from the wlCommonInit function

  4. Have you read any of the tutorial? https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/all-tutorials/

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • 1. ive run the app with cordova run android too 2. the code app is from the cordova example from the mf console, and from the https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/user-authentication/javascript/ 3. just call the var userLoginChallengeHandler = new UserLoginChallengeHandler() from wlCommonInit 4. yes i had read the tutorials – user2449016 Jul 19 '16 at 18:06
  • and throws WL.Client.__onWlInitComplete is not a function too – user2449016 Jul 19 '16 at 18:22
-2

Please refer to the link https://github.com/MobileFirst-Platform-Developer-Center/PinCodeCordova/blob/98f8f38bf7dbdc30b8c8b9837a9b826e44f15926/www/js/ChallengeHandler.js

The example uses

WL.Client.createWLChallengeHandler("PinCodeAttempts")

instead of

WL.Client.createSecurityCheckChallengeHandler("PinCodeAttempts")
J. Chomel
  • 8,193
  • 15
  • 41
  • 69
  • 1
    That's an old version of it. The ...createSecurityCheck... should be used as that's the updated API. – Idan Adar Sep 26 '16 at 14:04
  • Remove your current cordova-plugin-mfp and re-add it. – Idan Adar Sep 27 '16 at 11:04
  • How do I get the updated API? I have logged into the Mobile First Operations Console. Navigated Actions -> Download Samples and downloaded the Cordova sample from there. I have added platform ios to it. To this I have added the UserLoginChallengeHandler.js file. I get WL.Client.createSecurityCheckChallengeHandler as undefined while WL.Client.createWLChallengeHandler works. 'mfpdev --v' gives '8.0.0-2016070716'. 'cordova plugin list' gives 'cordova-plugin-mfp 8.0.2016040814 "IBM MobileFirst Platform Foundation"'. I have tried removing and again adding the 'cordova-plugin-mfp' plugin – Mickelle Dsouza Sep 27 '16 at 11:13
  • Okay, so you're downloading and installing the CLI and the SDKs from the DevKit. What you get from the devkit is true and up to date only for that build of the DevKit. You need to either download an updated Devkit build, which will contain newer resources, or opt to NOT USE the resources available from the DevKit (which are, again, only true and up to date for That Specific Build of the DevKit) and instead install the CLI directly from NPM which means you'll use the latest available build. Also, by installing the Cordova plug-in using the Cordova CLI, this too will get the latest build – Idan Adar Sep 27 '16 at 11:17
  • Thanks. running 'npm install -g mfpdev-cli' followed by 'cordova plugin remove cordova-plugin-mfp' and 'cordova plugin add cordova-plugin-mfp' worked for me. Now the mfpdev -v shows '8.0.0-2016080322' – Mickelle Dsouza Sep 28 '16 at 08:01