Search code examples
ibm-mobilefirstworklight-adaptersworklight-security

Worklight client side api query


I used adapter based authentication and I have set the userIdentity. Now I was trying to get the loginname and username using the Worklight API's WL.Client.getUserName(realm) and WL.Client.getLoginName(realm), but both the API calls return NULL as the result. I have set the user identity in the adapter using the code below. I just don't know how to set the username and loginname of the user when authentication is done on adapter based authentication. I am able to retrieve the userId of the realm by the WL.Client.getUserInfo(realm, "userID").

How do I set the username and loginname?

var userIdetity={
          userId : "kawin",
          disaplyName : "Kawinesh",
          attributes : {
          foo : "bar"
          }
  };
     WL.Server.setActiveUser(realmname,userIdentity);

Solution

  • Hi i have found the answer i just have to set the usrIdentity object along with the userName and loginName key value pair like

    var userIdentity = {
                    userId: username,
                    displayName: username, 
                    attributes: {
                        foo: "bar"
                    },
                    loginName : username,
                    userName : username
            };