1

I created map, web mapping application on ArcGIS Online and wanted to access map using this app (but app hosted on my server using app login). We can create web application using many default template on ArcGIS Online. we can also download source code of these JavaScript applications and can host them on own servers.

But I am not able to find any example which can guide me to modify app code to use app login.

I already know following steps:

  • Register the app and get client id (app id)/client secret (app secret)
  • Using POST request get access token from https://www.arcgis.com/sharing/rest/oauth2/token/
  • What next? Not sure
  • How to modify code in my downloaded app to access map?
  • Downloaded app folder structure

enter image description here


@heather-zerbe-gonzago helped but I am still not successful running my map. I am using web application created by App builder and hosted it on own server. I have changed below files and using https://github.com/Esri/resource-proxy

Proxy.config enter image description here Config.json enter image description here

Getting error {"error":{"code":400,"message":"Unable to generate token","details":["Unable to generate token for this server"]}} while hitting exchangePortalTokenForServerToken method in proxy.ashx file enter image description here


I am able to resolve the above issue and come across another one. I am trying to access ArcGIS Online Map using web builder generated app hosted on own servers.

I am getting below error code:498 details:[] message :"Invalid Token" while app hits url https://***/arcgisdev/proxy.ashx?https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer?f=json

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Apr 16, 2017 at 20:56
2
  • Did you checkout the doc here? developers.arcgis.com/authentication/… Commented Apr 17, 2017 at 13:10
  • Yes, I saw the doc. I am stuck after getting a token, how received token will be used to access map? there is no sample for that. Could you please provide some sample code to access web map by using received token (developing in JavaScript API) Thanks Commented Apr 17, 2017 at 14:26

1 Answer 1

4

Probably the easiest way is to let a proxy handle this for you. For example, once you register your app, you can then copy and paste the clientId and secret into your proxy file. If you specify a proxy within your application, it will route the POST request via the proxy using the specified credentials from this registered app.

We actually use this in a few of our samples that require user logins to access hosted services off of AGO. Take a look at the Directions sample here, https://developers.arcgis.com/javascript/3/jssamples/widget_directions_basic.html, specifically take note of the line

 //all requests to route.arcgis.com will proxy to the proxyUrl defined in this object.
 urlUtils.addProxyRule({
 urlPrefix: "route.arcgis.com",
 proxyUrl: "/sproxy/"
 });
 urlUtils.addProxyRule({
 urlPrefix: "traffic.arcgis.com",
 proxyUrl: "/sproxy/"
 });

The proxyUrl should point to a secured proxy on your web server. You can download this at https://github.com/Esri/resource-proxy. You will need to modify the proxy.config file with the credentials from your registered app. Specifically, take note of clientId and clientSecret. (README.md#proxy-configuration-settings)

Oto Kaláb
7,0253 gold badges33 silver badges54 bronze badges
answered Apr 17, 2017 at 16:41
3
  • I forgot to mention, you can find some additional info on this. Spoke on this at this year's Dev Summit, esri.com/videos/…. Specifically take note around 50:00 Commented Apr 17, 2017 at 18:24
  • Hello Heather, Thanks, for so much useful Information, however, I am still not able to run it successfully. Commented Apr 18, 2017 at 13:41
  • Hello Heather, Please refer Update 1 section in question for the error I am getting. I am having a feeling that I am using some wrong config values. Thanks Commented Apr 18, 2017 at 14:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.