ArcGIS uses a client credentials flow to implement app authenticationclient and client from a set of OAuth credentialsclient_id, client_secret, and redirect URIs. They are a type of developer credential.
The diagram above explains this flow using the following steps:
-
OAuth credentials
OAuth credentials are an item that contains parameters required to implement user authentication or app authentication, including a are registered in the portalclient_id,client_secret, and redirect URIs. They are a type of developer credential.ArcGIS portal, also known as a portal, is a website with applications and tools that can be used to create, manage, access, and share geospatial content and data. It supports security and authentication, developer credentials, content and data service management, user and group management, and site administration. A portal can be hosted in Esri's infrastructure or your own infrastructure. to obtain aclientand_id client._secret -
The confidential
clientand_id clientare stored in a server-side component._secret -
The server gets an 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. by submitting a request to your organization's portal serviceA portal service provides the functionality to securely create, access, and manage content, data services, users, and groups in a portal. The service can be hosted by Esri or in ArcGIS Enterprise. -
The server delivers the access token to the client application upon request.
-
The client application uses the access token to authorize requests to secure resources
A secure resource is any item or service in an ArcGIS that requires an ArcGIS account and authentication to access. Examples include ArcGIS Location Services, and items and data services in an ArcGIS portal. .
This flow adheres to the client grant type defined in the OAuth 2.0 specificationclient and client values are never exposed to the client application. To read more about the client credentials protocol, go to OAuth 2.0 RFC 6749 section 4.4.
Manual implementation
The remainder of this page shows how to manually implement app authentication
Create OAuth credentials
App authenticationclient_id, client_secret, and redirect URIs. They are a type of developer credential.
Configure authentication variables
-
Copy the
clientand_id clientparameters from your OAuth credentials_secret OAuth credentials are an item that contains parameters required to implement user authentication or app authentication, including a and paste them into a new application.client_id,client_secret, and redirect URIs. They are a type of developer credential.server.jsUse dark colors for code blocks const clientId = 'YOUR_CLIENT_ID'; const clientSecret = 'YOUR_CLIENT_SECRET';
Request the token endpoint
App authentication is implemented by submitting a request to the token endpoint
-
Find the URL of 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. for your ArcGIS organizationAn organization a list of members from the same business, association, or entity who can sign in, access tools and applications, and collaborate with other members in a portal. All members have an ArcGIS account and are approved by an administrator to access the same portal. . For ArcGIS Online and Location Platform users, the token endpoint ishttps.://www.arcgis.com/sharing/rest/oauth2/token server.jsUse dark colors for code blocks const token_endpoint = ' https://www.arcgis.com/sharing/rest/oauth2/token'; -
Submit an HTTP POST request to the endpoint. Include your
client,_id client, and a_secret grantparameter set to_type 'client._credentials' server.jsUse dark colors for code blocks const token_endpoint = ' https://www.arcgis.com/sharing/rest/oauth2/token'; const response = await fetch(token_endpoint, { method: 'POST', headers: { "Content-type":"application/x-www-form-urlencoded" }, body: new URLSearchParams({ 'grant_type':'client_credentials', 'client_id':clientId, 'client_secret':clientSecret }) })
Use the token
After obtaining the access token