HOW TO

Generate a token for a stand-alone ArcGIS Server that uses IWA SSO authentication using Python

Last Published: January 11, 2023

Summary

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:

Procedure

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

Software:
  • ArcGIS Server

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options