You will learn: how to create proxies to allow applications to access premium services such as routing and directions.
ArcGIS Online premium services such as Routing and GeoEnrichment consume credits and require applications to provide authentication to access them. ArcGIS supports a number of authentication patterns, but one of the easiest is to implement the "App login" pattern with a service proxy. A service proxy is an authenticated URL that you can set up to allow your applications to access services with your credentials. ArcGIS makes this easy by providing an ArcGIS Online hosted proxy service that you can configure with the ArcGIS for Developers website. To do so, you need to register an application and then create proxies to the premium services your applications will use. As your applications use services, your account will be deducted credits, and you can keep track of the usage through the statistics provided on the dashboard. To learn more about authentication and premium services, please visit the ArcGIS Security and Authentication documentation.
In this tutorial you will register a new application and create proxies for the Geocoding, Routing, Traffic, Service Area and Demographics services. These proxies will be used in other tutorials.
You will need an ArcGIS developer or ArcGIS Online organization account to complete this tutorial. If you do not have an account, you can sign up for a free account here.
Before you can create service proxies, you need to create and register an application in your ArcGIS account. Each application has a unique Client ID and Client Secret and can be configured with different authentication settings.
At the top right of the main menu, click > New Application to create a new applicaiton. Set the following properties:
Click Register your Application.
In applications, proxies can be set up for each service endpoint that your applications will use. You can create one or multiple proxies per application. For all of the ArcGIS Tutorials, we'll just set up one application with all of the required proxies in it.
In your application, click Servcies.
In the New Service Proxy box, create the following proxies for these services:
In order to protect your proxies you can limit the sites that can access them by setting up a whitelist of HTTP referrers. Web browsers will automatically set the referer header to the domain of the website. In most mobile applications you can manually set the referer header to a specific value. Only referer headers matching those in your whitelist will be allowed to use your services.
NOTE: If you do not specify a whitelist there will be no restrictions on which sites can access these services.
In your application, click services and identify the Whitelisted Referrers.
Add in the following whitelisted domains:
https://*.codepen.io> Add (for the ArcGIS JS API Tutorials)
http://localhost:8000> Add (optional, for local development)
http://localhost:80> Add (optional, for local development))
Feel free to add in any other domains you wish to whitelist for your applications.
You have successfully created an application with proxies to premium services. Now you can use the URLs in your applications and users will not be prompted for credentials. See challenge to give it a try!
Now that the proxies are in place, go to your applications and replace the URLs to the premium services with the proxy URLs you created above. If you don't have an application, do the following:
Go the Get a route and directions tutorial and complete the tutorial or just run the solution.
Complete the challenge step of the tutorial and add the URL to your Route and Directions proxy and then run the application again. The application will no longer prompt the user to sign in and will use the authenticated service proxy.
After you complete the step above, test the application and then go to your dashboard and click Usage to monitor service usage. Try appling different time filters as well.