Skip to content

Security and authentication

ArcGIS supports secure access to ArcGIS services and portal items. It ensures that only valid, authorized users and services can access protected information. To access secure ArcGIS resources, you need an access token that you can obtain by implementing an authentication workflow in your app. The type of authentication you use will depend on the security and access requirements of your app.

There are three types of authentication that you can use to get an access token:

  • API key authentication: grants a long-lived access token to authenticate requests to ArcGIS services and secure portal items. For more information see the Introduction to API key authentication. To obtain an API key access token, go to the Create an API key tutorial using your ArcGIS account. Here you can configure the API key privileges to authorize access to different services and portal items.

  • User authentication: a collection of authentication workflows that connect your app to a user's ArcGIS account.

    • OAuth 2.0: manage ArcGIS authentication and grant a short-lived access token generated via OAuth 2.0. This gives your application permission to access ArcGIS secured services authorized to an existing ArcGIS user's account. For more information see the OAuthUserCredential.
    • Generate token: manages ArcGIS authentication and grants a short-lived access token generated via Esri's proprietary token-based authentication mechanism. This gives your application permission to access ArcGIS secured services authorized to an existing ArcGIS user's account. For more information see the TokenCredential and PregeneratedTokenCredential.
  • App authentication: uses the registered application's credentials to access location services on ArcGIS. It manages ArcGIS authentication and grants a short-lived access token generated via OAuth 2.0 using the Application item's Client ID and Client Secret outside of the context of a user.

Choose a type of authentication

The following considerations can help determine which type of authentication to implement:

  • Access to resources—Your app can access ArcGIS services and portal items using API key authentication, User authentication, or App authentication.

  • User experience—If you don't want to make users log in, your app can access ArcGIS services using API key authentication or App authentication. In this case, users will not need to have an ArcGIS account in order to use your app.

  • Usage charges—If you want service usage to be charged to the user's account, your app must request that the user log in using User authentication. When using API key authentication or App authentication, all access to services from your app will be charged to your ArcGIS account.

You might also need to consider the level of security required for your app, how your app will be distributed, and your available ArcGIS products and accounts.

ScenarioSolution
Your app requires access to ArcGIS services only, you don't want to make users log in, and you are willing to pay for all charges incurred from usage of the app.API key authentication or App authentication
Your app requires access to location services only and you want usage charged to the user.User authentication
Your app needs to access content that requires an ArcGIS Online subscription.User authentication
Your app needs to access private hosted data on your ArcGIS Location Platform account.API key authentication or App authentication
Your app allows users to view and edit private data hosted in ArcGIS Online or ArcGIS Enterprise.User authentication
You plan to distribute your app through ArcGIS Marketplace.User authentication

API key authentication

An API key can grant your public-facing application access to specific ArcGIS services and portal items.

Use API key authentication when you want to:

  • Quickly write applications that consume ArcGIS services.
  • Provide access to services without requiring users to sign in with an ArcGIS account.

To authorize your app to access secured resources, obtain a API key access token using the Create an API key tutorial. Set the API key access token on the ArcGISEnvironment.

main.dart
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

import 'package:arcgis_maps/arcgis_maps.dart';
import 'package:flutter/material.dart';

void main() {

  ArcGISEnvironment.apiKey = 'YOUR_ACCESS_TOKEN';

}

You will be able to view the app's usage telemetry on the respective ArcGIS Location Platform or ArcGIS Online account. You can also set the API key access token on any class that implements ApiKeyResource. This will override any access token you have set on the ArcGISEnvironment and will enable more granular usage telemetry.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    // Create a new ArcGIS basemap and apply an access token.
    final basemap = Basemap.withStyle(BasemapStyle.arcGISNavigation);
    basemap.apiKey = 'YOUR_ACCESS_TOKEN';

    // Create a new map with the basemap.
    final map = ArcGISMap.withBasemap(basemap);

Classes that implement ApiKeyResource include:

