Ibm mobilefirst Worklight注销未清除活动用户

Ibm mobilefirst Worklight注销未清除活动用户,ibm-mobilefirst,worklight-adapters,worklight-server,Ibm Mobilefirst,Worklight Adapters,Worklight Server,我正在使用Worklight 6.1并使用challange处理程序来确定我的用户是否已登录 登录后,我的应用程序中的注销按钮上会附加以下代码: on(logoutBtn, "click", lang.hitch(this, function() { WL.Client.logout('AdapterAuthRealm', { onSuccess:lang.hitch(this, function() { this.gotoView("login"); }), o

我正在使用Worklight 6.1并使用challange处理程序来确定我的用户是否已登录

登录后,我的应用程序中的注销按钮上会附加以下代码:

on(logoutBtn, "click", lang.hitch(this, function() {
    WL.Client.logout('AdapterAuthRealm', { onSuccess:lang.hitch(this, function() {
        this.gotoView("login");
    }), onFailure:lang.hitch(this, function() {
        WL.Logger.error("Unable to logout");
    })});
    return false;
}));
单击它会打开登录视图,但当用户再次尝试登录时,会显示以下错误:

"Cannot change identity of an already logged in user in realm 'AdapterAuthRealm'.
The application must logout first."`
根据以下问题:

在设置新用户之前,我必须首先清除活动用户:

WL.Server.setActiveUser("AdapterAuthRealm", null);
实际上,我希望WL.Client.logout能够自动执行此操作,但我自己在适配器的onLogout函数中这样做似乎没有任何效果:

<realm loginModule="NonValidatingLoginModule" name="AdapterAuthRealm">
  <className>com.worklight.integration.auth.AdapterAuthenticator</className>
  <parameter name="login-function" value="PortalAdapter.onAuthRequired"/>
  <parameter name="logout-function" value="PortalAdapter.onLogout"/>            
</realm>
将其添加到适配器中的“我的登录”函数中,如下所示:

var userIdentity = { userId: username, displayName: username, attributes: {}};
WL.Server.setActiveUser("AdapterAuthRealm", null);
WL.Server.setActiveUser("AdapterAuthRealm", userIdentity);
导致我的应用程序的登录/注销请求出现不受限制的循环

我的问题:

  • 我应该在何时/何地清除活动用户
  • 使用challange处理程序时,是否允许使用WL.Client.logout方法
  • 您的领域应该有一个注销函数,该函数应该指向要注销的适配器过程。您可以将其添加为realm的参数
  • 您可以添加
    WL.Server.setActiveUser(“AdapterAuthRealm”,null)到适配器中的onLogout()过程

    <realm loginModule="loginModule" name="AdapterAuthRealm">
                <className>com.worklight.integration.auth.AdapterAuthenticator</className>
                <parameter name="login-function" value="LoginAdapter.onAuthRequired"/>
                <parameter name="logout-function" value="LoginAdapter.onLogout"/>
            </realm>
    
    
    com.worklight.integration.auth.AdapterAuthenticator
    

    2是的。您可以使用WL.Client.Logout();`当使用质询处理程序时

    谢谢你的回复,但这是我已经在做的事情,这就是为什么我一开始就感到困惑…在我的情况下,我不会为onLogout()返回任何东西,但是当不返回任何东西时,它似乎不会改变任何事情:-(你在使用
    challengeHandler.submitSuccess()吗)
    ?在成功注销时,尝试使用
    WL.Client.reloadApp();
    并在登录前检查relam是否通过
    WL.Client.isUserAuthenticated(“AdapterAuthRealm”)
    验证,这是因为客户端和服务器不同步。请标记我的答案。
    <realm loginModule="loginModule" name="AdapterAuthRealm">
                <className>com.worklight.integration.auth.AdapterAuthenticator</className>
                <parameter name="login-function" value="LoginAdapter.onAuthRequired"/>
                <parameter name="logout-function" value="LoginAdapter.onLogout"/>
            </realm>