A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.arcgis.com/swift/security-and-authentication/ below:

Security and authentication | ArcGIS Maps SDK for Swift

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:

Security and authentication guide

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 authentication

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

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 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:

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.

MainApp.swift

Use dark colors for code blocks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import SwiftUI
import ArcGIS

@main
struct MainApp: App {

    init() {
        ArcGISEnvironment.apiKey = APIKey("<#YOUR-ACCESS-TOKEN#>")
    }

    var body: some SwiftUI.Scene {
        WindowGroup {
            ContentView()
                .ignoresSafeArea()
        }
    }
}

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
// Create a new ArcGIS basemap and apply an access token.
let basemap = Basemap(style: .arcGISNavigation)
basemap.apiKey = APIKey("<#YOUR-ACCESS-TOKEN#>")

// Create a new map with the basemap.
let map = Map(basemap: basemap)

Classes that implement APIKeyResource include:

Attention

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 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:

Note

You cannot access ArcGIS location services by authenticating with an ArcGIS Enterprise user account.

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:

Note

App authentication access tokens, generated using an ArcGIS Enterprise account, do not provide access to ArcGIS location services.

Learn more about app authentication

In this SDK, all aspects of ArcGIS and network authentication have been encapsulated into a single ArcGIS Maps SDK for Swift 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 dialogs. For example, here is the default alert prompting the user for username and password credentials.

  1. In the application's App struct, import the ArcGISToolkit and create an instance of the Authenticator. Ensure that the application's AuthenticationManager uses the authenticator to handle authentication challenges. Set the authenticator view modifier so that a prompt can be displayed if the authenticator is asked to handle an authentication challenge.

    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
    
    import SwiftUI
    import ArcGIS
    import ArcGISToolkit
    
    struct AuthenticationApp: App {
    
        @ObservedObject var authenticator: Authenticator
    
        init() {
            // Creates an authenticator object.
            authenticator = Authenticator()
            // Sets the authenticator to handle authentication challenges.
            ArcGISEnvironment.authenticationManager.handleChallenges(using: authenticator)
        }
    
    
        var body: some SwiftUI.Scene {
            WindowGroup {
                ContentView()
                // Sets the authenticator view modifier.
                .authenticator(authenticator)
    
    
            }
        }
    
    }
  2. If the authenticator is going to use OAuth or Identity-Aware Proxy (IAP), you must specify the necessary configurations in a task in the application's body property.

    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
        var body: some SwiftUI.Scene {
            WindowGroup {
                ContentView()
                // Sets the authenticator view modifier.
                .authenticator(authenticator)
    
                // Defines the OAuth or Identity-Aware Proxy (IAP) configurations.
                .task {
                    authenticator.oAuthUserConfigurations.append(
                        OAuthUserConfiguration(
                            portalURL: URL(string: "Your client portal URL goes here")!,
                            clientID: "Your client ID goes here",
                            redirectURL: URL(string: "Your redirect URL goes here")!
                        )
                    )
                    try? await authenticator.iapConfigurations.append(
                        IAPConfiguration.configuration(from: URL(filePath: "Your IAP configuration JSON file path goes here")!)
                    )
                }
    
    
            }
        }
    
  3. You can also configure the authenticator to persist credentials in the keychain. If the application is restarted, the store of credentials is automatically pre-populated with saved credentials and the user does not have to sign in again.

    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
                // Persists the credentials in the keychain.
                .task {
                    try? await ArcGISEnvironment.authenticationManager.setupPersistentCredentialStorage(
                        access: .whenUnlockedThisDeviceOnly,
                        synchronizesWithiCloud: false
                    )
                }
    
  4. During application sign-out you should revoke all tokens then clear all credentials from the credentials 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
    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
            // Revokes OAuth refresh and access tokens
            await ArcGISEnvironment.authenticationManager.revokeOAuthTokens()
            // Clears all ArcGIS and network credentials from their respective stores.
            await ArcGISEnvironment.authenticationManager.clearCredentialStores()
    

To see the Authenticator in action, check out the Authentication Example application and refer to AuthenticationApp.swift in your project.

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 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        let authenticationManager = ArcGISEnvironment.authenticationManager

The AuthenticationManager provides:

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:

You can catch and respond to these authentication challenges using the ArcGISAuthenticationChallengeHandler and NetworkAuthenticationChallengeHandler, respectively.

ArcGIS authentication challenge handler