Learn more about API key authentication

User authentication

User authentication is a set of authentication workflows that allow users with an ArcGIS account to sign into an application and access ArcGIS content, services, and resources. The typical authentication protocol used is OAuth2.0. When a user signs into an application with their ArcGIS account, an access token is generated that authorizes the application to access services and content on their behalf. The resources and functionality available depend on the user type, roles, and privileges of the user's ArcGIS account.

Services that your app accesses with user authentication will be billed to the authenticated user's ArcGIS account and its associated ArcGIS subscription. If your application will access your users' secure content in ArcGIS or if you plan to distribute your application through ArcGIS Marketplace, you must use user authentication.

Implement user authentication when you want to:

  • Ensure users are signed in and authenticated with their own ArcGIS account.
  • Use your app user's credits to pay for their private data, content, or service transactions.
  • Limit the length of time users can be signed in to your app with a temporary token.
  • Distribute your app through ArcGIS Marketplace.
Learn more about user authentication

App authentication

App authentication grants a short-lived access token, generated via OAuth 2.0, authorizing your application to access ArcGIS location services, such as basemap layers, search, and routing.

Use app authentication when you want to:

  • Access location services with a more secure process and a short-lived token.
  • Provide access to services without requiring users to have an ArcGIS account.
Learn more about app authentication

Authenticator toolkit component

In this SDK, all aspects of ArcGIS and network authentication have been encapsulated into a single ArcGIS Maps SDK for Flutter toolkit component called the Authenticator. This component supports multiple types of authentication challenges, including ArcGIS authentication methods (OAuth and ArcGIS token), Integrated Windows Authentication (IWA), and Client Certificate (PKI). It also provides default user interfaces for login prompts, certificate selection prompts, and server trust dialogs.

Authentication manager

If you do not want to use the Authenticator toolkit component, you can manage the authentication process in your application code using the AuthenticationManager. This is a static property of the ArcGISEnvironment.

Use dark colors for code blocksCopy
1
ArcGISEnvironment.authenticationManager

The AuthenticationManager provides:

  • ArcGIS and network challenge handlers that allow you to respond to the authentication challenges. For example, you can write code to present the user with a login screen and then continue to authenticate with those credentials. For more information, see Handle authentication challenges.

  • The credential stores are available for you to place ArcGIS and network credentials that are automatically checked when your application attempts to connect to secure resources. These stores can also be made persistent in the keychain so that user does not have to sign in again when the application is re-launched. For more information, see Create and store credentials.

Handle authentication challenges

If your application attempts to access a secure resource and there is no matching credential in the credential store, an authentication challenge is raised:

  • ArcGISAuthenticationChallenge is raised if the ArcGIS secured resource requires OAuth or ArcGIS Token authentication.
  • NetworkAuthenticationChallenge is raised if the ArcGIS secured resource requires network credentials, such as Integrated Windows Authentication (IWA) or Public Key Infrastructure (PKI).

You can catch and respond to the authentication challenges using the ArcGISAuthenticationChallengeHandler and NetworkAuthenticationChallengeHandler, respectively. These challenge handlers represent abstract interfaces that you can implement in any class. You can catch and respond to the authentication challenges using the ArcGISAuthenticationChallengeHandler and NetworkAuthenticationChallengeHandler, respectively. These challenge handlers represent abstract interfaces that you can implement in any class.

ArcGIS authentication challenge handler

