@@ -8,6 +8,17 @@ import SwiftyJSON
88
99public extension NextcloudKit {
1010 // MARK: - App Password
11+
12+ // Retrieves an app password (token) for the given user credentials and server URL.
13+ //
14+ // Parameters:
15+ // - url: The base server URL (e.g., https://cloud.example.com).
16+ // - user: The username for authentication.
17+ // - password: The user's password.
18+ // - userAgent: Optional user-agent string to include in the request.
19+ // - options: Optional request configuration (headers, queue, etc.).
20+ // - taskHandler: Callback for observing the underlying URLSessionTask.
21+ // - completion: Returns the token string (if any), raw response data, and NKError result.
1122 func getAppPassword( url: String ,
1223 user: String ,
1324 password: String ,
@@ -47,6 +58,54 @@ public extension NextcloudKit {
4758 }
4859 }
4960
61+ /// Asynchronously fetches an app password for the provided user credentials.
62+ ///
63+ /// - Parameters:
64+ /// - url: The base URL of the Nextcloud server.
65+ /// - user: The user login name.
66+ /// - password: The user’s password.
67+ /// - userAgent: Optional custom user agent for the request.
68+ /// - options: Optional request configuration.
69+ /// - taskHandler: Callback to observe the task, if needed.
70+ /// - Returns: A tuple containing the token, response data, and error result.
71+ func getAppPasswordAsync( url: String ,
72+ user: String ,
73+ password: String ,
74+ userAgent: String ? = nil ,
75+ options: NKRequestOptions = NKRequestOptions ( ) ,
76+ taskHandler: @escaping ( _ task: URLSessionTask ) -> Void = { _ in }
77+ ) async -> (
78+ token: String ? ,
79+ responseData: AFDataResponse < Data > ? ,
80+ error: NKError
81+ ) {
82+ await withCheckedContinuation { continuation in
83+ getAppPassword ( url: url,
84+ user: user,
85+ password: password,
86+ userAgent: userAgent,
87+ options: options,
88+ taskHandler: taskHandler) { token, responseData, error in
89+ continuation. resume ( returning: (
90+ token: token,
91+ responseData: responseData,
92+ error: error
93+ ) )
94+ }
95+ }
96+ }
97+
98+ // Deletes the app password (token) for a specific account using basic authentication.
99+ //
100+ // Parameters:
101+ // - serverUrl: The full server URL (e.g., https://cloud.example.com).
102+ // - username: The username associated with the app password.
103+ // - password: The password or app password used for authentication.
104+ // - userAgent: Optional user-agent string for the request.
105+ // - account: The logical account identifier used in the app.
106+ // - options: Optional request configuration (headers, queues, etc.).
107+ // - taskHandler: Callback to observe the underlying URLSessionTask.
108+ // - completion: Returns the raw response and a possible NKError result.
50109 func deleteAppPassword( serverUrl: String ,
51110 username: String ,
52111 password: String ,
@@ -87,6 +146,44 @@ public extension NextcloudKit {
87146 }
88147 }
89148
149+ /// Asynchronously deletes the current app password/token from the server.
150+ ///
151+ /// - Parameters:
152+ /// - serverUrl: Full URL of the Nextcloud server.
153+ /// - username: The user identifier.
154+ /// - password: The password or token used for deletion authorization.
155+ /// - userAgent: Optional string to customize the User-Agent header.
156+ /// - account: Logical account identifier.
157+ /// - options: Configuration options for the request.
158+ /// - taskHandler: Optional callback for observing the URLSessionTask.
159+ /// - Returns: A tuple containing the response and a possible error.
160+ func deleteAppPasswordAsync( serverUrl: String ,
161+ username: String ,
162+ password: String ,
163+ userAgent: String ? = nil ,
164+ account: String ,
165+ options: NKRequestOptions = NKRequestOptions ( ) ,
166+ taskHandler: @escaping ( _ task: URLSessionTask ) -> Void = { _ in }
167+ ) async -> (
168+ responseData: AFDataResponse < Data > ? ,
169+ error: NKError
170+ ) {
171+ await withCheckedContinuation { continuation in
172+ deleteAppPassword ( serverUrl: serverUrl,
173+ username: username,
174+ password: password,
175+ userAgent: userAgent,
176+ account: account,
177+ options: options,
178+ taskHandler: taskHandler) { responseData, error in
179+ continuation. resume ( returning: (
180+ responseData: responseData,
181+ error: error
182+ ) )
183+ }
184+ }
185+ }
186+
90187 // MARK: - Login Flow V2
91188
92189 ///
@@ -155,6 +252,14 @@ public extension NextcloudKit {
155252 }
156253 }
157254
255+ // Polls the login flow V2 endpoint to retrieve login credentials (OAuth-style).
256+ //
257+ // Parameters:
258+ // - token: The login flow token to poll for.
259+ // - endpoint: The base URL endpoint (e.g., https://cloud.example.com).
260+ // - options: Optional request configuration (version, headers, queues, etc.).
261+ // - taskHandler: Callback to observe the underlying URLSessionTask.
262+ // - completion: Returns the discovered server URL, loginName, appPassword, the raw response data, and any NKError.
158263 func getLoginFlowV2Poll( token: String ,
159264 endpoint: String ,
160265 options: NKRequestOptions = NKRequestOptions ( ) ,
@@ -187,4 +292,39 @@ public extension NextcloudKit {
187292 }
188293 }
189294 }
295+
296+ /// Asynchronously polls the login flow V2 endpoint for login credentials.
297+ ///
298+ /// - Parameters:
299+ /// - token: The token used in the login flow process.
300+ /// - endpoint: Full base endpoint URL to call the polling API.
301+ /// - options: Request configuration such as version, headers, queue.
302+ /// - taskHandler: Optional callback to observe the underlying URLSessionTask.
303+ /// - Returns: A tuple with server URL, login name, app password, raw response, and NKError.
304+ func getLoginFlowV2PollAsync( token: String ,
305+ endpoint: String ,
306+ options: NKRequestOptions = NKRequestOptions ( ) ,
307+ taskHandler: @escaping ( _ task: URLSessionTask ) -> Void = { _ in }
308+ ) async -> (
309+ server: String ? ,
310+ loginName: String ? ,
311+ appPassword: String ? ,
312+ responseData: AFDataResponse < Data > ? ,
313+ error: NKError
314+ ) {
315+ await withCheckedContinuation { continuation in
316+ getLoginFlowV2Poll ( token: token,
317+ endpoint: endpoint,
318+ options: options,
319+ taskHandler: taskHandler) { server, loginName, appPassword, responseData, error in
320+ continuation. resume ( returning: (
321+ server: server,
322+ loginName: loginName,
323+ appPassword: appPassword,
324+ responseData: responseData,
325+ error: error
326+ ) )
327+ }
328+ }
329+ }
190330}
0 commit comments