Skip to content

Fix oauth XPC interrupt #43

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:

```swift
dependencies: [
.package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "4.0.0"),
.package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "4.0.1"),
],
```

7 changes: 5 additions & 2 deletions Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ open class Client {
"x-sdk-name": "Apple",
"x-sdk-platform": "client",
"x-sdk-language": "apple",
"x-sdk-version": "4.0.0",
"x-sdk-version": "4.0.1",
"X-Appwrite-Response-Format": "1.4.0"
]

@@ -321,18 +321,21 @@ open class Client {
default:
var message = ""
var data = try await response.body.collect(upTo: Int.max)
var type = ""

do {
let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any]

message = dict?["message"] as? String ?? response.status.reasonPhrase
type = dict?["type"] as? String ?? ""
} catch {
message = data.readString(length: data.readableBytes)!
}

throw AppwriteError(
message: message,
code: Int(response.status.code)
code: Int(response.status.code),
type: type
)
}
}
11 changes: 5 additions & 6 deletions Sources/Appwrite/Services/Account.swift
Original file line number Diff line number Diff line change
@@ -1003,7 +1003,7 @@ open class Account: Service {
success: String? = nil,
failure: String? = nil,
scopes: [String]? = nil
) throws -> Bool {
) async throws -> Bool {
let apiPath: String = "/account/sessions/oauth2/{provider}"
.replacingOccurrences(of: "{provider}", with: provider)

@@ -1017,13 +1017,12 @@ open class Account: Service {
let query = "?\(client.parametersToQueryString(params: apiParams))"
let url = URL(string: client.endPoint + apiPath + query)!
let callbackScheme = "appwrite-callback-\(client.config["project"] ?? "")"
let group = DispatchGroup()

group.enter()
WebAuthComponent.authenticate(url: url, callbackScheme: callbackScheme) { result in
group.leave()
try await withCheckedThrowingContinuation { continuation in
WebAuthComponent.authenticate(url: url, callbackScheme: callbackScheme) { result in
continuation.resume(with: result)
}
}
group.wait()

return true