The ArcGISAuthenticationChallengeHandler is used to handle authentication challenges from ArcGIS secured resources that require OAuth or ArcGIS Token authentication. Handle the challenge by returning one of the ArcGISAuthenticationChallenge options:

  1. Create a class implementing the ArcGISAuthenticationChallengeHandler abstract interface to handle ArcGIS authentication challenges.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    // Defines an ArcGIS authentication challenge handler.
    class _AuthenticateWithOAuthState extends State<AuthenticateWithOAuth>
        implements ArcGISAuthenticationChallengeHandler {
    
      // The OAuth configuration that this challenge handler can work with.
      final _oauthUserConfiguration = OAuthUserConfiguration(
        portalUri: portalUri,
        clientId: clientId,
        redirectUri: redirectUri,
      );
    
      // Handles the challenge to an ArcGIS secured resources that requires
      // OAuth or ArcGIS Token authentication.
      @override
      void handleArcGISAuthenticationChallenge(
        ArcGISAuthenticationChallenge challenge,
      ) async {
    
        try {
          // Initiate the sign in process to the OAuth server using the
          // defined user configuration.
          final credential = await OAuthUserCredential.create(
            configuration: _oauthUserConfiguration,
          );
    
          // If sign in was successful, then continue with the provided
          // credential.
          challenge.continueWithCredential(credential);
        } on ArcGISException catch (error) {
          // The sign in was canceled or there was some other error.
          final e = (error.wrappedException as ArcGISException?) ?? error;
    
          if (e.errorType == ArcGISExceptionType.commonUserCanceled) {
            // Cancel the request that initiated the challenge.
            challenge.cancel();
          } else {
            // Handle the challenge without a credential, causing it to fail
            // with the original authentication error.
            challenge.continueAndFail();
          }
        }
      }
    }
  2. Set an instance of the class on the AuthenticationManager.arcGISAuthenticationChallengeHandler property of the ArcGISEnvironment.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
        // `this` represents an instance of the class that implements the
        // ArcGISAuthenticationChallengeHandler.
        ArcGISEnvironment
            .authenticationManager.arcGISAuthenticationChallengeHandler = this;
    

Network authentication challenge handler

The NetworkAuthenticationChallengeHandler is used to handle authentication challenges from ArcGIS secured resources that require network credentials, such as Integrated Windows Authentication (IWA) or Public Key Infrastructure (PKI). Handle the challenge by returning one of the following subclasses of the NetworkAuthenticationChallenge sealed class.

  1. Create a class that implements the NetworkAuthenticationChallengeHandler protocol to handle Network authentication challenges.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    // Define a Network authentication challenge handler.
    class MyNetworkChallengeHandler
      implements NetworkAuthenticationChallengeHandler {
    }
  2. Set an instance of the class on the AuthenticationManager.networkAuthenticationChallengeHandler property of the ArcGISEnvironment.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    // Create the challenge handler and set it on the authentication manager.
    final myNetworkChallengeHandler = MyNetworkChallengeHandler();
    
    ArcGISEnvironment.authenticationManager
      .networkAuthenticationChallengeHandler = myNetworkChallengeHandler;

Create and store credentials

When an authentication challenge is raised, your application can create a credential that is held in the ArcGIS and network credential stores provided by the AuthenticationManager.

These credential stores exist for the lifetime of the application. They ensure that an authentication challenge is only raised if a matching credential does not exist in the store. If you want to avoid prompting users for credentials between application sessions, persist the credential stores by using the static method initPersistentStore() on the ArcGIS credential store.

Use dark colors for code blocksCopy
1
2
ArcGISEnvironment.authenticationManager.arcGISCredentialStore =
    await ArcGISCredentialStore.initPersistentStore();

During application sign-out you should revoke all tokens and clear all credentials from the credential stores.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  @override
  void dispose() {
    // Remove the challenge handler from the ArcGIS environment.
    ArcGISEnvironment
        .authenticationManager.arcGISAuthenticationChallengeHandler = null;

    // Revoke OAuth tokens and remove all credentials to log out.
    Future.wait(
      ArcGISEnvironment.authenticationManager.arcGISCredentialStore
          .getCredentials()
          .whereType<OAuthUserCredential>()
          .map((credential) => credential.revokeToken()),
    ).catchError((error) {
      // Handle errors.
    }).whenComplete(() {
      ArcGISEnvironment.authenticationManager.arcGISCredentialStore.removeAll();
    });

    super.dispose();
  }

