We have experienced the same issue for one of our apps. Here is what we did to resolve the issue.
- Register the app with ArcGIS Online.
- Once registered, click on the app link to go to the app info page.
- Under App Registration, you will see the App ID and App Secret.
- Download the ESRI proxy page via Releases · Esri/resource-proxy · GitHub. If you are using .NET, that will work. The java version has a bug. Let me know if you happen using Java version.
- Add two serverUrl entries in proxy.config as below:
<serverUrl url="http://route.arcgis.com"
clientId="the_app_id"
clientSecret="the_app_secret"
matchAll="true"/>
<serverUrl url="http://traffic.arcgis.com"
clientId="the_app_id"
clientSecret="the_app_secret"
matchAll="true"/>
- Whenever the app hits route.arcgis.com or traffic.arcgis.com which the Directions dijit does, the app will use the proxy page with the client id and secret to request for the token. Once the token is expired after maybe 2 hours, the proxy page will request for a refresh token. But all these happens behind the scene. The app id will be charged for any credits for using the routing service.
Hope it helps. Good luck.
Jason Zou