Skip to content

Commit 95517a3

Browse files
committed
Release candidate for 1.5.x
1 parent adbb8c1 commit 95517a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+182
-181
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:
3131

3232
```swift
3333
dependencies: [
34-
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "5.0.0-rc.4"),
34+
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "5.0.0-rc.5"),
3535
],
3636
```
3737

@@ -125,9 +125,10 @@ let account = Account(client)
125125

126126
do {
127127
let user = try await account.create(
128-
userId: ID.unique(),
129-
email: "[email protected]",
130-
password: "password"
128+
userId: ID.unique(),
129+
130+
password: "password",
131+
name: "Walter O'Brien"
131132
)
132133
print(String(describing: user.toMap()))
133134
} catch {
@@ -150,9 +151,10 @@ func main() {
150151

151152
do {
152153
let user = try await account.create(
153-
userId: ID.unique(),
154-
email: "[email protected]",
155-
password: "password"
154+
userId: ID.unique(),
155+
156+
password: "password",
157+
name: "Walter O'Brien"
156158
)
157159
print(String(describing: account.toMap()))
158160
} catch {

Sources/Appwrite/Client.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import Foundation
66
import AsyncHTTPClient
77
@_exported import AppwriteModels
88

9-
typealias CookieListener = (_ existing: [String], _ new: [String]) -> Void
10-
119
let DASHDASH = "--"
1210
let CRLF = "\r\n"
1311

@@ -25,7 +23,7 @@ open class Client {
2523
"x-sdk-name": "Apple",
2624
"x-sdk-platform": "client",
2725
"x-sdk-language": "apple",
28-
"x-sdk-version": "5.0.0-rc.4",
26+
"x-sdk-version": "5.0.0-rc.5",
2927
"x-appwrite-response-format": "1.5.0"
3028
]
3129

@@ -35,7 +33,6 @@ open class Client {
3533

3634
internal var http: HTTPClient
3735

38-
internal static var cookieListener: CookieListener? = nil
3936

4037
private static let boundaryChars = "abcdefghijklmnopqrstuvwxyz1234567890"
4138

@@ -323,8 +320,6 @@ open class Client {
323320
let existing = UserDefaults.standard.stringArray(forKey: domain)
324321
let new = response.headers["Set-Cookie"]
325322

326-
Client.cookieListener?(existing ?? [], new)
327-
328323
UserDefaults.standard.set(new, forKey: domain)
329324
}
330325
switch T.self {

Sources/Appwrite/OAuth/WebAuthComponent.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ public class WebAuthComponent {
9595
let existing = UserDefaults.standard.stringArray(forKey: domain)
9696
let new = [cookie]
9797

98-
Client.cookieListener?(existing ?? [], new)
99-
10098
UserDefaults.standard.set(new, forKey: domain)
10199

102100
WebAuthComponent.onCallback(

Sources/Appwrite/OS.swift

Lines changed: 0 additions & 60 deletions
This file was deleted.

Sources/Appwrite/Services/Account.swift

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ open class Account: Service {
404404
/// @throws Exception
405405
/// @return array
406406
///
407-
open func create2FAChallenge(
407+
open func createChallenge(
408408
factor: AppwriteEnums.AuthenticationFactor
409409
) async throws -> AppwriteModels.MfaChallenge {
410410
let apiPath: String = "/account/mfa/challenge"
@@ -1220,7 +1220,6 @@ open class Account: Service {
12201220
/// @param AppwriteEnums.OAuthProvider provider
12211221
/// @param String success
12221222
/// @param String failure
1223-
/// @param Bool token
12241223
/// @param [String] scopes
12251224
/// @throws Exception
12261225
/// @return array
@@ -1230,7 +1229,6 @@ open class Account: Service {
12301229
provider: AppwriteEnums.OAuthProvider,
12311230
success: String? = nil,
12321231
failure: String? = nil,
1233-
token: Bool? = nil,
12341232
scopes: [String]? = nil
12351233
) async throws -> Bool {
12361234
let apiPath: String = "/account/sessions/oauth2/{provider}"
@@ -1239,7 +1237,6 @@ open class Account: Service {
12391237
let apiParams: [String: Any?] = [
12401238
"success": success,
12411239
"failure": failure,
1242-
"token": token,
12431240
"scopes": scopes,
12441241
"project": client.config["project"]
12451242
]
@@ -1255,7 +1252,6 @@ open class Account: Service {
12551252
}
12561253

12571254
return true
1258-
12591255
}
12601256

12611257
///
@@ -1661,6 +1657,61 @@ open class Account: Service {
16611657
)
16621658
}
16631659

1660+
///
1661+
/// Create OAuth2 token
1662+
///
1663+
/// Allow the user to login to their account using the OAuth2 provider of their
1664+
/// choice. Each OAuth2 provider should be enabled from the Appwrite console
1665+
/// first. Use the success and failure arguments to provide a redirect URL's
1666+
/// back to your app when login is completed.
1667+
///
1668+
/// If authentication succeeds, `userId` and `secret` of a token will be
1669+
/// appended to the success URL as query parameters. These can be used to
1670+
/// create a new session using the [Create
1671+
/// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1672+
/// endpoint.
1673+
///
1674+
/// A user is limited to 10 active sessions at a time by default. [Learn more
1675+
/// about session
1676+
/// limits](https://appwrite.io/docs/authentication-security#limits).
1677+
///
1678+
/// @param AppwriteEnums.OAuthProvider provider
1679+
/// @param String success
1680+
/// @param String failure
1681+
/// @param [String] scopes
1682+
/// @throws Exception
1683+
/// @return array
1684+
///
1685+
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
1686+
open func createOAuth2Token(
1687+
provider: AppwriteEnums.OAuthProvider,
1688+
success: String? = nil,
1689+
failure: String? = nil,
1690+
scopes: [String]? = nil
1691+
) async throws -> Bool {
1692+
let apiPath: String = "/account/tokens/oauth2/{provider}"
1693+
.replacingOccurrences(of: "{provider}", with: provider.rawValue)
1694+
1695+
let apiParams: [String: Any?] = [
1696+
"success": success,
1697+
"failure": failure,
1698+
"scopes": scopes,
1699+
"project": client.config["project"]
1700+
]
1701+
1702+
let query = "?\(client.parametersToQueryString(params: apiParams))"
1703+
let url = URL(string: client.endPoint + apiPath + query)!
1704+
let callbackScheme = "appwrite-callback-\(client.config["project"] ?? "")"
1705+
1706+
_ = try await withCheckedThrowingContinuation { continuation in
1707+
WebAuthComponent.authenticate(url: url, callbackScheme: callbackScheme) { result in
1708+
continuation.resume(with: result)
1709+
}
1710+
}
1711+
1712+
return true
1713+
}
1714+
16641715
///
16651716
/// Create phone token
16661717
///

docs/examples/account/create2f-a-challenge.md renamed to docs/examples/account/create-challenge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let client = Client()
77

88
let account = Account(client)
99

10-
let mfaChallenge = try await account.create2FAChallenge(
10+
let mfaChallenge = try await account.createChallenge(
1111
factor: .totp
1212
)
1313

docs/examples/account/create-email-token.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let client = Client()
77
let account = Account(client)
88

99
let token = try await account.createEmailToken(
10-
userId: "[USER_ID]",
10+
userId: "<USER_ID>",
1111
1212
phrase: false // optional
1313
)

docs/examples/account/create-magic-u-r-l-token.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let client = Client()
77
let account = Account(client)
88

99
let token = try await account.createMagicURLToken(
10-
userId: "[USER_ID]",
10+
userId: "<USER_ID>",
1111
1212
url: "https://example.com", // optional
1313
phrase: false // optional

docs/examples/account/create-o-auth2session.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ let success = try await account.createOAuth2Session(
1111
provider: .amazon,
1212
success: "https://example.com", // optional
1313
failure: "https://example.com", // optional
14-
token: false, // optional
1514
scopes: [] // optional
1615
)
1716

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Appwrite
2+
import AppwriteEnums
3+
4+
let client = Client()
5+
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
6+
.setProject("5df5acd0d48c2") // Your project ID
7+
8+
let account = Account(client)
9+
10+
let success = try await account.createOAuth2Token(
11+
provider: .amazon,
12+
success: "https://example.com", // optional
13+
failure: "https://example.com", // optional
14+
scopes: [] // optional
15+
)
16+

0 commit comments

Comments
 (0)