Security and authentication

ArcGIS supports secure access to ArcGIS services and portal items. It ensures that only valid, authorized users and services can access protected information. To access secure ArcGIS resources, you need an access token that you can obtain by implementing an authentication workflow in your app. The type of authentication you use will depend on the security and access requirements of your app.

There are three types of authentication that can be used to obtain an access token:

  • API key authentication: grants a long-lived access token to authenticate requests to ArcGIS services and secure portal items. For more information see the Introduction to API key authentication. Go to the Create an API key tutorial to obtain a new API Key access token using your ArcGIS account. You can configure the API key privileges to authorize access to different services and secure portal items.
    • API key access tokens created with an ArcGIS Enterprise account, from ArcGIS Enterprise in version 11.4 onwards, provide access to secure items in an ArcGIS Enterprise portal.
  • User authentication: grants a short-lived token, generated via OAuth, giving your application permission to access the ArcGIS services and secure portal items authorized to an existing ArcGIS user's account.
  • App authentication: grants a short-lived token, generated via OAuth, authorizing your application to access ArcGIS services and secure portal items.

To make authenticated requests to services, you need to set the token parameter to an access token.

API key authentication

An API Key can grant your public-facing application access to specific ArcGIS services and portal items.

Use API key authentication when you want to:

  • Quickly write applications that consume ArcGIS services.
  • Provide access to services without requiring users to sign in with an ArcGIS account.
Learn more about API key authentication

Use an API key in your ArcGIS Runtime app

An API key, can be used to authorize access to specific ArcGIS services and portal items. Go to the Create an API key tutorial to obtain a new access token.

If you set the access token on the ArcGISRuntimeEnvironment using this access token, all requests made by your app will be authorized using this token. You can also set an access token on any ArcGIS Runtime class that implements ApiKeyResource . When you set an access token for a specific class, it will override any access token you may have set on ArcGISRuntimeEnvironment , enabling more granular usage telemetry and management for ArcGIS Online resources by using the ArcGIS Location Platform.

Classes that implement ApiKeyResource include:

User authentication

User authentication is a set of authentication workflows that allow users with an ArcGIS account to sign into an application and access ArcGIS content, services, and resources. The typical authentication protocol used is OAuth2.0. When a user signs into an application with their ArcGIS account, an access token is generated that authorizes the application to access services and content on their behalf. The resources and functionality available depend on the user type, roles, and privileges of the user's ArcGIS account.

Service your app accesses through user authentication will be billed to the authenticated user's ArcGIS account and its associated ArcGIS subscription. If your application will access your users' secure content in ArcGIS or if you plan to distribute your application through ArcGIS Marketplace, you must use user authentication.

Implement user authentication when you want to:

  • Ensure users are signed in and authenticated with their own ArcGIS account.
  • Use your app user's credits to pay for their private data, content, or service transactions.
  • Limit the length of time users can be signed in to your app with a temporary token.
  • Distribute your app through ArcGIS Marketplace.
Learn more about User authentication

App authentication

App authentication grant a short-lived access token, generated via OAuth, authorizing your application to access ArcGIS location services, such as basemap layers, search, and routing.

Use app authentication when you want to:

  • Access location services with a more secure process and a short-lived token.
  • Provide access to services without requiring users to have an ArcGIS account.
Learn more about App authentication

Choose an authentication method

The choice of which type of authentication to implement is primarily dependent upon the resources required by your application. Also consider the strengths and limitations of the API or SDK technology on which your application is built. Your choice of authentication method is also affected by the API with which you build your application. For example, ArcGIS Runtime APIs provide an AuthenticationManager, with helper methods and patterns to implement user authentication workflows.

ScenarioSolution
Your app requires access only to location services, such as the basemap layer, geocoding, or routing services.API key authentication
Your app allows users to view and edit private data in ArcGIS.User authentication
Your app is on a web server or API backend and requires access only to basemaps and geocoding.App authentication
Your app uses Esri Leaflet, Mapbox GL JS, or OpenLayers.API key authentication
Your app uses an ArcGIS API.API key authentication or User authentication

Authentication manager

ArcGIS Runtime APIs contain an AuthenticationManager, which provides helper methods and patterns for implementing user authentication workflows.

AuthenticationManager manages user authentication when connecting to secured services and provides a central place to configure the following aspects of authentication:

Set a central authentication challenge handler that will allow your users to authenticate with secured services

The DefaultAuthenticationChallengeHandler class can take care of user credential and OAuth challenges. For other challenges you must implement AuthenticationChallengeHandler and pass an instance of your handler to setAuthenticationChallengeHandler(AuthenticationChallengeHandler).

The AuthenticationManager's AuthenticationChallengeHandler is null by default; if no handler is set, the request to the secured resource will fail as it cannot be authenticated; for example, a Loadable that uses a secured resource may have a LoadStatus.FAILED_TO_LOAD and the Loadable.getLoadError() will indicate an authorization failure.

Manage an in-memory cache of credentials

When a user is challenged and enters credentials which successfully allow access to the resource, those credentials are automatically added to the AuthenticationManager.CredentialCache . When secured resources from the same server and port are accessed subsequently, credentials in this cache are reused automatically, avoiding unnecessary challenges. Certificates are also cached, see below for more details.

If your app allows a user to sign out of a portal or server, call AuthenticationManager.CredentialCache.clear() to remove all cached credentials when the user signs out, to prevent users accessing resources for which they do not have permission.

The credential cache can be serialized to json, enabling it to be stored between app sessions. However, the serialized credential cache should be secured using an appropriate mechanism for your platform to ensure that credentials are not available to other apps or processes.

Manage the certificates for accessing certificate secured resources

Authentication challenges issued for self-signed server certificates can be handled as follows. Use the setSelfSignedCertificateListener(SelfSignedCertificateListener) method to provide a listener that will handle self signed certificates as they are encountered (Other types of AuthenticationChallenge will continue to be sent to the current AuthenticationChallengeHandler ). This approach is useful when you want to add specific logic for trusting self-signed certificates on a case-by-case basis, but the behavior of the DefaultAuthenticationChallengeHandler is suitable for all other authentication challenges.

For testing purposes, setTrustAllSigners(boolean) can be called with a value of true to indicate an app is willing to trust all valid, non-expired, self-signed certificates. This should never be used in production code.

Manage a set of OAuth configurations

If your app will connect to OAuth secured resources, and you have set an instance of the DefaultAuthenticationChallengeHandler onto the AuthenticationManager , then add an OAuthConfiguration for a specific client ID and portal by calling addOAuthConfiguration(OAuthConfiguration). The set of OAuthConfiguration is stored in-memory only and does not persist between sessions.

What's Next?

For more information about Security and Authentication, see the Security and Authentication chapter.

Tutorials

Samples

Authenticate with OAuth

Integrated Windows authentication

Token authentication

Create and save a map

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.