Worklight, передающий учетные данные для входа на серверный контент iframed

Вот сценарий:

Worklight studio 6.2 с областью аутентификации Worklight Server и Webseal.

Я занимаюсь разработкой гибридного приложения, для которого требуется вход в систему (уже настроенный и работающий), а затем отправка в iframe с содержимым на стороне сервера (форум). Я следовал инструкциям ibm worklight для обработчика аутентификации, который работает просто отлично.

Проблема заключается в том, что после того, как моя страница аутентификации была представлена ​​и пользователь ввел свои учетные данные, вход в систему будет успешным, но в фрейме появится новая страница входа (веб-страница). Поэтому в основном мне нужно отправить эти учетные данные в iframe, чтобы избежать избыточности.

Обработчик аутентификации:

var REALM_HTTPHEADER = 'HeaderAuthRealm';
var LOGIN_FORM_TAM = 'pkmslogin.form';
function showLoginScreen() {

$.mobile.changePage("#authPage");
}
function showMainScreen() {
$.mobile.changePage("#forum");
}
var websealRealmChallengeHandler =
WL.Client.createChallengeHandler(REALM_HTTPHEADER);
var lastRequestURL;
websealRealmChallengeHandler.isCustomResponse = function(response) {
//A normal login form has been returned.
var findLoginForm = response.responseText.search("pkmslogin.form");
if (findLoginForm >= 0) {
lastRequestURL = response.request.url;
return true;
}
//Need to also check for errors and handle as appropriate
//This response is a worklight server response, handle it normally
return false;
};
websealRealmChallengeHandler.handleChallenge = function(response) {
showLoginScreen();
};
websealRealmChallengeHandler.handleFailure = function(response) {
console.log("Error during WebSEAL authentication.");
};


websealRealmChallengeHandler.submitLoginFormCallback = function(response) {
var isCustom = websealRealmChallengeHandler.isCustomResponse(response);
if (isCustom) {
websealRealmChallengeHandler.handleChallenge(response);
}
else {
//hide the login screen, we are logged in
showMainScreen();
websealRealmChallengeHandler.submitSuccess();
}
};
$("#loginButton").click(function(){
var reqURL = "/../../../" + LOGIN_FORM_TAM;
var options = {method: "POST"};
options.parameters = {
Username : $("#username").val(),
password : $("#password").val(),
"login-form-type" : "pwd"
};
options.headers = {};
websealRealmChallengeHandler.submitLoginForm(reqURL, options,
websealRealmChallengeHandler.submitLoginFormCallback);
}
);

main.js:

function wlCommonInit(){
    /*
     * Use of WL.Client.connect() API before any connectivity to a Worklight Server is required. 
     * This API should be called only once, before any other WL.Client methods that communicate with the Worklight Server.
     * Don't forget to specify and implement onSuccess and onFailure callback functions for WL.Client.connect(), e.g:
     *    
     *    WL.Client.connect({
     *          onSuccess: onConnectSuccess,
     *          onFailure: onConnectFailure
     *    });
     *     
     */

    // Common initialization code goes here
    WL.Client.connect();


}

$(document).on("pagecreate", "#forum", function() {
    if (!$("#forumFrame").length ) {
         $("<iframe id=\"forumFrame\" src='https://mysite.something.it/forum/' style='height: 100%; width: 100%' seamless/>").appendTo("#wrapper");

    }
});

index.html:

<!DOCTYPE HTML>
<html>
        <head>
            <meta charset="UTF-8">
            <title>forum_sigillo</title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
            <!--
                <link rel="shortcut icon" href="images/favicon.png">
                <link rel="apple-touch-icon" href="images/apple-touch-icon.png"> 
            -->
            <link href="jqueryMobile/jquery.mobile-1.4.3.css" rel="stylesheet">
            <link rel="stylesheet" href="css/main.css">
            <script>window.$ = window.jQuery = WLJQ;</script>
            <script src="jqueryMobile/jquery-1.11.1.js"></script>
        </head>
        <body style="display: none;">

            <div data-role="page" id="forum">


        <div id="wrapper">


        </div>

        </div>

   <div data-role="page" id="authPage">

    <div data-role="header" id="header1" data-position="fixed" data-tap="toggle">
                <h3 style="font-family: Verdana; text-align: center; color: white">LOGIN</h3>
            </div>

<div data-role="content" id="loginContent" style="padding: 0px; padding-top: 15px;">



            <label for="username" style="color: white; text-align: center">Username</label><input type="text" name="text"
                id="username" style="text-align:center; width: 100%">

             <label for="password" style="color: white; text-align: center">Password</label><input type="password"
                name="text0" id="password" style="text-align:center; width: 100%"> <br>

                 <a href="#" data-role="button" id="loginButton" style="text-align: center; color: white">Login</a>

        </div>

</div>
            <script src="js/AuthenticationHandler.js"></script>
            <script src="js/initOptions.js"></script>
            <script src="js/main.js"></script>
            <script src="js/messages.js"></script>
            <script src="jqueryMobile/jquery.mobile-1.4.3.js"></script>
        </body>
</html>

1 ответ

Я склонен согласиться с тем, что написано во втором ответе, здесь: Совместное использование глобальной переменной javascript страницы с помощью iframe на этой странице

Альтернатива, как предложено, - междоменный обмен сообщениями: http://blog.teamtreehouse.com/cross-domain-messaging-with-postmessage

Но это никогда не делалось в приложении Worklight, о котором я знаю.

Другие вопросы по тегам