@@ -37,55 +37,6 @@ public final class Authenticator: ObservableObject {
37
37
self . oAuthUserConfigurations = oAuthUserConfigurations
38
38
}
39
39
40
- /// Sets the ArcGIS and Network challenge handlers to be this authenticator.
41
- public func setupAuthenticationChallengeHandlers( ) {
42
- ArcGISEnvironment . authenticationManager. arcGISAuthenticationChallengeHandler = self
43
- ArcGISEnvironment . authenticationManager. networkAuthenticationChallengeHandler = self
44
- }
45
-
46
- /// Sets up new credential stores that will be persisted to the keychain.
47
- /// - Remark: The credentials will be stored in the default access group of the keychain.
48
- /// You can find more information about what the default group would be here:
49
- /// https://developer.apple.com/documentation/security/keychain_services/keychain_items/sharing_access_to_keychain_items_among_a_collection_of_apps
50
- /// - Parameters:
51
- /// - access: When the credentials stored in the keychain can be accessed.
52
- /// - synchronizesWithiCloud: A Boolean value indicating whether the credentials are synchronized with iCloud.
53
- public func setupPersistentCredentialStorage(
54
- access: ArcGIS . KeychainAccess ,
55
- synchronizesWithiCloud: Bool = false
56
- ) async throws {
57
- let previousArcGISCredentialStore = ArcGISEnvironment . authenticationManager. arcGISCredentialStore
58
-
59
- // Set a persistent ArcGIS credential store on the ArcGIS environment.
60
- ArcGISEnvironment . authenticationManager. arcGISCredentialStore = try await . makePersistent(
61
- access: access,
62
- synchronizesWithiCloud: synchronizesWithiCloud
63
- )
64
-
65
- do {
66
- // Set a persistent network credential store on the ArcGIS environment.
67
- await ArcGISEnvironment . authenticationManager. setNetworkCredentialStore (
68
- try await . makePersistent( access: access, synchronizesWithiCloud: synchronizesWithiCloud)
69
- )
70
- } catch {
71
- // If making the shared network credential store persistent fails,
72
- // then restore the ArcGIS credential store.
73
- ArcGISEnvironment . authenticationManager. arcGISCredentialStore = previousArcGISCredentialStore
74
- throw error
75
- }
76
- }
77
-
78
- /// Clears all ArcGIS and network credentials from the respective stores.
79
- /// Note: This sets up new `URLSessions` so that removed network credentials are respected
80
- /// right away.
81
- public func clearCredentialStores( ) async {
82
- // Clear ArcGIS Credentials.
83
- ArcGISEnvironment . authenticationManager. arcGISCredentialStore. removeAll ( )
84
-
85
- // Clear network credentials.
86
- await ArcGISEnvironment . authenticationManager. networkCredentialStore. removeAll ( )
87
- }
88
-
89
40
/// The current challenge.
90
41
/// This property is not set for OAuth challenges.
91
42
@Published var currentChallenge : ChallengeContinuation ?
@@ -137,3 +88,56 @@ extension Authenticator: NetworkAuthenticationChallengeHandler {
137
88
return await challengeContinuation. value
138
89
}
139
90
}
91
+
92
+ public extension AuthenticationManager {
93
+ /// Sets authenticator as ArcGIS and Network challenge handlers to handle authentication
94
+ /// challenges.
95
+ /// - Parameter authenticator: The authenticator to be used for handling challenges.
96
+ func handleAuthenticationChallenges( using authenticator: Authenticator ) {
97
+ ArcGISEnvironment . authenticationManager. arcGISAuthenticationChallengeHandler = authenticator
98
+ ArcGISEnvironment . authenticationManager. networkAuthenticationChallengeHandler = authenticator
99
+ }
100
+
101
+ /// Sets up new credential stores that will be persisted to the keychain.
102
+ /// - Remark: The credentials will be stored in the default access group of the keychain.
103
+ /// You can find more information about what the default group would be here:
104
+ /// https://developer.apple.com/documentation/security/keychain_services/keychain_items/sharing_access_to_keychain_items_among_a_collection_of_apps
105
+ /// - Parameters:
106
+ /// - access: When the credentials stored in the keychain can be accessed.
107
+ /// - synchronizesWithiCloud: A Boolean value indicating whether the credentials are synchronized with iCloud.
108
+ func setupPersistentCredentialStorage(
109
+ access: ArcGIS . KeychainAccess ,
110
+ synchronizesWithiCloud: Bool = false
111
+ ) async throws {
112
+ let previousArcGISCredentialStore = ArcGISEnvironment . authenticationManager. arcGISCredentialStore
113
+
114
+ // Set a persistent ArcGIS credential store on the ArcGIS environment.
115
+ ArcGISEnvironment . authenticationManager. arcGISCredentialStore = try await . makePersistent(
116
+ access: access,
117
+ synchronizesWithiCloud: synchronizesWithiCloud
118
+ )
119
+
120
+ do {
121
+ // Set a persistent network credential store on the ArcGIS environment.
122
+ await ArcGISEnvironment . authenticationManager. setNetworkCredentialStore (
123
+ try await . makePersistent( access: access, synchronizesWithiCloud: synchronizesWithiCloud)
124
+ )
125
+ } catch {
126
+ // If making the shared network credential store persistent fails,
127
+ // then restore the ArcGIS credential store.
128
+ ArcGISEnvironment . authenticationManager. arcGISCredentialStore = previousArcGISCredentialStore
129
+ throw error
130
+ }
131
+ }
132
+
133
+ /// Clears all ArcGIS and network credentials from the respective stores.
134
+ /// Note: This sets up new `URLSessions` so that removed network credentials are respected
135
+ /// right away.
136
+ func clearCredentialStores( ) async {
137
+ // Clear ArcGIS Credentials.
138
+ ArcGISEnvironment . authenticationManager. arcGISCredentialStore. removeAll ( )
139
+
140
+ // Clear network credentials.
141
+ await ArcGISEnvironment . authenticationManager. networkCredentialStore. removeAll ( )
142
+ }
143
+ }
0 commit comments