It is not mentioned anywhere in any esri doc, but there is a way to have the user info from a token. You have to use arcgis/rest/self
service like this:
https://<servername>:6443/arcgis/rest/self?f=pjson&token=<token>
From python you can call that service using httplib
or other library
import arcpy
import json
from httplib import HTTPConnection
from urllib import urlencode
class MyGPService:
def __init__(self, config):
self.token = arcpy.getParameter(0)
def getUserFromToken(self):
try:
params = urlencode({"token": self.token, "f": "json"})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
httpConn = HTTPConnection(SERVER_BASE_URL, SERVER_PORT)
httpConn.request("POST", "/arcgis/rest/self", params, headers)
response = httpConn.getresponse()
getUserResponse = json.loads(response.read())
httpConn.close()
except Exception as e:
arcpy.AddError(e)
if "error" in getUserResponse:
arcpy.AddError(getUserResponse["error"])
else:
return getUserResponse["user"]