Create and set a current user session

josh_brostoff
Giga Contributor

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());

8 REPLIES 8

DrewW
Mega Sage
Mega Sage

Have you thought about impersonating the user before the code runs?


josh_brostoff
Giga Contributor

Unfortunately the user is "guest" and doesnt have a real session.


So the call to the REST service is not authenticated but there is a parm that specifies the user?


josh_brostoff
Giga Contributor

Yes, in the request header there is a parm that has the user_id