简体   繁体   English

成功进行IMC身份验证后,Worklight身份验证错误401

[英]Worklight authentication error 401 after successfully IMC authentication

I used this code to pass the IMC server and authenticate my WL 6.2 server ( WL server does not require any authentication ). 我使用此代码来传递IMC服务器并验证我的WL 6.2服务器(WL服务器不需要任何身份验证)。

PADMAppRealmChallengeHandler.loginToImc = function (userid, password) { PADMAppRealmChallengeHandler.loginToImc =函数(用户名,密码){

PADMAppRealmChallengeHandler.writeMessage("Authenticating with w3 IMC server ...");
PADMAppRealmChallengeHandler.writeMessage("Called loginToImc ...");

if (byPassIMC)
{

}
else
{
    base64uid = window.btoa(userid + ":" + password);

    // var WgSessionKey = WLJQ.cookie("WgSessionKey");
    alert("Cookies are: " + document.cookie );
    // alert("WgSessionKey=" + WgSessionKey);
    WLJQ.ajax({
        url: IMCURL,
        method: "get",
        async: false,
        cache : false, 
        crossDomain  : true ,
        headers : {
            "Authorization": "Basic " + base64uid 
            //,  "Cookie" : "WgSessionKey=XXXXX"
        },
        dataType: "text",
        error: function(jqXHR, status, error) {
            console.log("status =" + status + " error=" + error);
            console.log(jqXHR);
            console.log("AllResponseHeaders");
            console.log("================================");
            console.log( jqXHR.getAllResponseHeaders() );
            PADMAppRealmChallengeHandler.writeError("Failed to authenticate. Please try again later");
            console.log("============== error responseText ==================");
            console.log( jqXHR.responseText);
            console.log("================================");

            PADMAppRealmChallengeHandler.setBusy(false);
        },
        timeout: 12000,
        success : function(data, textStatus, jqXHR) {
            console.log("================================");
            PADMAppRealmChallengeHandler.writeMessage("IMC SUCC ");
            console.log("================================");

            console.log(jqXHR);
            console.log("AllResponseHeaders");
            console.log("================================");
            console.log( jqXHR.getAllResponseHeaders() );
            console.log(data);
            console.log("================================");


            var SetCookies = jqXHR.getResponseHeader('Set-Cookie');
            // alert("SetCookies=" + SetCookies );


            console.log("============== success responseText ==================");
            console.log( jqXHR.responseText);
            console.log("================================");

            // if (data == "Success!!") 
            if (data) 
            {
                var options = 
                {
                        onSuccess: function(e)
                        {
                            PADMAppRealmChallengeHandler.writeMessage("Workligth Connect + IMC SUCC ");
                            PADMAppRealmChallengeHandler.writeMessage(JSON.stringify(e));
                            PADMAppRealmChallengeHandler.setBusy(false);
                            return;
                        },
                        onFailure: function(e)
                        {

                            PADMAppRealmChallengeHandler.writeError("Failed to authenticate with Worklight. Please try again later");
                            PADMAppRealmChallengeHandler.setBusy(false);
                            alert("Error with Workligth server " + JSON.stringify(e));
                        }
                };

                console.log("Run WL.Client.connect(options); ");
                WL.Client.connect(options);
            } else {
                PADMAppRealmChallengeHandler.writeError("The user ID or password entered is incorrect");
                alert("Failed to login on IMC server, verify your user and/or password please !!");
                PADMAppRealmChallengeHandler.setBusy(false);
            }
        }
    });

}

}; };

after the a good ajax get request, the WL.client.connect() request is reject by IMC , error 401 .. unauthenticate. 在一个好的ajax获取请求之后,IMC将拒绝WL.client.connect()请求,错误401 ..不进行身份验证。

The issue happens on 问题发生在

WL Studio | WL Studio | Android | Android | iOS iOS版

v6.3 | v6.3 | Error 401 | 错误401 | not tested 未经测试

v6.2 | v6.2 | Error 410 | 错误410 | WORKS ! 作品!

v6.1 | v6.1 | WOKRS | WOKRS | not tested 未经测试

v5.X | v5.X | WORKS | 作品| not tested 未经测试

It seems the issue is due the fact the Set-Cookie WgSessionKey is not capture by the WL framework. 似乎该问题是由于WL框架未捕获Set-Cookie WgSessionKey造成的。 It happens only on Android. 它仅在Android上发生。 It seems a bug introduced on WL 6.2 on Android 似乎是Android的WL 6.2上引入的错误

In Worklight 6.2 there is no publically supported way of accessing the Android cookie store. 在Worklight 6.2中,没有公开支持的访问Android Cookie存储的方法。 This is a known limitation of the platform. 这是平台的已知限制。

An alternative, undocumented, unsupported , method was provided to the user in order to over the problem: 为了解决该问题,向用户提供了另一种未记录, 不受支持的方法:
var req=new WLJSX.Ajax.WLRequest( ... instead of WLJQ.ajax({ ... var req=new WLJSX.Ajax.WLRequest( ...而不是WLJQ.ajax({ ...

The plan is to add proper Android cookie store support via public API in a future release. 该计划是在将来的版本中通过公共API添加适当的Android cookie存储支持。 It will then be possible to inject anything needed... 这样就可以注入所需的任何东西了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM