Create and set a current user session
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2017 01:07 PM
I have a scripted REST API where I want to create a new user session based off the user name (line 4) in the request header. However, because this integration does not use any type of authentication, the current user is identified as "guest". I want to set the current user to the user session that is created in my gliderecord query below. How can I do this?
//create a user session
var gr = new GlideRecord('sys_user_session');
gr.initialize();
gr.name = sn_user_name;
gs.info('this is the username for the user session' + sn_user_name)
gr.insert();
gs.info('current user session GlideRecordSecure query: {0}', gs.getUserID());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2017 01:19 PM
Have you thought about impersonating the user before the code runs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2017 02:28 PM
Unfortunately the user is "guest" and doesnt have a real session.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2017 06:37 AM
So the call to the REST service is not authenticated but there is a parm that specifies the user?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2017 07:13 AM
Yes, in the request header there is a parm that has the user_id