IBM Worklight:WL.Client.getUserName无法在身份验证后立即检索userIdentity [英] IBM Worklight : WL.Client.getUserName Fails to retrieve userIdentity immediately after authentication

查看:107
本文介绍了IBM Worklight:WL.Client.getUserName无法在身份验证后立即检索userIdentity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了基于适配器的身份验证,身份验证没有问题,而且运行正常。我在遇到活跃用户身份问题时遇到了一些问题。代码可能会向您解释一下

I have done adapter based authentication and there is no problem in authentication and it works fine. I have faced some issues in getting the active users useridentity.The code may explain you a bit more

adapterAuthRealmChallengeHandler.handleChallenge = function(response){
    var authRequired = response.responseJSON.authRequired;
    if (authRequired == true){
        if (response.responseJSON.errorMessage)
            alert(response.responseJSON.errorMessage);
    } else if (authRequired == false){
        adapterAuthRealmChallengeHandler.submitSuccess();
        setTimeout(function(){pageTransitionCall();},10000); //this code only works 
            pageTransitionCall(); //This throws null error in console
    }   
};
function pageTransitionCall(){
    console.log(WL.Client.getUserName("AdapterAuthRealm"));
}

正如你所看到的,我试图获得领域的活跃用户名。 WL.Client.getUserName(AdapterAuthRealm)仅在一段时间间隔后才有效,我不确定时间间隔。通过适配器代码如下所示

As you can see i was trying to get the active userName of the realm. The WL.Client.getUserName("AdapterAuthRealm") only works after some time interval only and i am not sure about the time interval. By adapter code is as below

function submitAuthentication(username, password,userCred){
    if (username==="worklight" && password === "worklight"){
        WL.Logger.info("if");
            var userIdentity = {
                    userId: userCred,
                    displayName: userCred,
                    attributes: {
                        foo: "bar"
                    },
                    loginName : userCred,
                    userName : userCred
            };
            WL.Server.setActiveUser("AdapterAuthRealm", userIdentity);
            WL.Logger.info(JSON.stringify(userIdentity));
            return { 
                authRequired: false 
            };
        }
    else
    {
        WL.Logger.info("else");
        return onAuthRequired(null, "Invalid login credentials");
    }
}

我怀疑为什么客户端无法检索到活动用户。并且我确信我的代码是正确的并且活动用户已设置,我可以在服务器日志中看到。在 setactvieruser 设置后,我只有在adpter中返回false 以及为什么客户端无法立即检索用户以及为什么需要延迟检索。我已经在Worklight V6.0和Worklight V6.1.i中验证了Ipad环境。

My doubt is why does the client cant retrieve the activeuser. And i am sure that my code is correct and active user is set and i can see in the server log.After the setactvieruser is set only i have return false in the adpter and why cant the client retrieve the user at instant and why it needs delay to retrieve. i have verified in both Worklight V6.0 and also Worklight V6.1.i have created the Ipad environment.

推荐答案

信息包含登录的userId(基本上任何userIdentity数据)在适配器身份验证后不会立即返回,但仅在原始请求成功时才返回。考虑这个

The info that contains logged in userId (basically any userIdentity data) is not returned immediately after adapter authentication but only when an original request succeeds. Consider this


  1. 你向服务器发出请求#1(假设调用程序)

  2. 您正在通过authRequired获得回复:true

  3. 您正在提交身份验证数据

  4. 您正在获取authRequred:false

  5. 您正在调用submitSuccess()

  6. WL框架会自动重新调用请求#1

  7. 您的回复是请求#1

  1. You're making request#1 to the server (let's say invoke procedure)
  2. You're getting response with authRequired:true
  3. You're submitting auth data
  4. You're getting authRequred:false
  5. You're calling submitSuccess()
  6. WL framework automatically re-invokes request#1
  7. You're getting response for request#1

userIdentity数据将在步骤7中返回,而不是在步骤4中返回。基本上,一旦启动身份验证流程,您就会被认为不在原始调用上下文中。您需要完成流程并告诉WL框架auth已完成。一旦你这样做 - WL框架将重新调用原始请求。 WL服务器将userIdentity数据添加到响应,WL客户端将更新userName,displayName等属性。

userIdentity data will be returned in step7 and not in step4. Basically once you start authentication flow you're considered out of the original invocation context. You need to finish the flow and tell WL framework that auth has completed. Once you do - WL framework will reinvoke the original request. WL server add userIdentity data to the response and WL client will update userName, displayName etc properties.

如果您在此之前需要用户数据,例如一旦auth完成,您就可以立即向submitAuthentication函数响应添加自定义属性,例如

In case you need user data before that, e.g. right away once auth is complete, you can add custom properties to your submitAuthentication function response, e.g.

        WL.Server.setActiveUser("AdapterAuthRealm", userIdentity);
        return { 
            authRequired: false,
            loginName: userIdentity.loginName
        };

这将确保loginName将返回到handleChallenge函数。你可以在那里找回它并用它做任何你想做的事。

this will make sure that loginName will be returned to your handleChallenge function. you can retrieve it there and do whatever you want with it.

这篇关于IBM Worklight:WL.Client.getUserName无法在身份验证后立即检索userIdentity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