title: Worklight logout does not clear active user
body: <p>I am using Worklight 6.1 and am using a challange handler to determine if my user is logged or not.</p>
  
  <p>Once logged in, I have the following code attached to my logout button in my app:</p>
  
  <pre><code>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;
  }));
  </code></pre>
  
  <p>Clicking it opens the login view, but when the user tries to login again, the following error is shown: </p>
  
  <pre><code>"Cannot change identity of an already logged in user in realm 'AdapterAuthRealm'.
  The application must logout first."`
  </code></pre>
  
  <p>According to the following SO question:
  <a href="https://stackoverflow.com/questions/16997804/worklight-wl-server-setactiveuser-cannt-modify-illegal-state-cannot-chang">Worklight: WL.Server.setActiveUser - Cann&#39;t modify - Illegal State: Cannot change identity</a></p>
  
  <p>I will first have to clear the active user before setting a new one:</p>
  
  <pre><code>WL.Server.setActiveUser("AdapterAuthRealm", null);
  </code></pre>
  
  <p>I actually expected WL.Client.logout to do this automaticly, but doing so myself in my onLogout function in my adapter does not seem to have any effect:</p>
  
  <pre><code>&lt;realm loginModule="NonValidatingLoginModule" name="AdapterAuthRealm"&gt;
    &lt;className&gt;com.worklight.integration.auth.AdapterAuthenticator&lt;/className&gt;
    &lt;parameter name="login-function" value="PortalAdapter.onAuthRequired"/&gt;
    &lt;parameter name="logout-function" value="PortalAdapter.onLogout"/&gt;            
  &lt;/realm&gt;
  </code></pre>
  
  <p>And</p>
  
  <pre><code>function onLogout() {
      WL.Logger.info("invoke logout request");
      WL.Server.setActiveUser("AdapterAuthRealm", null);
  
      var input = {
          method : 'get',
          returnedContentType : 'text/plain',
          path : '/logoutUrl'
      };
  
      WL.Server.invokeHttp(input);
  }
  </code></pre>
  
  <p>Adding it to my login function in my adapter as follows:</p>
  
  <pre><code>var userIdentity = { userId: username, displayName: username, attributes: {}};
  WL.Server.setActiveUser("AdapterAuthRealm", null);
  WL.Server.setActiveUser("AdapterAuthRealm", userIdentity);
  </code></pre>
  
  <p>Results in an infenite loop of login / logout requests of my app.</p>
  
  <p><strong>My questions:</strong></p>
  
  <ol>
  <li>When/where am I supposed to clear my active user?</li>
  <li>When using a challange handler, is it allowed to use the WL.Client.logout method?</li>
  </ol>