ArcGIS credentials

You can access secured resources with user authentication or app authentication using the following credential types.

If you know the services domain/server context, you can create an ArcGIS credential, independent of loading the specific resource and store it in the ArcGISCredentialStore.

OAuth user credential

To create an OAuthUserCredential, provide an OAuthUserConfiguration with a valid portal URL, client ID, and redirect URL. This will present the OAuth sign in page for the user to enter their username and password. Once the OAuthUserCredential is created, you will be able to retrieve the access token information from the asynchronous getTokenInfo() method.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
final oauthUserConfiguration = OAuthUserConfiguration(
    portalUri: portalUri,
    clientId: 'clientId',
    redirectUri: redirectUri,
);
final credential = await OAuthUserCredential.create(
    configuration: oauthUserConfiguration,
);
final tokenInfo = await credential.getTokenInfo();

OAuth application credential

To create an OAuthApplicationCredential, provide a valid portal URL, a client ID, and a client secret. Optionally, you can specify the token expiration in minutes. Once the OAuthApplicationCredential is created, you will be able to access the token information using the asynchronous getTokenInfo() method.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
final credential = OAuthApplicationCredential.create(
    portalUri: portalUri,
    clientId: 'clientId',
    clientSecret: 'clientSecret',
    tokenExpirationInterval: 5,
);
final tokenInfo = await credential.getTokenInfo();

Token credential

To create a TokenCredential, provide a secured service URL, valid username, and password. Optionally, you can specify token expiration minutes. Once a TokenCredential is created, you will be able to access token information from the asynchronous getTokenInfo() method.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
final credential = await TokenCredential.create(
    uri: uri,
    username: 'username',
    password: 'password',
    tokenExpirationInterval: 5,
);
final tokenInfo = await credential.getTokenInfo();

Pregenerated token credential

To create a PregeneratedTokenCredential, provide a previously generated short or long-lived access token. Use this credential when the access token is created using the generateToken REST endpoint directly. You must provide the referer if one was used while generating the token.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
final tokenInfo = TokenInfo.create(
    accessToken: 'accessToken',
    expirationDate: date,
    isSslRequired: true,
);
final credential = PregeneratedTokenCredential(
    uri: uri,
    tokenInfo: tokenInfo,
    referer: 'referer',
);

Network credentials

You can access resources secured by network authentication using the appropriate NetworkCredential:

Password credentials

  • The BasicNetworkCredential is used to authenticate HTTP Basic secured resources.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    final basicNetworkCredential = BasicNetworkCredential.forChallenge(
      challenge,
      'username',
      'password',
    );
  • The DigestNetworkCredential is used to authenticate HTTP Digest secured resources.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    final digestNetworkCredential = DigestNetworkCredential.forChallenge(
      challenge,
      'username',
      'password',
    );
  • The NtlmNetworkCredential is used to authenticate NTLM secured resources.

    Use dark colors for code blocksCopy
    1
    2
    3
    4
    5
    final ntlmNetworkCredential = NtlmNetworkCredential.forChallenge(
      challenge,
      'username',
      'password',
    );

Client certificate network credential

A ClientCertificateNetworkCredential is used to authenticate Public Key Infrastructure (PKI) secured resources. To create a client certificate network credential, pass in a string that represents the host, the URL to a .p12 or .pfx extension certificate file on disk and a password.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
final privateKey = File(
  '/path/to/certificate.pfx',
).readAsBytesSync();

final clientCertificateNetworkCredential = ClientCertificateNetworkCredential.forChallenge(
  challenge,
  privateKey,
  'password',
);

Server trust network credential

To trust a development server that uses a self-signed certificate (untrusted host), create a ServerTrustNetworkCredential and specify that the server should be trusted.

Use dark colors for code blocksCopy
1
2
final serverTrustNetworkCredential =
    ServerTrustNetworkCredential.forChallenge(challenge);

Samples

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.