ArcGIS supports secure access to location services and private data. It ensures that only valid, authorized users and applications access protected information. To access secure resources, you need to implement an authentication method so your applications can make authenticated requests for services.
An authentication method is a process used to obtain an access token. Your app must present an access token when it makes a request to an ArcGIS location service. Access tokens define the scope and permissions available to your application. The type of authentication you use to get an access token will vary.
There are two methods for authenticating users and three types of authentication that can be used to obtain an access token:
- API key: A simple method to authenticate users.
- API key authentication: This creates a long-lived access token that grants your application access to location services and private content.
- OAuth 2.0: This method uses application credentials to manage and authorize access for authenticated users.
- User authentication (formerly ArcGIS identity): This generates a short-lived token via OAuth 2.0, authorizing your application to access ArcGIS content, services, and resources on behalf of a logged-in ArcGIS user.
- App authentication: This generates a short-lived token via OAuth 2.0, authorizing a developer's application to access ready-to-use services on their behalf.
To make authenticated requests to services, you need to set the token
parameter to an access token.
API key authentication
An API key is a long-lived access token that authorizes your application to access secure services, content, and functionality in ArcGIS. Using API keys is typically the easiest way to access ArcGIS location services in your applications.
To use API keys, you need to have one of the following ArcGIS accounts:
- ArcGIS Location Platform account
- ArcGIS Online account
Use API keys when you want to:
- Quickly write applications that consume ready-to-use services.
- Provide access to services without requiring users to sign in with an ArcGIS account.
- Use an access token that doesn't expire.
- Meter service usage to the ArcGIS subscription that owns the API key.
You can set a global API key to use across different scenes in a project.
To set a global API key:
Go to Edit -> Project Settings, in the ArcGIS Maps SDK tab, and enter the API key.
To set an API key for a specific scene:
-
You need an ArcGIS Location Platform account or ArcGIS Online account and an API key to access ArcGIS services. If you don't have an account, sign up for free.
-
Open the Map Creator UI in the Unity Editor, and click the Auth tab.
-
Set the API key in the API Key field.
With the Map Creator UI, the API key is used for all your content. If you want to use different API keys for each data, use the C# API.
OAuth 2.0
OAuth 2.0 is an industry-standard protocol for authorization. ArcGIS stores private user identities and content; 3rd party applications access those resources through a secure OAuth 2.0 user authorization protocol.
User authentication
User authentication is a type of authentication that allows users with an ArcGIS account to sign into an application and allow it to access ArcGIS content, services, and resources on their behalf. The typical authorization protocol used is OAuth 2.0. When a user signs into an application, an access token is granted that authorizes the application to access services and content on their behalf. The resources and functionality available to the application depend on the user type, roles, and privileges assigned to the user's ArcGIS account.
Implement user authentication when you want to:
- Ensure users are signed in and authenticated with their own ArcGIS account.
- Meter service usage to your app user's ArcGIS subscription to pay for their private data, content, or service transactions.
- Limit the length of time users can sign in to your app with a temporary token.
To set up OAuth 2.0 with user authentication:
For the editor mode, there is a sample OAuth challenge handler that allows you to configure OAuth 2.0 with user authentication. To load private data in the Scene view:
- Have an ArcGIS account, register an OAuth app, and have a Client ID and Redirect URI for your app to access a private layer. If you don't have an account, sign up for free.
- Open the Map Creator UI and click the Auth tab.
- In the Add Authentication Configuration section, set a name for the configuration and introduce the Client ID and the Redirect URI for the private content.
- Click the Add button.
- Click the tab where you have private content, such as Basemap, Elevation, or Layers, and select the configuration name from the Authentication drop-down.
- Save and reload the scene.
When you add a configuration, you can find it under the Authentication Configurations section. When you reload your scene, the login window opens in a default web browser window. To add basemap, elevation, and layers, see the Layers section.
For play mode, you should configure another OAuth challenge handler for your own app. You can attach your own script or the OAuth Challenge Handlers Initializer (which uses the sample scripts) to the game object with the ArcGIS Map Component.
- Click ArcGIS Map in the Hierarchy window.
- In the Inspector window, click the Add Components button.
- Select OAuth Challenge Handlers Initializer.
When the secured feature service data is loaded, the login window will open in the default web browser.
App credential authentication
App credential authentication uses a set of application credentials to grant a short-lived access token generated via OAuth 2.0. The token authorizes your application to access ready-to-use services, such as basemap layers, search, and routing.
Use application credentials when you want to:
- Access ready-to-use services with a more secure process and a short-lived token.
- Provide access to services without requiring users to have an ArcGIS account.
Choose an authentication method
The choice of which type of authentication to implement is mostly dependent upon the resources required by your application.
Scenario | Solution |
---|---|
Your app requires access only to ready-to-use services, such as the basemap layer, geocoding, or routing services. | API key |
Your app allows users to view and edit private data in ArcGIS. | User authentication |
Your app is API backend and requires access only to basemaps and geocoding. | App credential authentication |