I have a customer who has an on-premise ArcGIS Enterprise instance which uses Integrated Windows Authentication. I am trying to allow those users to display certain Feature layers on a map in my web application, using that authentication and/or OAuth.
It appears that the ArcGIS Javascript API, using some mechanism I don't understand, is able to make requests to this Enterprise instance without providing a token, directly using IWA. However, in my map I am not using ArcGIS Javascript but rather Esri Leaflet.
Experimenting a bit, and trying to compare the behavior seen in the ArcGIS Online Assistant, I was able, using the ArcGIS Javascript API, to make a successful call to generateToken. My call looks roughly like https://site.customerdomain.com/webadaptor/sharing/rest/generateToken with params of
f=json&client=referer&expiration=60&referer=mysite.mydomain.com
This token is then able to successfully retrieve service data as configured in the web map, with URLs that look like
https://site.customerdomain.com/gisurl/rest/services/Actual_Service/MapServer/?token=<token>&f=json
But some of the services they want to use are on a federated server of some sort, and the endpoint looks like
https://site.customerdomain.com.com/webadaptor/sharing/servers/<serverid>/rest/services/Service_Name/FeatureServer/0/?token=<token>&f=json
These endpoints are failing with a 401 Unauthorized response code, and I am unable to see the response body due to a CORS error.
What would cause this 401 Unauthorized response and how do I generate a token that will be accepted by this federated server?