This sample shows how to display a secure webmap using OAuth 2.0 authentication and the IdentityManager. The IdentityManager provides built-in functionality to support the authentication process.
How it works
First, register an application with your ArcGIS organization to get an application ID. This ID is used to authenticate your application with the ArcGIS platform. See the OAuth credentials documentation or the tutorial for additional detailed information about registering an application.
Create an OAuthInfo object and specify the application ID you received when registering your application. This must be done before the map components are loaded. After this is set, pass this OAuthInfo object to the IdentityManager's registerOauthInfos method and the IdentityManager takes care of the rest.
const oAuthInfo = new OAuthInfo({
// Replace with your actual App ID
appId: "APP_ID"
// Set the portalUrl if using a portal other than ArcGIS Online.
//portalUrl: esriConfig.portalUrl
});
esriId.registerOAuthInfos([oAuthInfo]);
Add an arcgis-map
component and set the item-id
attribute to a secure webmap. Add an arcgis-search
and arcgis-legend
component to the map.
<arcgis-map item-id="SECURE_WEBMAP_ID">
<arcgis-search position="top-right"></arcgis-search>
<arcgis-legend position="bottom-left"></arcgis-legend>
</arcgis-map>
Please see the authentication documentation for additional detailed information about user authentication and OAuth 2.0. In addition, please refer to the ArcGIS Organization portals for more information on authentication.
For a similar example using ESM, see this GitHub sample.