cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

User data

mneufeld
12-Amethyst

User data

When experience is marked as "requires authentication" and logs in - is it possible to retreive user information? Just want to know if it was userA or userB.

Then when services are invoked from experience is it possible to have authenticated user information?

 

2 REPLIES 2

You can get the user name from the CurrentSessionInfo.GetCurrentUser() method:

1) In "External Data", click the + to add an item

2) Search for "CurrentSessionInfo" under "Entities"

3) Select it, and switch to "Services" on the right.

4) Search for "GetCurrentUser", and click the green + to add it to your project

5) Back in the project window, under External Data, find CurrentSessionInfo->Services->GetCurrentUser->Configuration and expand it

6) Make sure the "Invoke on startup" option is checked.

 

You can now link that to an app parameter or directly to a targetable widget field (like the "text" field of a textbox). You can also access the value in script code using

$scope.app.mdl['CurrentSessionInfo'].svc['GetCurrentUser'].data[0].result

I'm not quite sure what your second question is getting at, but hopefully this will be enough to get you going down the right path.

I will add some context: 

  • I created two users in Thingworx: userA and userB
  • I created very simple 2D experience where I have a button that triggers CurrentSessionInfo.GetCurrentUser service from Twx. Result from service is bound to Label widget. My experience "Requires authentication".
  1. When I run View, I scan Thingmark, pick my experience, I provide credentials for userA ("Remember Me" checkbox stays not checked), I press the button to fire service, I get answer "userA" in Label. So it works.
  2. When I go back to Scan, I scan Thingmark again, pick my experience and... it does not ask me for credentials any more... When I press the button I get userA again. ("Remember Me" checkbox  was not checked at first launch).
  3. When I go to Settings and pick Clear login credentials and cookies or I simply close View app and run it again, then experience asks me for credentials as it should, when I provide userB then I get userB as a result from Twx service. (Looks like there is some user credential caching as long as app is alive

Note: Tested on Android 8, View 8.3.6.

Note2: invoking CurrentSessionInfo.GetCurrentIP service from Twx, returns always 127.0.0.1 for me (probably because my ES and Thingworx are on the same host), so it does not seem to be device IP.

 

For the second part of my question about tracking what user invoked what service in Thingworx - all is visible in Monitoring (when specific user get visibility and runtime permissions).

 

Top Tags