IBM Mobilefirst 8.0基于LTPA的安全检查 - 获取令牌后不称为handleSuccess方法

时间:2017-06-14 14:02:20

标签: android cordova ibm-mobilefirst mobilefirst-server

我尝试按照本教程创建基于angularjs的Cordova移动应用程序:https://mobilefirstplatform.ibmcloud.com/blog/2016/08/11/best-practices-for-building-angularjs-apps-with-mobilefirst-foundation-8.0/ 和基于LTPA的安全检查登录流程(在Mobilefirst 8.0中)基于以下样本:https://github.com/mfpdev/ldap-and-ltpa-sample

移动应用正在使用角度。授权实施:

app.factory('Auth', function ($rootScope) {

    var securityCheckName = 'LTPA',
        _$scope = null,
        challengeHandler = null,
        URL = '',

    challengeHandler = WL.Client.createSecurityCheckChallengeHandler(securityCheckName);
    challengeHandler.securityCheckName = securityCheckName;
    WLAuthorizationManager.login(securityCheckName, {'username': '', 'password': ''});

    challengeHandler.handleChallenge = function (challenge) {
        if (challenge && challenge.loginURL) {
            URL = challenge.loginURL;
        }
    };

    challengeHandler.handleSuccess = function (data) {
        // code
    };

    challengeHandler.handleFailure = function (error) {
        // code
    };

    return {
        login: function ($scope, username, password) {
            _$scope = $scope;

            var request = new WLResourceRequest(URL, WLResourceRequest.POST);
            request.send("j_username=" + username + "&j_password=" + password + "&action=Login").then(
            function(response) {
                challengeHandler.submitChallengeAnswer({});
            },
            function(error) {
              // on error
            });
        }
    };
});

这似乎仅适用于iOS。在Android handleSuccess上没有调用函数。

与过去一样,在Android设备上发送Cookie时出现问题(使用较旧的MF版本),因此我在login函数中尝试了解决方法,隐藏的InAppBrowser以登录形式打开,然后用户登录进程已经完成,一旦收到令牌,就会通过cordova-cookie-master-plugin进行设置并调用submitChallengeAnswer

login: function ($scope, username, password) {
    _$scope = $scope;

    var request = new WLResourceRequest(URL, WLResourceRequest.POST);
    request.send("j_username=" + username + "&j_password=" + password + "&action=Login").then(
    function(response) {
        if (device.platform == "iOS") {
            challengeHandler.submitChallengeAnswer({});
        } else {
            iab = cordova.InAppBrowser.open(URL, "_blank", "hidden=yes");
            iab.addEventListener('loadstop', function(event){

                iab.executeScript({code:
                    'var field1 = document.getElementsByTagName("input")[0];' +
                    'var field2 = document.getElementsByTagName("input")[1];' +
                    'field1.setAttribute("value", "' + username + '");' +
                    'field2.setAttribute("value", "' + password + '");' +
                    'document.forms[0].submit();'
                }, function(){
                    // on error
                });

                try {
                    cookieMaster.getCookieValue(URL, 'LtpaToken2', function(data) {
                        WL.Client.setCookie({
                          "name" : "LtpaToken2",
                          "value" : data.cookieValue,
                          "domain" : ".example.com",
                          "path" : "/",
                          "expires" : "Thu, 18 Dec 2999 12:00:00 UTC"
                        }).then(function() {
                            challengeHandler.submitChallengeAnswer({});
                        }).fail(function(err) {
                            // on error
                        });
                    }, function(error) {
                        // on error
                    });
                } catch(err) {
                    // on error
                }

            });

            iab.addEventListener('exit', function(){
                iab.removeEventListener('loadstop', function() { /* on success */ });
            });
        }
    },
    function(error) {
      // on error
    });
}

这个解决方案也不适合我。我希望在challengeHandler.submitChallengeAnswer()被解雇后,handleSuccess将会被调用,但是没有发生。而是调用handleChallenge

0 个答案:

没有答案