why don't you change that to lookup and pick whatever variable is used there?
Alternatively there's a security.login() function you could use to set the user in a headless-client, I assume that set's the correct internal variables, at least that is what I seem to use here.