HOW TO
When requesting a token via Python, the request is technically anonymous. Since anonymous authentication is disabled at the Web Adaptor level when taking advantage of IWA SSO, a 404 unauthorized error is returned when trying to generate a token.
To work around this limitation, it is necessary to install the requests-negotiate-sspi module in the Python environment that we want to use to grant the "requests" module the ability to pass Windows credentials in requests.
Use the sample script below to generate a token:
import requests
from requests_negotiate_sspi import HttpNegotiateAuth
import json
server = "https://hostname.domain.com/server"
tokenurl = server + '/tokens'
params = {'username':'username@domain','password':'password','client':'referer','referer': server,'f':'json'}
request = requests.get(tokenurl ,params=params, auth=HttpNegotiateAuth())
json = request.json()
myToken = json.get("token","")
print(myToken)
Article ID: 000029104
Get help from ArcGIS experts
Start chatting now