@@ -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 ///
0 commit comments