The ArcGISAuthenticationChallengeHandler is used to handle authentication challenges from ArcGIS secured resources that require OAuth, Identity-Aware Proxy (IAP), or ArcGIS Token authentication. Handle the challenge by returning the ArcGISAuthenticationChallenge.Disposition with any of the following options:

  1. Create a class that adopts the ArcGISAuthenticationChallengeHandler protocol to handle ArcGIS authentication challenges.

    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
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    @MainActor
    // Creates an ArcGIS authentication challenge handler
    final class MyArcGISChallengeHandler: ArcGISAuthenticationChallengeHandler {
        // The OAuth configurations that this challenge handler can work with.
        let oAuthUserConfigurations: [OAuthUserConfiguration]
        public init(
            oAuthUserConfigurations: [OAuthUserConfiguration] = []
        ) {
            self.oAuthUserConfigurations = oAuthUserConfigurations
        }
    
        // Handles the challenge to an ArcGIS secured resource that requires OAuth or ArcGIS Token authentication.
        func handleArcGISAuthenticationChallenge(
            _ challenge: ArcGISAuthenticationChallenge
        ) async throws -> ArcGISAuthenticationChallenge.Disposition {
            // If an OAuth user configuration is available for the challenge then create an `OAuthUserCredential`.
            if let configuration = oAuthUserConfigurations.first(where: { $0.canBeUsed(for: challenge.requestURL) }) {
                return .continueWithCredential(
                    try await OAuthUserCredential.credential(for: configuration)
                )
            } else {
                // If not, prompt the user for a username and password to create a `TokenCredential`.
                // ...
                return .continueWithCredential(
                    try await TokenCredential.credential(for: challenge, username: "username", password: "password")
                )
            }
        }
    }
    
  2. Set an instance of the class on the AuthenticationManager.arcGISAuthenticationChallengeHandler property of the ArcGISEnvironment.

    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
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
        // Creates the challenge handler with desired OAuth user configurations and set it on the `AuthenticationManager`.
        let myArcGISChallengeHandler = MyArcGISChallengeHandler(oAuthUserConfigurations: [OAuthUserConfiguration(portalURL: URL(string: "my-portal-URL")!, clientID: "my-client-ID", redirectURL: URL(string: "my-redirect-URL")!)])
        ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler = myArcGISChallengeHandler
    
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 the NetworkAuthenticationChallenge.Disposition with any of the following options:

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

    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
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    // Creates a Network authentication challenge handler
    final class MyNetworkChallengeHandler: NetworkAuthenticationChallengeHandler {
        func handleNetworkAuthenticationChallenge(
            _ challenge: NetworkAuthenticationChallenge
        ) async -> NetworkAuthenticationChallenge.Disposition {
            switch challenge.kind {
            case .ntlm, .basic, .digest:
                // Prompts the user for a username and password to create a `NetworkCredential`.
                // ...
                return .continueWithCredential(.password(username: "username", password: "password"))
            case .clientCertificate:
                // Prompts the user for a client certificate to create a `NetworkCredential`.
                // ...
                do {
                    return .continueWithCredential(try .certificate(at: URL(fileURLWithPath: "/pathToCertificate"), password: "password"))
                } catch {
                    return .continueWithoutCredential
                }
            case .serverTrust:
                // Prompts user to ask if they want to trust an untrusted host.
                // ...
                return .continueWithCredential(.serverTrust)
            case .negotiate:
                // Rejects the negotiate challenge so next authentication protection
                // space is tried.
                return .rejectProtectionSpace
            @unknown default:
                return .cancel
            }
        }
    }
    
  2. Set an instance of the class on the AuthenticationManager.networkAuthenticationChallengeHandler property of the ArcGISEnvironment.

    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
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
        // Creates the challenge handler and set it on the `AuthenticationManager`.
        let 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 exists in the store. If you want to avoid prompting users for credentials between application sessions, persist the credential stores in the keychain by using the function makePersistent(access:synchronizesWithiCloud:) on the authentication manager.

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        ArcGISEnvironment.authenticationManager.arcGISCredentialStore = try await .makePersistent(
            access: .afterFirstUnlockThisDeviceOnly,
            synchronizesWithiCloud: true
        )
        await ArcGISEnvironment.authenticationManager.setNetworkCredentialStore(
            try await .makePersistent(access: .afterFirstUnlockThisDeviceOnly, synchronizesWithiCloud: true)
        )

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
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

    func signOut() async throws {
        await revokeOAuthTokens()
        await invalidateIAPCredentials()
        arcGISCredentialStore.removeAll()
        await networkCredentialStore.removeAll()
    }

    @discardableResult
    func revokeOAuthTokens() async -> Bool {
        let oAuthUserCredentials = arcGISCredentialStore.credentials.compactMap { $0 as? OAuthUserCredential }
        return await withTaskGroup(of: Bool.self, returning: Bool.self) { group in
            for credential in oAuthUserCredentials {
                group.addTask {
                    do {
                        try await credential.revokeToken()
                        return true
                    } catch {
                        return false
                    }
                }
            }

            return await group.allSatisfy(\.self)
        }
    }

    @discardableResult
    func invalidateIAPCredentials() async -> Bool {
        let iapCredentials = arcGISCredentialStore.credentials.compactMap {
            $0 as? IAPCredential
        }
        return await withTaskGroup(of: Bool.self, returning: Bool.self) { group in
            for credential in iapCredentials {
                group.addTask {
                    return (try? await credential.invalidate()) ?? false
                }
            }

            return await group.allSatisfy(\.self)
        }
    }
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.

