Overview

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.

Before you begin

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.

Steps

Register a new application

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.

  1. Sign in to your ArcGIS account. If you don't already have one, sign-up for free.

  2. To create a new application, click Dashboard + > New Application with the following properties:

    • Title: ArcGIS Tutorial Proxy App
    • Tags: ArcGIS Tutorial
  3. Click Register your Application.

Create proxies for premium services

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.

  1. In your application, click Servcies.

  2. In the New Service Proxy box, create the following proxies for these services:

    • Geocoding
      • Request Limit: 10
      • Interval: minute
      • Click Add
    • Routing and Directions
      • Request Limit: 10
      • Interval: minute
      • Click Add
    • Traffic Layer
      • Request Limit: 10
      • Interval: minute
      • Click Add
    • Service Area
      • Request Limit: 10
      • Interval: minute
      • Click Add
    • Demographics
      • Request Limit: 10
      • Interval: minute
      • Click Add

Secure your proxies

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.

  1. In your application, click services and identify the Whitelisted Referrers.

  2. 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.

Congratulations, you're done!

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!

Challenge

Use the proxies in your apps

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:

  1. Go the Get a route and directions tutorial and complete the tutorial or just run the solution.

  2. 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.

Monitor usage

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.