Skip to content

Commit

Permalink
coding (#61)
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana authored Mar 6, 2024
1 parent fa460bb commit 4a33e6c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Sources/NextcloudKit/NextcloudKit+Login.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,47 @@ extension NextcloudKit {
}
}

@objc public func deleteAppPassword(serverUrl: String,
username: String,
password: String,
userAgent: String? = nil,
queue: DispatchQueue = .main,
completion: @escaping (_ data: Data?, _ error: NKError) -> Void) {

let endpoint = "ocs/v2.php/core/apppassword"

guard let url = self.nkCommonInstance.createStandardUrl(serverUrl: serverUrl, endpoint: endpoint) else {
return queue.async { completion(nil, .urlError) }
}

var headers: HTTPHeaders = [.authorization(username: username, password: password)]
if let userAgent = userAgent {
headers.update(.userAgent(userAgent))
}
headers.update(name: "OCS-APIRequest", value: "true")

var urlRequest: URLRequest
do {
try urlRequest = URLRequest(url: url, method: HTTPMethod(rawValue: "DELETE"), headers: headers)
} catch {
return queue.async { completion(nil, NKError(error: error)) }
}

sessionManager.request(urlRequest).validate(statusCode: 200..<300).response(queue: self.nkCommonInstance.backgroundQueue) { response in
if self.nkCommonInstance.levelLog > 0 {
debugPrint(response)
}

switch response.result {
case .failure(let error):
let error = NKError(error: error, afResponse: response, responseData: response.data)
queue.async { completion(nil, error) }
case .success(let xmlData):
queue.async { completion(xmlData, .success) }
}
}
}

// MARK: - Login Flow V2

@objc public func getLoginFlowV2(serverUrl: String,
Expand Down

0 comments on commit 4a33e6c

Please sign in to comment.