I'm trying to access a webmap from our on-premise portal in a javascript app. Unfortunately, all of the examples in esri documentation are to access ArcGIS Online data. They say "You can also do this with onpremise portals" but there's exactly zero documentation or examples on how to do so. Does anyone have any code examples? I'm tearing my hair out trying to figure it out, but nothing I'm trying is working.
Hi Karen,
Sorry to hear about the trouble.
I think you're looking for the portalUrl property:
https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#portalUrl
We have this doc'ed in some samples to use a resource from your own Portal:
https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=webmap-basic
I've found and tried with that example. However, the issue is that the services and such are secured. Portal is federated. When I try to access the webmap using just the esriConfig.portalUrl, I get a 401 error saying unauthorized; i'm assuming i need to somehow generate and use a token for this, but I can find zero examples. To be clear, I only get that 401 error when I try to access it in code; if i simply put the url into my browser directly, it allows me to access it.
Are you prompted to enter a username and password? For secure resources, it should automatically prompt you.
Another option would be to use a self-hosted proxy to authenticate for you:
https://developers.arcgis.com/javascript/latest/guide/proxies/
Using an app login or a user login:
https://developers.arcgis.com/javascript/latest/guide/secure-resources/#application-logins