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.
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. For more information see the OAuthApplicationCredential.
Be careful to adequately secure client secrets, access tokens, and user credentials. Never embed such information in a client application where it can be discovered by viewing the source code or using developer tools. See Security best practices for more information.
Choose a type of authenticationThe 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.
API key authenticationAn API key can grant your public-facing application access to specific ArcGIS services and portal items.
Use API key authentication when you want to:
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
.
Use dark colors for code blocks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ArcGISEnvironment.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")
setContent {
MaterialTheme {
val map = remember {
ArcGISMap(basemapStyle = BasemapStyle.ArcGISTopographic)
}
MapView(
modifier = Modifier.fillMaxSize(),
arcGISMap = map
)
}
}
}
}
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 blocks
1
2
3
4
5
6
7
8
val map = remember {
// Create a new ArcGIS basemap and apply an access token.
val basemap = Basemap(basemapStyle = BasemapStyle.ArcGISTopographic)
basemap.apiKey = ApiKey.create("YOUR_ACCESS_TOKEN")
// Create a new map with the basemap.
ArcGISMap(basemap = basemap)
}
Classes that implement ApiKeyResource
include:
ArcGISSceneLayer
ArcGISTiledLayer
ArcGISVectorTiledLayer
Basemap
BasemapStylesService
ClosestFacilityTask
ExportTileCacheTask
ExportVectorTilesTask
GeodatabaseSyncTask
LocatorTask
RouteTask
ServiceAreaTask
ServiceFeatureTable
All API keys created before June 2024 are known as API keys (legacy), or legacy API keys. Legacy API keys can no longer be created, and will cease to function after May 2026. See Update to API key credentials for instructions on how to migrate from legacy API keys to API key credentials.
For more information, see API key (legacy) retirement.
Learn more about API key authentication User authenticationUser 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:
You cannot access ArcGIS location services by authenticating with an ArcGIS Enterprise user account.
Learn more about user authentication App authenticationApp 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:
App authentication access tokens, generated using an ArcGIS Enterprise account, do not provide access to ArcGIS location services.
Learn more about app authenticationIn this SDK, all aspects of ArcGIS and network authentication have been encapsulated into a single ArcGIS Maps SDK for Kotlin toolkit component called the Authenticator. This component supports multiple types of authentication challenges, including ArcGIS authentication methods (OAuth, Identity-Aware Proxy (IAP), 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 prompts. For example, here is the default alert prompting the user for username and password credentials.
The Authenticator
composable is designed to be displayed on top of your app's UI. It should be called at a near-root level; for example, at the same level as a NavHost
or the Scaffold
containing your map or scene view. The Authenticator
should also be the last call of the function so it draws over other content. Username/password and server trust challenges are able to adapt to the size of the container, allowing flexible layout integration.
A toolkit composable named DialogAuthenticator
provides the same functionality as Authenticator
, but displays the username/password prompt and the server trust UI in a dialog.
All other authentication challengesâincluding OAuth, IAP, and client certificate promptsâare handled consistently across both composables, using the browser or Android certificate picker as appropriate.
The toolkit contains an essential related class named AuthenticatorState
, which handles authentication challenges and exposes state that the Authenticator
(or DialogAuthenticator
) displays to the end user. You create an AuthenticatorState
instance by calling the AuthenticatorState()
composable.
Call AuthenticatorState()
to create an implementation of the AuthenticatorState
interface. Then pass the authenticator state to the Authenticator
composable, which should be invoked after MapView
so that the login screen will hide the map view by displaying on top of it.
Use dark colors for code blocks
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
@Composable
fun Screen() {
val authenticatorState by remember { mutableStateOf(AuthenticatorState()) }
authenticatorState.oAuthUserConfigurations = listOf(
OAuthUserConfiguration(
portalUrl = "https://www.arcgis.com",
clientId = "Your client ID goes here",
redirectUrl = "Your redirect URL goes here"
)
)
val map = remember {
createMap()
}
Scaffold {
MapView(
modifier = Modifier
.fillMaxSize()
.padding(it),
arcGISMap = map
)
}
DialogAuthenticator(authenticatorState = authenticatorState)
}
If the authenticator is going to use OAuth or Identity-Aware Proxy (IAP), you must specify the OAuthConfiguration
or IapConfiguration
, add it to a list, and assign the list to the corresponding property on AuthenticatorState
.
Use dark colors for code blocks
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
authenticatorState.oAuthUserConfigurations = listOf(
OAuthUserConfiguration(
portalUrl = "https://www.arcgis.com", // or URL of your ArcGIS Enterprise or ArcGIS Location Platform portal.
clientId = "Your client ID goes here",
redirectUrl = "Your redirect URL goes here"
)
)
Use dark colors for code blocks
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
val iapConfiguration =
IapConfiguration.create("Your IAP configuration JSON file path goes here")
.getOrThrow()
authenticatorState.iapConfigurations = listOf(iapConfiguration)
You can also create a credential store that will be persistent between sessions. If the application is restarted, the credential store is automatically pre-populated with stored credentials, and the user does not have to sign in again. In this code, you assign the new credential store to ArcGISEnvironment.authenticatorManager.arcGISCredentialStore
. Configuration set on the AuthenticationManager
will be used by Authenticator
and DialogAuthenticator
.
Use dark colors for code blocks
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
ArcGISEnvironment.authenticationManager.arcGISCredentialStore =
ArcGISCredentialStore.createWithPersistence().getOrThrow()
During application sign-out all tokens should be revoked and all credentials cleared from the credentials store. AuthenticatorState.signOut()
revokes the tokens and clears the credentials store.
Use dark colors for code blocks
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
arcGISCredentialStore.getCredentials().forEach {
when {
it is OAuthUserCredential -> {
it.revokeToken()
}
it is IapCredential -> {
it.invalidate { iapSignOut ->
promptForIapSignOut(iapSignOut)
}
}
}
}
networkCredentialStore.removeAll()
arcGISCredentialStore.removeAll()
To see the Authenticator in action, including the use of OAuth, check out the Authentication Microapp.
Authentication managerIf 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 available as a static property on the ArcGISEnvironment
.
Use dark colors for code blocks Copy
1
ArcGISEnvironment.authenticationManager
The AuthenticationManager
provides:
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, Identity-Aware Proxy (IAP), 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 these authentication challenges using the ArcGISAuthenticationChallengeHandler
and NetworkAuthenticationChallengeHandler
, respectively. These are functional interfaces that each implement a single abstract method called handleArcGISAuthenticationChallenge()
and handleNetworkAuthenticationChallenge()
respectively. Instead of creating a class that implements the interface, you can use a lambda expression.
The ArcGISAuthenticationChallengeHandler
is used to handle authentication challenges from ArcGIS secured resources that require OAuth, Identity-Aware Proxy (IAP), or ArcGIS Token authentication. The recommended way to handle authentication changes is to use the Authenticator
component in the ArcGIS Maps SDK for Kotlin toolkit. If you choose not to use Authenticator
, you can handle the challenge in your code and return one of the following subclasses of the ArcGISAuthenticationChallengeResponse
sealed class:
ContinueWithCredential(ArcGISCredential)
- Handles the challenge with the specified credential.ContinueAndFail
- Handles the challenge without a credential, causing it to fail with the original authentication errorContinueAndFailWithError
- Handles the challenge with an error that occurred while trying to generate a credential. The request which issued the authentication challenge will fail with the given error.Cancel
- Cancels the request that initiated the challenge.Create a custom ArcGISAuthenticationChallengeHandler
and assign it to the AuthenticationManager.arcGISAuthenticationChallengeHandler
.
Use dark colors for code blocks Copy
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
ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler =
ArcGISAuthenticationChallengeHandler { challenge ->
when (challenge.type) {
ArcGISAuthenticationChallengeType.Iap -> {
val matchingIapConfiguration = iapConfigurations.first {
it.canBeUsedForUrl(challenge.requestUrl)
}
val iapCredential =
IapCredential.create(matchingIapConfiguration) { iapSignIn ->
// Prompt to open browser for IAP sign in
// ...
}.getOrThrow()
ArcGISAuthenticationChallengeResponse.ContinueWithCredential(
iapCredential
)
}
ArcGISAuthenticationChallengeType.OAuthOrToken -> {
val matchingOAuthUserConfiguration = oAuthUserConfigurations.first {
it.canBeUsedForUrl(challenge.requestUrl)
}
val oAuthUserCredential =
OAuthUserCredential.create(matchingOAuthUserConfiguration) { oAuthUserSignIn ->
// Prompt to open browser and sign in with Oauth username and password.
// ...
}.getOrThrow()
ArcGISAuthenticationChallengeResponse.ContinueWithCredential(
oAuthUserCredential
)
}
ArcGISAuthenticationChallengeType.Token -> {
val tokenCredential =
TokenCredential.createWithChallenge(challenge, username, password)
.getOrThrow()
ArcGISAuthenticationChallengeResponse.ContinueWithCredential(
tokenCredential
)
}
}
}
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 and return one of the following subclasses of the NetworkAuthenticationChallengeResponse
sealed class.
ContinueWithCredentia(NetworkCredential)
- Handles the challenge with the specified credential.ContinueAndFail
- Handles the challenge without a credential, causing it to fail with the original authentication errorContinueAndFailWithError
- Handles the challenge with an error that occurred while trying to generate a credential. The request which issued the authentication challenge will fail with the given error.Cancel
- Cancels the request that initiated the challenge.Create a custom NetworkAuthenticationChallengeHandler
and pass it to the AuthenticationManager.networkAuthenticationChallengeHandler
.
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ArcGISEnvironment.authenticationManager.networkAuthenticationChallengeHandler =
NetworkAuthenticationChallengeHandler { authenticationChallenge ->
when (authenticationChallenge.networkAuthenticationType) {
is NetworkAuthenticationType.UsernamePassword ->
// Create the Password Credential
val credential = PasswordCredential(username, password)
NetworkAuthenticationChallengeResponse.ContinueWithCredential(credential)
is NetworkAuthenticationType.ServerTrust ->
NetworkAuthenticationChallengeResponse.ContinueWithCredential(ServerTrust)
is NetworkAuthenticationType.Certificate -> {
val selectedAlias = showCertificatePicker(activityContext)
selectedAlias?.let {
NetworkAuthenticationChallengeResponse.ContinueWithCredential(CertificateCredential(it))
} ?: NetworkAuthenticationChallengeResponse.ContinueAndFail
}
}
}
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
.
ArcGISCredentialStore
stores ArcGIS credentials.NetworkCredentialStore
stores Network credentials.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 using the companion functions ArcGISCredentialStore.createWithPersistence()
and NetworkCredentialStore.createWithPersistence()
. This uses Android's EncryptedSharedPreferences.
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
lifecycleScope.launch {
val arcGISCredentialStore = ArcGISCredentialStore.createWithPersistence().getOrThrow()
ArcGISEnvironment.authenticationManager.arcGISCredentialStore = arcGISCredentialStore
val networkCredentialStore = NetworkCredentialStore.createWithPersistence().getOrThrow()
ArcGISEnvironment.authenticationManager.networkCredentialStore = networkCredentialStore
}
During application sign-out you should revoke all tokens and clear all credentials from the credential stores.
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
val arcGISCredentialStore = ArcGISEnvironment.authenticationManager.arcGISCredentialStore
val networkCredentialStore =
ArcGISEnvironment.authenticationManager.networkCredentialStore
arcGISCredentialStore.getCredentials ().forEach {
when {
it is OAuthUserCredential -> {
it.revokeToken()
}
it is IapCredential -> {
it.invalidate { iapSignOut ->
promptForIapSignOut(iapSignOut)
}
}
}
networkCredentialStore.removeAll()
arcGISCredentialStore.removeAll()
Note
If your application is using an IapCredential
, a Microsoft page will be presented that allows the user to sign-out. Note that after a successful sign-out, the user must click the Cancel button to return to your application.
You can access secure resources with user authentication or app authentication using any of the following credential types:
OAuthUserConfiguration
.IapConfiguration
.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
.
To create an OAuthUserCredential
, instantiate an OAuthUserConfiguration
with a valid portal URL, client ID, and redirect URL, and wrap the instance in a list. You must present a prompt, in a browser supported by the device, for the user to enter their username and password. The response from the browser should be handled within your activity or the fragment that launched the browser prompt. Once the OAuthUserCredential
is created, you will be able to access the token information by calling getTokenInfo()
on the credential.
Use dark colors for code blocks Copy
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
// Define OAuthConfiguration
val oAuthUserConfiguration = OAuthUserConfiguration(
"<portal URL>",
"<ClientID>",
"<redirectURI>"
)
lifecycleScope.launch {
val oAuthUserCredential = OAuthUserCredential.create(oAuthUserConfiguration) { oAuthUserSignIn ->
promptForOAuthUserSignIn(oAuthUserSignIn)
}.getOrThrow()
oAuthUserCredential.getTokenInfo()
}
See the Android documentation for details on how to launch custom chrome tabs in android and work with getting result from an activity. If you use the Authenticator
in the Toolkit, all this is handled for you.
To see this authentication in action, look at the Authenticate with OAuth sample.
IapCredentialThe IapCredential
supports access to an ArcGIS Enterprise portal and its services that are protected behind an Identity-Aware Proxy (IAP). You must present a prompt, in a browser supported by the device, for the user to enter their username and password. The response from the browser should be handled within your activity or the fragment that launched the browser prompt.
To initiate an IAP authorization workflow, create an IapConfiguration
to store your application's registration details and use it to create an IapCredential
. Follow the steps below to create an IapCredential
:
To establish trust between your application and the IAP, you administrator registers your application with the Microsoft Identity Platform. Following this, you will be able to review the client ID, tenant ID, redirect url, and so on.
Create the IapConfiguration
using these app 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 JSON file containing the following key/value pairs:
Use dark colors for code blocks Copy
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:
Create the IapConfiguration
using the IapConfiguration.create(path)
companion function.
Use dark colors for code blocks Copy
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
val iapConfigurationFromJson = IapConfiguration.create("/path/to/IAP/configuration/file.json").getOrElse { error ->
showMessage(error.message.toString())
}
If the JSON file is missing any required properties, the IapConfiguration
will fail.
Alternatively, create the IapConfiguration
by specifying each parameter in the IapConfiguration.create()
companion function.
Use dark colors for code blocks Copy
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
val iapConfiguration = IapConfiguration.create(
authorizeUrl = "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize",
tokenUrl = "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token",
logoutUrl = "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/logout",
clientId = "<client_id>",
clientSecret = "<client_secret>",
redirectUrl = "<redirect_url>",
iapClientId = "<iap_client_id>",
scopes = listOf(
"<client_id>/.default", "offline_access", "openid", "profile"
),
hostsBehindProxy = listOf("*.domain.com"),
authorizationPromptType = IapAuthorizationPromptType.Unspecified
)
Best Practice: To avoid storing secure information in you app's code, the recommended approach is to use the IapConfiguration.create(path)
companion function using a JSON file on disk to create a IapConfiguration
.
Implement the functional interface ArcGISAuthenticationChallengeHandler
. Inside the lambda, check if the challenge is of type ArcGISAuthenticationChallengeType.Iap
.
Use dark colors for code blocks
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler =
ArcGISAuthenticationChallengeHandler { challenge ->
if (challenge.type == ArcGISAuthenticationChallengeType.Iap) {
val matchingIapConfiguration = iapConfigurations.first { iapConfiguration ->
}
}
}
Call IapConfiguration.canBeUsedForUrl()
to check if the configuration can be used for the requestUrl()
contained in the challenge. A configuration can be used for a URL if the URL's host matches one of the hosts specified in the configuration's hosts behind proxy.
Use dark colors for code blocks
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler =
ArcGISAuthenticationChallengeHandler { challenge ->
if (challenge.type == ArcGISAuthenticationChallengeType.Iap) {
val matchingIapConfiguration = iapConfigurations.first { iapConfiguration ->
iapConfiguration.canBeUsedForUrl(challenge.requestUrl)
}
}
}
Create an IapCredential
by calling the IapCredential.create()
companion function and passing in the IapConfiguration
. This will present the sign-in page for the user to enter their username and password. Once the IapCredential
is created, it will be added to the ArcGISCredentialStore
, and you will be able to access token information by calling getTokenInfo()
on the credential.
Use dark colors for code blocks
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler =
ArcGISAuthenticationChallengeHandler { challenge ->
if (challenge.type == ArcGISAuthenticationChallengeType.Iap) {
val matchingIapConfiguration = iapConfigurations.first { iapConfiguration ->
iapConfiguration.canBeUsedForUrl(challenge.requestUrl)
}
iapCredential =
IapCredential.create(matchingIapConfiguration) { iapSignIn ->
promptForIapSignIn(iapSignIn)
// ...
}.getOrThrow()
val iapTokenInfo = iapCredential.getTokenInfo().getOrThrow()
ArcGISAuthenticationChallengeResponse.ContinueWithCredential(
iapCredential
)
}
// Handle other types of ArcGIS AuthenticationChallenge.
else if (challenge.type == ArcGISAuthenticationChallengeType.OAuthOrToken) {
// ...
}
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 user must click the Cancel button to return to your application.
Use dark colors for code blocks Copy
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
val signOutRequestResult = iapCredential.invalidate { iapSignOut ->
promptForIapSignOut(iapSignOut)
}
if (signOutRequestResult.isSuccess) {
showMessage("Invalidation of the IAP session was successful")
} else {
showMessage("Invalidation of the IAP session failed: ${signOutRequestResult.exceptionOrNull()?.message}")
}
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 by calling getTokenInfo()
on the credential.
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
scope.launch {
TokenCredential.create(requestUrl,username, password, 30).onSuccess {
// Get accesstoken from credential
var tokenInfo = it.getTokenInfo().getOrNull()
var accessToken = tokenInfo?.accessToken
}
}
PregeneratedTokenCredential
To create a PregeneratedTokenCredential
, provide a previously generated short or long-lived access token. Use this 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 blocks Copy
1
2
3
var accessToken = "xxxxxxx"
var tokenInfo = val tokenInfo = TokenInfo(accessToken, Instant.now().plus(2, ChronoUnit.HOURS), true)
var pregeneratedTokenCredential = PregeneratedTokenCredential(requestUrl, tokenInfo)
OAuthApplicationCredential
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 by calling getTokenInfo()
on the credential.
Use dark colors for code blocks Copy
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
lifecycleScope.launch {
val oAuthApplicationCredential = OAuthApplicationCredential.create(
portalUrl = "portalUrl",
clientId = "clientId",
clientSecret = "clientSecret",
tokenExpirationInterval = 30
).getOrNull() ?: return@launch
val oAuthApplicationTokenInfo = oAuthApplicationCredential.getTokenInfo().getOrThrow()
ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler =
ArcGISAuthenticationChallengeHandler {
ArcGISAuthenticationChallengeResponse.ContinueWithCredential(oAuthApplicationCredential)
}
}
Attention
It is important that you secure the client secret like you would a password. Never embed it in a client application where it can be discovered through viewing source or developer tools.
Network credentialsYou can access resources secured by network authentication using the following credential types:
The PasswordCredential
is used to authenticate HTTP Basic or Integrated Windows Authentication (IWA) secured resources.
Use dark colors for code blocks Copy
1
var passwordCredential = PasswordCredential("username", "password")
CertificateCredential
CertificateCredential
represents a digital client certificate used to access certificate secured resources. All the digital certificates need to be pre-installed in the device keychain. The CertificateCredential
can be created using the alias of the chosen certificate.
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
private suspend fun showCertificatePicker(activityContext: Activity): String? =
suspendCancellableCoroutine { continuation ->
val aliasCallback = KeyChainAliasCallback { alias ->
continuation.resume(alias)
}
KeyChain.choosePrivateKeyAlias(
activityContext, aliasCallback, null, null, null, null
)
}
val selectedAlias = showCertificatePicker(activityContext)
var certificateCredential = selectedAlias?.let { CertificateCredential(it) } ?: null
Tutorials Samples
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4