Using OAuth/tokens to get secured service from on-premise Portal????

316
3
07-01-2019 11:51 AM
KarenEllett
Occasional Contributor

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.

Tags (2)
0 Kudos
3 Replies
Noah-Sager
Esri Regular Contributor

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

0 Kudos
KarenEllett
Occasional Contributor

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.

0 Kudos
Noah-Sager
Esri Regular Contributor

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

0 Kudos