I have a geoprocessing service on ArcGIS server 10.3 that is protected with tokens.

This GP Service is a python script. Is it possible to retrieve the user information, such username and password, from inside the script using the token passed as parameter?

Is there a way with arcpy to retrieve user information from a valid token?

1 Answer 1


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:


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):
           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())
        except Exception as e:

        if "error" in getUserResponse:
           return getUserResponse["user"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.