Skip to content

You can access resources secured with user authentication, app authentication, or network authentication using the available credential types.

  • ArcGIS credentials are used to access resources secured by ArcGIS authentication methods, such as OAuth, Identity-Aware Proxy (IAP), and ArcGIS token. For more information, see ArcGIS credentials.
  • Network credentials are used to access resources secured by network authentication methods, such as Integrated Windows Authentication (IWA) and Client Certificate (PKI). For more information, see Network credentials.

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();

IapCredential

The IapCredential supports access to an ArcGIS Enterprise portal and its services that are protected behind an Identity-Aware Proxy (IAP). ArcGIS Maps SDK for Flutter currently supports the Microsort Entra Application Proxy via the Microsoft Identity Platform. To initiate an IAP authorization workflow, create an IapConfiguration to store your application's registration details and use it to create an IapCredential.

Use the following steps to create an IapCredential:

To establish trust between your application and the IAP, your administrator registers your application with the Microsoft Identity Platform. Following this, you can review the client ID, tenant ID, redirect url, and so on.

Create an IapConfiguration using these application registration details. Depending on your workflow, you can initialize an IapConfiguration by either providing the details in a JSON file or supplying them directly in the application's code.

To initialize the IapConfiguration with a JSON file, create a Microsort Entra Application Proxy JSON file containing the following key/value pairs:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"authorize_url" : "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize",
"token_url" : "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token",
"logout_url" : "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/logout",
"client_id" : "<client_id>",
"redirect_url" : "<redirect_url>",
"scope" : [
    "<client_id>/.default",
    "offline_access",
    "openid",
    "profile"
],
"hosts_behind_proxy" : ["*.domain.com"],
"authorization_prompt_type" : "<empty string, none, login, consent, or select_account>"
}

The keys are defined as follows:

  • authorize_url - The authorization endpoint of the Identity-Aware Proxy (IAP) portal.
  • token_url - The token endpoint of the Identity-Aware Proxy (IAP) portal.
  • logout_url - The logout endpoint of the Identity-Aware Proxy (IAP) portal.
  • client_id - A unique identifier associated with an application which is registered with the Identity-Aware Proxy (IAP) portal.
  • redirect_url - The URL that the Identity-Aware Proxy (IAP) login and logout pages will redirect to when authentication completes. The scheme of this URL must be registered as a custom URL scheme in the application.
  • scope - The scope of user's account.
  • hosts_behind_proxy - The hosts to be accessed behind the Identity-Aware Proxy (IAP).
  • authorization_prompt_type - The type of user interaction required for authentication and consent while signing in to the Identity-Aware Proxy (IAP).

Create the IapConfiguration using the IapConfiguration.create() initializer.

Use dark colors for code blocksCopy
1
    final iapConfiguration = await IapConfiguration.create(iapConfigurationFileUri);

If the JSON file is missing any required properties, this IapConfiguration initializer will fail.

Alternatively, create the IapConfiguration by specifying each parameter in the IapConfiguration constructor.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    IapConfiguration(
        authorizeUri: Uri.parse(
        'https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize',
        ),
        tokenUri: Uri.parse(
        'https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token',
        ),
        logoutUri: Uri.parse(
        'https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/logout',
        ),
        clientId: '<client_id>',
        redirectUri: Uri.parse('<redirect_url>'),
        scopes: ['<client_id>/.default', 'offline_access', 'openid', 'profile'],
        hostsBehindProxy: ['*.domain.com'],
    );

Best Practice: To avoid storing secure information in you application's code, the recommended approach is to use the IapConfiguration.create() initializer with a JSON file on disk to create a IapConfiguration.

To ensure that the IapConfiguration can be used when an authentication challenge is issued for IAP credential, call IapConfiguration.canBeUsedForUri() using a URL specified in the configuration’s hosts behind proxy.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
if (iapConfiguration.canBeUsedForUri(
        Uri.parse(
        '<ArcGIS Enterprise resource URL of host specified in hostsBehindProxy>',
        ),
    )) {
        debugPrint(
            'The IAP configuration supports access to the Identity-Aware Proxy.',
        );
    } else {
        debugPrint(
            'The IAP configuration can not be used for the given url. Review the configuration parameters.',
    );
}

Create the IapCredential using the IapConfiguration. This will present the Microsoft sign-in page for the user to enter their username and password. Once the IapCredential is created, it is added to the ArcGISCredentialStore and you can access its tokenInfo property.

Use dark colors for code blocksCopy
1
2
    final iapCredential = await IapCredential.create(iapConfiguration);
    final tokenInfo = await iapCredential.getTokenInfo();

During application sign-out, you must invalidate the credential by calling IapCredential.invalidate(). This will present a Microsoft page that allows the user to sign-out. Note that after a successful sign-out, the browser will not redirect back to the application. The user must manually switch back to the application after sign-out.

Use dark colors for code blocksCopy
1
2
    // Returns true if the logout request is successful, otherwise false.
    await iapCredential.invalidate();

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 for 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);

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