WL.Client.createSecurityCheckChallengeHandler 不是函数

WL.Client.createSecurityCheckChallengeHandler is not a function

你好,我正在尝试 运行 在 MF8 新应用程序中进行安全检查(只需从 mf 控制台下载 cordova 示例应用程序并添加 android 平台),当我尝试实例化时来自 app.init();

的 UserLoginChallengeHandler
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;

};

然后一直从我的 mfpdev 应用程序预览中抛出此错误 未捕获的类型错误:WL.Client.createSecurityCheckChallengeHandler 不是 (compiled_code)

处的函数

我是否缺少某些配置?或者这个方法刚刚被弃用(因为我只记录了 WL.Client 中的所有方法并且这个方法丢失了),而且,我没有找到知识中心的所有 api 文档在哪里,是否有任何 URl 我失踪了

  1. 如果尝试使用 CLI 预览功能在浏览器中预览应用程序,则 OAuth 流程目前将不起作用。现在使用模拟器或物理设备

  2. 不清楚您下载的是哪个样本。现在控制台中的示例看起来像您的代码。这是什么?

  3. 假设这是一个 Cordova 示例,您需要从 wlCommonInit 函数调用 API

  4. 你读过任何教程吗? https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/all-tutorials/

您必须删除核心SDK插件并重新安装才能获得最新版本。 从项目的根文件夹:

  1. cordova 插件删除 cordova-plugin-mfp
  2. cordova 插件添加 cordova-plugin-mfp

来自 mf8 开发人员服务器 (mfp-app-scaffolds-cordova) 的示例应用程序具有带有 7.1 方法的 cordova-plugin-mfp,只需删除 mf 的所有插件并使用 cordova plugin add cordova- 手动添加它们插件-mfp

请参考link https://github.com/MobileFirst-Platform-Developer-Center/PinCodeCordova/blob/98f8f38bf7dbdc30b8c8b9837a9b826e44f15926/www/js/ChallengeHandler.js

示例使用

WL.Client.createWLChallengeHandler("PinCodeAttempts")

而不是

WL.Client.createSecurityCheckChallengeHandler("PinCodeAttempts")