ArcGIS credentials

You can access secured resources with user authentication or app authentication using any of 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.

OAuthUserCredential

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 access token information from the asynchronous tokenInfo property.

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        let configuration = OAuthUserConfiguration(
            portalURL: URL(string: "portal-string")!,
            clientID: "client-ID",
            redirectURL: URL(string: "redirect-string")!
        )
        let credential = try await OAuthUserCredential.credential(for: configuration)
        let tokenInfo = try await credential.tokenInfo
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 Swift 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.

Note

Using a private or ephemeral web browser session is not recommended when creating or invalidating IAPCredential and OAuthUserCredential for user authentication to access the Identity-Aware Proxy (IAP). This is because such sessions may require users to enter their credentials multiple times.

Use the following steps to create an IAPCredential:

  1. 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.

  2. 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.

    1. 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 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:

      • authorize_url - The authorize 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).
    2. Create the IAPConfiguration using the IAPConfiguration.configuration(from:) initializer.

      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
          static var iapConfigurationFromJSON: IAPConfiguration {
              get async throws {
                  try await .configuration(
                      from: URL(filePath: "/path/to/IAP configuration/file.json")!
                  )
              }
          }
      

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

    3. Alternatively, create the IAPConfiguration by specifying each parameter in the IAPConfiguration.configuration initializer.

      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
          static var iapConfiguration: IAPConfiguration {
              try! .configuration(
                  authorizeURL: URL(string: "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize")!,
                  tokenURL: URL(string: "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token")!,
                  logoutURL: URL(string: "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/logout")!,
                  clientID: "<client_id>",
                  redirectURL: URL(string: "<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.configuration(from:) initializer uses a JSON file on disk to create a IAPConfiguration.

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

    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
            if iapConfiguration.canBeUsed(for: URL(string: "<ArcGIS Enterprise resource URL of host specified in hostsBehindProxy>")) {
                print("The IAP configuration supports access to the Identity-Aware Proxy.")
            } else {
                print("The IAP configuration can not be used for the given url. Review the configuration parameters.")
            }
    
  4. 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 will be added to the ArcGISCredentialStore and you will be able to access its tokenInfo property.

    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
          let iapCredential = try await IAPCredential.credential(for: iapConfiguration)
    
          let tokenInfo = try await iapCredential.tokenInfo
    
  5. 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
            do {
                try await iapCredential.invalidate()
            } catch {
                print("IAP credential is not invalidated.")
            }
    
TokenCredential

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 tokenInfo property.

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        let credential = try await TokenCredential.credential(
            for: URL(string: "portal-string")!,
            username: "username",
            password: "password",
            tokenExpirationMinutes: 5
        )
        let tokenInfo = try await credential.tokenInfo
PregeneratedTokenCredential

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 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        let tokenInfo = TokenInfo(
            accessToken: "<access-token",
            expirationDate: date,
            isSSLRequired: true
        )
        let credential = PregeneratedTokenCredential(
            url: URL(string: "service-string")!,
            tokenInfo: tokenInfo!,
            referer: "referer"
        )
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 from the asynchronous tokenInfo property.

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        let credential = try await OAuthApplicationCredential.credential(
            for: URL(string: "portal-string")!,
            clientID: "client-ID",
            clientSecret: "client-secret",
            tokenExpirationMinutes: 5
        )
        let tokenInfo = try await credential.tokenInfo
Note

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 credentials

You can access resources secured by network authentication using the following credential types.

PasswordCredential

The PasswordCredential is used to authenticate HTTP Basic/Digest, Integrated Windows Authentication (IWA) secured resources. To create a PasswordCredential, use a static function of NetworkCredential with username and a password.

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        // Password credential for HTTP Basic/Digest, Integrated Windows Authentication (IWA)
        let passwordCredential = NetworkCredential.password(username: "my-username", password: "my-password")
CertificateCredential

A CertificateCredential is used to authenticate Public Key Infrastructure (PKI) secured resources. To create a CertificateCredential, use a static function of NetworkCredential with the URL to a .p12 or .pfx extension certificate file on disk and a password.

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        let credential = try NetworkCredential.certificate(at: URL(fileURLWithPath: "file URL to .p12 or .pfx file"), password: "password")
ServerTrust

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

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        // Server trust credential for host with self-signed certificate
        let credential = NetworkCredential.serverTrust
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