What is an access token?
An access token is an authorization string that provides secure access to ArcGIS resources. Your app must present an access token whenever it makes an authenticated request to ArcGIS services or secure items. They define the scope of privileges available to your application, and their properties vary based on the type of authentication used to obtain them. Access tokens are always associated with an ArcGIS account, and service usage with the token will be billed to that account's ArcGIS subscription.
AAPTKUgfudpnh_cXrZ7wRiqGE4q0VCQENKpafTPqVh27cldNPiqORWEyVueCmI67s3ebSNEYl0Sn3IitIyf18X8PxF3N8m9ZE30i5iwGHtGfnv6-DoKA-C8-lJ9GM30s-Wxn75jLBdnQnMjIgwVXEjIoualIMSfk4IWraDv3GMV8XP3fAUA73P23Vfs-THx2QjfDNVD3iuGCqLG0udK_TVLchskcBFVbsj1PRWXGcFaKKzdPkwWMXps_4P_cZEBAZdImAT1_L1aY2CIy
You can get an access token by implementing a type of authentication in your app. Different types of authentication result in access tokens with different privileges.
Types of access tokens
There are different types of access tokens that have different durations.
Type of token | Type of authentication | Description |
---|---|---|
API token | API key authentication | A static, long-lived API key valid for up to one year. They are created, managed, and deleted using API key credentials. |
User token | User authentication | Expires after a set amount of time, 30 minutes by default (max 2 weeks). A new token is generated for each user that signs in to a custom application with user authentication. |
App token | App authentication | Expires after 2 weeks. They are generated using a client and client from OAuth credentials. |
Privileges for access tokens
Access tokens have different privileges depending on the method used to obtain them:
-
Tokens from API key authentication and App authentication have their privileges managed by the developer credentials used to obtain them.
-
Tokens from user authentication have their privileges determined by the ArcGIS account of the signed-in user.
View token information
You can retrieve information about an access token by including it in a /self
request to the portal service. Set the app
parameter to the token you want to view information about (valid or not), and set the token
parameter to a valid access token. Some of the returned properties include:
- Access token privileges
- Access token expiration date
- client ID of the associated developer credentials
- Item ID of the associated developer credentials
- Owner of the associated developer credentials
- ID of the associated organization
https://<PORTAL_URL>/self?token=<YOUR_ACCESS_TOKEN>&appInfoToken=<YOUR_ACCESS_TOKEN>&f=pjson
How to use an access token
You can use an access token to make a request to ArcGIS for resources. To make requests to ArcGIS services, you need to set the token
parameter to include the value of the access token. If the token is authenticated successfully, the request is granted access to the operation or resource.
https://<LOCATION_SERVICE_URL>?token=<YOUR_ACCESS_TOKEN>
You can also make requests to ArcGIS REST APIs by using an ArcGIS Maps SDK.
Code examples
The following code examples show how to use access tokens to authenticate REST API requests to ArcGIS resources.
Access a basemap style
This example accesses the ArcGIS Outdoor basemap style from the basemap styles service.
curl https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/arcgis/outdoor? \
-d "token=<YOUR_ACCESS_TOKEN>"
Perform geocoding
This example performs a forward geocode by making a request to the geocoding service.
curl https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates \
-d "f=pjson" \
-d "address=1600 Pennsylvania Ave NW, DC" \
-d "token=<YOUR_ACCESS_TOKEN>"
Access a feature service
This example retrieves features from a feature service.
curl https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/LA_County_Parcels/FeatureServer/0/query? \
-d "where=1=1" \
-d "outFields=*" \
-d "f=json" \
-d "token=<YOUR_ACCESS_TOKEN>"
Get item details
This example accesses a private item hosted in ArcGIS.com and retrieves its properties.
curl https://www.arcgis.com/sharing/rest/content/items/<ITEM_ID> \
-d 'f=pjson' \
-d 'token=<YOUR_ACCESS_TOKEN>'