Authenticate with ArcGIS Online (or your own portal) using OAuth2 to access secured resources (such as private web maps or layers).

Use case
Your app may need to access items that are only shared with authorized users. For example, your organization may host private data layers or feature services that are only accessible by verified users. You may also need to take advantage of premium ArcGIS Online services, such as geocoding or routing, that require a named user login.
How to use the sample
Upon launch, a web map containing premium content will load. You will be prompted by an ArcGIS Online login to view the private layers. Enter a user name and password for an ArcGIS Online named user account (such as your ArcGIS Developer account). If you authenticate successfully, the traffic layer will display; otherwise, the map will contain only the public basemap layer.
How it works
- Create an
OAuthUserConfigurationobject specifying the portal URL, client ID, and redirect URL. - Create a toolkit component
Authenticatorobject with OAuth user configuration. - Set authenticator object as ArcGIS and Network challenge handlers on authentication manager to handle authentication challenges.
- Load a map with premium content requiring authentication.
Relevant API
- AuthenticationManager
- Authenticator
- OAuthUserConfiguration
- Portal
- PortalItem
Additional information
The workflow presented in this sample works for all SAML based enterprise (IWA, PKI, Okta, etc.) & social (Facebook, Google, etc.) identity providers for ArcGIS Online or Portal. For more information, see the topic Set up enterprise logins.
For additional information on using OAuth in your app, see the topic OAuth credentials (for user authentication) and Serverless native and mobile app workflow.
Tags
authentication, cloud, credential, OAuth, portal, security