This topic outlines the high-level steps of how to implement app authentication
1. Create OAuth credentials
App authenticationclient_id, client_secret, and redirect URIs. They are a type of developer credential.
2. Implement a client credentials flow
App authenticationclient. This involves making a request to the token endpointclient and client from OAuth credentials. The high-level steps to implement this flow are as follows:
-
Paste the
clientand_id clientfrom a set of OAuth credentials_secret OAuth credentials are an item that contains parameters required to implement user authentication or app authentication, including a into your application.client_id,client_secret, and redirect URIs. They are a type of developer credential. -
Submit a POST request to the token endpoint
An token endpoint is an endpoint of a portal service that can be queried to request an access token. It is used to implement user authentication OAuth2.0 flows. , either directly or through a helper class provided by an ArcGIS APIAn ArcGIS API is a web, native, game engine, or scripting API that has advanced mapping and spatial analysis capabilities and can be used to access ArcGIS services. ArcGIS APIs are designed to work optimally with the ArcGIS system and provide the most advanced GIS features and the highest performance possible. . -
Use the access token
An access token is an authorization string that provides access to secure ArcGIS content, data, and services. Its capabilities are determined by the privileges it supports. It is obtained by implementing API key authentication, User authentication, or App authentication. returned in the response. If you made the request on a server, you can now send the access token to your client application.
ArcGIS APIs
ArcGIS REST JS provides an Application class that can be used to implement app authentication
import { ApplicationCredentialsManager } from "@esri/arcgis-rest-request";
import { geocode } from "@esri/arcgis-rest-geocoding";
const appManager = ApplicationCredentialsManager.fromCredentials({
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET"
});
appManager.refreshToken().then((manager) => {
Server-side examples
The following examples show how to set up a web server that implements app authentication and passes the resulting access token
3. Make a request
Implementing app authentication successfully will grant an access tokenclient_id, client_secret, and redirect URIs. They are a type of developer credential.client and client.
ArcGIS APIs and SDKs
If you use app authentication/oauth2/token endpoint can be used directly in requests.
The examples below show how to display a map using an access token
esriConfig.apiKey = "YOUR_ACCESS_TOKEN";
const map = new Map({
basemap: "arcgis/topographic", // Basemap layer
});
const view = new MapView({
map: map,
center: [-118.805, 34.027],
zoom: 13, // scale: 72223.819286
container: "viewDiv",
constraints: {
snapToZoom: false,
},
});
ArcGIS REST APIs
Your application can also include the access tokentoken parameter.
This example shows how to geocode an address with 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>"