Question

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);
Was it helpful?

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
        };

OTHER TIPS

You can store custom attributes (as username and loginname) when creating user identity as here:

   var userIdetity={
          userId : "kawin",
          displayName : "Kawinesh",
          attributes : {
             username : "your_user",
             loginname : "your_login_name"                 
          }
  };

  WL.Server.setActiveUser("AdapterAuthRealm", userIdentity);

Then, on the client side, you can retrieve those values getting the "attributes" object as here:

var attributes = WL.Client.getUserInfo("AdapterAuthRealm", "attributes");
var username = attributes.username;
var loginname = attributes.loginname;

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top