SwiftAPI.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. * Copyright 2022 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. import XCTest
  18. @testable import FirebaseAuth
  19. import FirebaseCore
  20. #if !os(macOS)
  21. import UIKit
  22. #endif
  23. /// This file tests public methods and enums. Properties are not included.
  24. /// Each function maps to a public header file.
  25. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  26. class AuthAPI_hOnlyTests: XCTestCase {
  27. // Each function corresponds with a public header.
  28. func FIRActionCodeSettings_h() {
  29. let codeSettings = FirebaseAuth.ActionCodeSettings()
  30. codeSettings.iOSBundleID = "abc"
  31. codeSettings.setAndroidPackageName("name", installIfNotAvailable: true, minimumVersion: "10.0")
  32. }
  33. func FIRAuth_h() throws {
  34. let auth = FirebaseAuth.Auth.auth()
  35. let authApp = FirebaseAuth.Auth.auth(app: FirebaseApp.app()!)
  36. let user = auth.currentUser!
  37. auth.updateCurrentUser(user) { _ in
  38. }
  39. authApp.fetchSignInMethods(forEmail: "abc@abc.com") { string, error in
  40. }
  41. auth.signIn(withEmail: "abc@abc.com", password: "password") { result, error in
  42. }
  43. auth.signIn(withEmail: "abc@abc.com", link: "link") { result, error in
  44. }
  45. #if os(iOS)
  46. let provider = OAuthProvider(
  47. providerID: GoogleAuthProvider.id,
  48. auth: FirebaseAuth.Auth.auth()
  49. )
  50. auth.signIn(with: provider, uiDelegate: nil) { result, error in
  51. }
  52. provider.getCredentialWith(nil) { credential, error in
  53. auth.signIn(with: credential!) { result, error in
  54. }
  55. }
  56. auth.signIn(with: OAuthProvider(providerID: "abc"), uiDelegate: nil) { result, error in
  57. }
  58. #endif
  59. auth.signInAnonymously { result, error in
  60. }
  61. auth.signIn(withCustomToken: "abc") { result, error in
  62. }
  63. auth.createUser(withEmail: "email", password: "password") { result, error in
  64. }
  65. auth.confirmPasswordReset(withCode: "code", newPassword: "password") { error in
  66. }
  67. auth.checkActionCode("abc") { codeInfo, error in
  68. }
  69. auth.verifyPasswordResetCode("code") { email, error in
  70. }
  71. auth.applyActionCode("code") { error in
  72. }
  73. auth.sendPasswordReset(withEmail: "email") { error in
  74. }
  75. let actionCodeSettings = ActionCodeSettings()
  76. auth.sendPasswordReset(withEmail: "email", actionCodeSettings: actionCodeSettings) { error in
  77. }
  78. auth.sendSignInLink(toEmail: "email", actionCodeSettings: actionCodeSettings) { error in
  79. }
  80. try auth.signOut()
  81. _ = auth.isSignIn(withEmailLink: "link")
  82. let handle = auth.addStateDidChangeListener { auth, user in
  83. }
  84. auth.removeStateDidChangeListener(handle)
  85. _ = auth.addIDTokenDidChangeListener { auth, user in
  86. }
  87. auth.removeIDTokenDidChangeListener(handle)
  88. auth.useAppLanguage()
  89. auth.useEmulator(withHost: "myHost", port: 123)
  90. #if os(iOS)
  91. _ = auth.canHandle(URL(fileURLWithPath: "/my/path"))
  92. auth.setAPNSToken(Data(), type: AuthAPNSTokenType(rawValue: 2)!)
  93. _ = auth.canHandleNotification([:])
  94. #endif
  95. try auth.useUserAccessGroup("abc")
  96. let nilUser = try auth.getStoredUser(forAccessGroup: "def")
  97. // If nilUser is not optional, this will raise a compiler error.
  98. // This condition does not need to execute, and may not if prior
  99. // functions throw.
  100. if let _ = nilUser {
  101. XCTAssert(true)
  102. }
  103. }
  104. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  105. func FIRAuth_hAsync() async throws {
  106. let auth = FirebaseAuth.Auth.auth()
  107. let user = auth.currentUser!
  108. try await auth.updateCurrentUser(user)
  109. _ = try await auth.fetchSignInMethods(forEmail: "abc@abc.com")
  110. _ = try await auth.signIn(withEmail: "abc@abc.com", password: "password")
  111. _ = try await auth.signIn(withEmail: "abc@abc.com", link: "link")
  112. let provider = OAuthProvider(providerID: "abc")
  113. #if os(iOS)
  114. let credential = try await provider.credential(with: nil)
  115. _ = try await auth.signIn(with: OAuthProvider(providerID: "abc"), uiDelegate: nil)
  116. _ = try await auth.signIn(with: credential)
  117. #endif
  118. _ = try await auth.signInAnonymously()
  119. _ = try await auth.signIn(withCustomToken: "abc")
  120. _ = try await auth.createUser(withEmail: "email", password: "password")
  121. _ = try await auth.confirmPasswordReset(withCode: "code", newPassword: "password")
  122. _ = try await auth.checkActionCode("abc")
  123. _ = try await auth.verifyPasswordResetCode("code")
  124. _ = try await auth.applyActionCode("code")
  125. _ = try await auth.sendPasswordReset(withEmail: "email")
  126. let actionCodeSettings = ActionCodeSettings()
  127. _ = try await auth.sendPasswordReset(
  128. withEmail: "email",
  129. actionCodeSettings: actionCodeSettings
  130. )
  131. _ = try await auth.sendSignInLink(toEmail: "email", actionCodeSettings: actionCodeSettings)
  132. }
  133. #if !os(macOS)
  134. func FIRAuthAPNSTokenType_h() {
  135. _ = AuthAPNSTokenType.unknown
  136. _ = AuthAPNSTokenType.sandbox
  137. _ = AuthAPNSTokenType.prod
  138. }
  139. #endif
  140. func FIRAuthErrors_h() {
  141. _ = AuthErrorCode.invalidCustomToken
  142. _ = AuthErrorCode.customTokenMismatch
  143. _ = AuthErrorCode.invalidCredential
  144. _ = AuthErrorCode.userDisabled
  145. _ = AuthErrorCode.operationNotAllowed
  146. _ = AuthErrorCode.emailAlreadyInUse
  147. _ = AuthErrorCode.invalidEmail
  148. _ = AuthErrorCode.wrongPassword
  149. _ = AuthErrorCode.tooManyRequests
  150. _ = AuthErrorCode.userNotFound
  151. _ = AuthErrorCode.accountExistsWithDifferentCredential
  152. _ = AuthErrorCode.requiresRecentLogin
  153. _ = AuthErrorCode.providerAlreadyLinked
  154. _ = AuthErrorCode.noSuchProvider
  155. _ = AuthErrorCode.invalidUserToken
  156. _ = AuthErrorCode.networkError
  157. _ = AuthErrorCode.userTokenExpired
  158. _ = AuthErrorCode.invalidAPIKey
  159. _ = AuthErrorCode.userMismatch
  160. _ = AuthErrorCode.credentialAlreadyInUse
  161. _ = AuthErrorCode.weakPassword
  162. _ = AuthErrorCode.appNotAuthorized
  163. _ = AuthErrorCode.expiredActionCode
  164. _ = AuthErrorCode.invalidActionCode
  165. _ = AuthErrorCode.invalidMessagePayload
  166. _ = AuthErrorCode.invalidSender
  167. _ = AuthErrorCode.invalidRecipientEmail
  168. _ = AuthErrorCode.missingEmail
  169. _ = AuthErrorCode.missingIosBundleID
  170. _ = AuthErrorCode.missingAndroidPackageName
  171. _ = AuthErrorCode.unauthorizedDomain
  172. _ = AuthErrorCode.invalidContinueURI
  173. _ = AuthErrorCode.missingContinueURI
  174. _ = AuthErrorCode.missingPhoneNumber
  175. _ = AuthErrorCode.invalidPhoneNumber
  176. _ = AuthErrorCode.missingVerificationCode
  177. _ = AuthErrorCode.invalidVerificationCode
  178. _ = AuthErrorCode.missingVerificationID
  179. _ = AuthErrorCode.invalidVerificationID
  180. _ = AuthErrorCode.missingAppCredential
  181. _ = AuthErrorCode.invalidAppCredential
  182. _ = AuthErrorCode.sessionExpired
  183. _ = AuthErrorCode.quotaExceeded
  184. _ = AuthErrorCode.missingAppToken
  185. _ = AuthErrorCode.notificationNotForwarded
  186. _ = AuthErrorCode.appNotVerified
  187. _ = AuthErrorCode.captchaCheckFailed
  188. _ = AuthErrorCode.webContextAlreadyPresented
  189. _ = AuthErrorCode.webContextCancelled
  190. _ = AuthErrorCode.appVerificationUserInteractionFailure
  191. _ = AuthErrorCode.invalidClientID
  192. _ = AuthErrorCode.webNetworkRequestFailed
  193. _ = AuthErrorCode.webInternalError
  194. _ = AuthErrorCode.webSignInUserInteractionFailure
  195. _ = AuthErrorCode.localPlayerNotAuthenticated
  196. _ = AuthErrorCode.nullUser
  197. _ = AuthErrorCode.dynamicLinkNotActivated
  198. _ = AuthErrorCode.invalidProviderID
  199. _ = AuthErrorCode.tenantIDMismatch
  200. _ = AuthErrorCode.unsupportedTenantOperation
  201. _ = AuthErrorCode.invalidDynamicLinkDomain
  202. _ = AuthErrorCode.rejectedCredential
  203. _ = AuthErrorCode.gameKitNotLinked
  204. _ = AuthErrorCode.secondFactorRequired
  205. _ = AuthErrorCode.missingMultiFactorSession
  206. _ = AuthErrorCode.missingMultiFactorInfo
  207. _ = AuthErrorCode.invalidMultiFactorSession
  208. _ = AuthErrorCode.multiFactorInfoNotFound
  209. _ = AuthErrorCode.adminRestrictedOperation
  210. _ = AuthErrorCode.unverifiedEmail
  211. _ = AuthErrorCode.secondFactorAlreadyEnrolled
  212. _ = AuthErrorCode.maximumSecondFactorCountExceeded
  213. _ = AuthErrorCode.unsupportedFirstFactor
  214. _ = AuthErrorCode.emailChangeNeedsVerification
  215. _ = AuthErrorCode.missingOrInvalidNonce
  216. _ = AuthErrorCode.missingClientIdentifier
  217. _ = AuthErrorCode.keychainError
  218. _ = AuthErrorCode.internalError
  219. _ = AuthErrorCode.malformedJWT
  220. }
  221. #if !os(macOS) && !os(watchOS)
  222. func FIRAuthUIDelegate_h() {
  223. class AuthUIImpl: NSObject, AuthUIDelegate {
  224. func present(_ viewControllerToPresent: UIViewController, animated flag: Bool,
  225. completion: (() -> Void)? = nil) {}
  226. func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {}
  227. }
  228. let obj = AuthUIImpl()
  229. obj.present(UIViewController(), animated: true) {}
  230. obj.dismiss(animated: false) {}
  231. }
  232. #endif
  233. func FIREmailAuthProvider_h() {
  234. _ = EmailAuthProvider.credential(withEmail: "e@email.com", password: "password")
  235. _ = EmailAuthProvider.credential(withEmail: "e@email.com", link: "link")
  236. }
  237. func FIRFacebookAuthProvider_h() {
  238. _ = FacebookAuthProvider.credential(withAccessToken: "token")
  239. }
  240. #if !os(macOS) && !os(watchOS)
  241. func FIRFedederatedAuthProvider_h() {
  242. class FederatedAuthImplementation: NSObject, FederatedAuthProvider {
  243. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  244. func credential(with UIDelegate: AuthUIDelegate?) async throws -> FirebaseAuth
  245. .AuthCredential {
  246. return FacebookAuthProvider.credential(withAccessToken: "token")
  247. }
  248. func getCredentialWith(_ UIDelegate: AuthUIDelegate?,
  249. completion: ((AuthCredential?, Error?) -> Void)? = nil) {}
  250. }
  251. let obj = FederatedAuthImplementation()
  252. obj.getCredentialWith(nil) { _, _ in
  253. }
  254. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  255. func FIRFedederatedAuthProvider_hAsync() async throws {
  256. let obj = FederatedAuthImplementation()
  257. try await _ = obj.credential(with: nil)
  258. }
  259. }
  260. #endif
  261. #if !os(watchOS)
  262. func FIRGameCenterAuthProvider_h() {
  263. GameCenterAuthProvider.getCredential { _, _ in
  264. }
  265. }
  266. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  267. func FIRGameCenterAuthProvider_hAsync() async throws {
  268. _ = try await GameCenterAuthProvider.getCredential()
  269. }
  270. #endif
  271. func FIRGitHubAuthProvider_h() {
  272. _ = GitHubAuthProvider.credential(withToken: "token")
  273. }
  274. func FIRGoogleAuthProvider_h() {
  275. _ = GoogleAuthProvider.credential(withIDToken: "token", accessToken: "aToken")
  276. }
  277. #if os(iOS)
  278. func FIRMultiFactor_h() {
  279. let obj = MultiFactor()
  280. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  281. let credential = provider.credential(withVerificationID: "id",
  282. verificationCode: "code")
  283. obj.getSessionWithCompletion { _, _ in
  284. }
  285. obj
  286. .enroll(with: PhoneMultiFactorGenerator.assertion(with: credential),
  287. displayName: "name") { _ in
  288. }
  289. let mfi = MultiFactorInfo(proto: AuthProtoMFAEnrollment(dictionary: [:]))
  290. obj.unenroll(with: mfi) { _ in
  291. }
  292. obj.unenroll(withFactorUID: "uid") { _ in
  293. }
  294. }
  295. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  296. func FIRMultiFactor_hAsync() async throws {
  297. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  298. let credential = provider.credential(withVerificationID: "id",
  299. verificationCode: "code")
  300. let obj = MultiFactor()
  301. _ = try await obj.session()
  302. try await obj.enroll(
  303. with: PhoneMultiFactorGenerator.assertion(with: credential),
  304. displayName: "name"
  305. )
  306. let mfi = MultiFactorInfo(proto: AuthProtoMFAEnrollment(dictionary: [:]))
  307. try await obj.unenroll(with: mfi)
  308. try await obj.unenroll(withFactorUID: "uid")
  309. }
  310. func FIRMultiFactorResolver_h() {
  311. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  312. let credential = provider.credential(withVerificationID: "id",
  313. verificationCode: "code")
  314. let obj = MultiFactorResolver(with: "", hints: [], auth: FirebaseAuth.Auth.auth())
  315. obj.resolveSignIn(with: PhoneMultiFactorGenerator.assertion(with: credential)) { _, _ in
  316. }
  317. }
  318. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  319. func FIRMultiFactorResolver_hAsync() async throws {
  320. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  321. let credential = provider.credential(withVerificationID: "id",
  322. verificationCode: "code")
  323. let obj = MultiFactorResolver(with: "", hints: [], auth: FirebaseAuth.Auth.auth())
  324. _ = try await obj.resolveSignIn(with: PhoneMultiFactorGenerator.assertion(with: credential))
  325. }
  326. #endif
  327. func FIROAuthProvider_h() {
  328. let provider = OAuthProvider(providerID: "id", auth: FirebaseAuth.Auth.auth())
  329. _ = provider.providerID
  330. #if os(iOS)
  331. _ = OAuthProvider.credential(withProviderID: "id", idToken: "idToden", accessToken: "token")
  332. _ = OAuthProvider.credential(withProviderID: "id", accessToken: "token")
  333. _ = OAuthProvider.credential(withProviderID: "id", idToken: "idToken", rawNonce: "nonce",
  334. accessToken: "token")
  335. _ = OAuthProvider.credential(withProviderID: "id", idToken: "idToken", rawNonce: "nonce")
  336. provider.getCredentialWith(provider as? AuthUIDelegate) { credential, error in
  337. }
  338. #endif
  339. }
  340. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  341. func FIROAuthProvider_h() async throws {
  342. let provider = OAuthProvider(providerID: GoogleAuthProvider.id, auth: FirebaseAuth.Auth.auth())
  343. #if os(iOS)
  344. provider.getCredentialWith(provider as? AuthUIDelegate) { credential, error in
  345. }
  346. _ = try await provider.credential(with: provider as? AuthUIDelegate)
  347. #endif
  348. }
  349. #if os(iOS)
  350. func FIRPhoneAuthProvider_h() {
  351. _ = PhoneAuthProvider.provider()
  352. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  353. provider.verifyPhoneNumber("123", uiDelegate: nil) { _, _ in
  354. }
  355. provider.verifyPhoneNumber("123", uiDelegate: nil, multiFactorSession: nil) { _, _ in
  356. }
  357. provider.verifyPhoneNumber(
  358. with: MultiFactorInfo(
  359. proto: AuthProtoMFAEnrollment(dictionary: [:])
  360. ) as! PhoneMultiFactorInfo,
  361. uiDelegate: nil,
  362. multiFactorSession: nil
  363. ) { _, _ in
  364. }
  365. provider.verifyPhoneNumber("123", uiDelegate: nil, multiFactorSession: nil) { _, _ in
  366. }
  367. _ = provider.credential(withVerificationID: "id", verificationCode: "code")
  368. }
  369. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  370. func FIRPhoneAuthProvider_hAsync() async throws {
  371. _ = PhoneAuthProvider.provider()
  372. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  373. _ = try await provider.verifyPhoneNumber("123", uiDelegate: nil)
  374. _ = try await provider.verifyPhoneNumber("123", uiDelegate: nil, multiFactorSession: nil)
  375. let mfi =
  376. MultiFactorInfo(proto: AuthProtoMFAEnrollment(dictionary: [:])) as! PhoneMultiFactorInfo
  377. _ = try await provider.verifyPhoneNumber(with: mfi, uiDelegate: nil,
  378. multiFactorSession: nil)
  379. _ = try await provider.verifyPhoneNumber("123", uiDelegate: nil, multiFactorSession: nil)
  380. }
  381. func FIRPhoneMultiFactorGenerator_h() {
  382. let credential = PhoneAuthProvider.provider().credential(withVerificationID: "id",
  383. verificationCode: "code")
  384. _ = PhoneMultiFactorGenerator.assertion(with: credential)
  385. }
  386. #endif
  387. // TODO: reenable with TOTP
  388. // func FIRTOTPSecret_h() {
  389. // let obj = TOTPSecret()
  390. // obj.sharedSecretKey()
  391. // obj.generateQRCodeURL(withAccountName: "name", issuer: "issuer")
  392. // obj.openInOTPApp(withQRCodeURL: "url")
  393. // }
  394. //
  395. // func FIRTOTPMultiFactorGenerator_h() {
  396. // TOTPMultiFactorGenerator.generateSecret(with: MultiFactorSession()) { _, _ in
  397. // }
  398. // TOTPMultiFactorGenerator.assertionForEnrollment(with: TOTPSecret(), oneTimePassword: "code")
  399. // TOTPMultiFactorGenerator.assertionForSignIn(withEnrollmentID: "id",
  400. // oneTimePassword: "code")
  401. // }
  402. //
  403. // #if compiler(>=5.5.2) && canImport(_Concurrency)
  404. // @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  405. // func FIRTOTPMultiFactorGenerator_hAsync() async throws {
  406. // try await TOTPMultiFactorGenerator.generateSecret(with: MultiFactorSession())
  407. // }
  408. // #endif
  409. func FIRTwitterAuthProvider_h() {
  410. _ = TwitterAuthProvider.credential(withToken: "token", secret: "secret")
  411. }
  412. func FIRUser_h() {
  413. let auth = FirebaseAuth.Auth.auth()
  414. let user = auth.currentUser!
  415. let credential = GoogleAuthProvider.credential(withIDToken: "token", accessToken: "aToken")
  416. user.updateEmail(to: "email") { _ in
  417. }
  418. user.updatePassword(to: "password") { _ in
  419. }
  420. let changeRequest = user.createProfileChangeRequest()
  421. user.reload { _ in
  422. }
  423. user.reauthenticate(with: credential) { _, _ in
  424. }
  425. #if os(iOS)
  426. let phoneCredential = PhoneAuthProvider.provider().credential(withVerificationID: "id",
  427. verificationCode: "code")
  428. user.updatePhoneNumber(phoneCredential) { _ in
  429. }
  430. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  431. user.reauthenticate(with: provider as! FederatedAuthProvider, uiDelegate: nil)
  432. user.link(with: provider as! FederatedAuthProvider, uiDelegate: nil) { _, _ in
  433. }
  434. #endif
  435. user.getIDTokenResult { _, _ in
  436. }
  437. user.getIDTokenResult(forcingRefresh: true) { _, _ in
  438. }
  439. user.getIDToken { _, _ in
  440. }
  441. user.getIDTokenForcingRefresh(true) { _, _ in
  442. }
  443. user.link(with: credential) { _, _ in
  444. }
  445. user.unlink(fromProvider: "abc") { _, _ in
  446. }
  447. user.sendEmailVerification { _ in
  448. }
  449. user.sendEmailVerification(with: ActionCodeSettings()) { _ in
  450. }
  451. user.delete { _ in
  452. }
  453. user.sendEmailVerification(beforeUpdatingEmail: "email") { _ in
  454. }
  455. user.sendEmailVerification(
  456. beforeUpdatingEmail: "email",
  457. actionCodeSettings: ActionCodeSettings()
  458. ) { _ in
  459. }
  460. changeRequest.commitChanges { _ in
  461. }
  462. }
  463. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  464. func FIRUser_hAsync() async throws {
  465. let auth = FirebaseAuth.Auth.auth()
  466. let user = auth.currentUser!
  467. let credential = GoogleAuthProvider.credential(withIDToken: "token", accessToken: "aToken")
  468. try await user.updateEmail(to: "email")
  469. try await user.updatePassword(to: "password")
  470. let changeRequest = user.createProfileChangeRequest()
  471. try await user.reload()
  472. try await user.reauthenticate(with: credential)
  473. #if os(iOS)
  474. let phoneCredential = PhoneAuthProvider.provider().credential(withVerificationID: "id",
  475. verificationCode: "code")
  476. try await user.updatePhoneNumber(phoneCredential)
  477. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  478. try await user.reauthenticate(with: provider as! FederatedAuthProvider, uiDelegate: nil)
  479. try await user.link(with: provider as! FederatedAuthProvider, uiDelegate: nil)
  480. #endif
  481. _ = try await user.getIDTokenResult()
  482. _ = try await user.getIDTokenResult(forcingRefresh: true)
  483. _ = try await user.getIDToken()
  484. _ = try await user.getIDToken(forcingRefresh: false)
  485. _ = try await user.link(with: credential)
  486. _ = try await user.unlink(fromProvider: "abc")
  487. try await user.sendEmailVerification()
  488. try await user.sendEmailVerification(with: ActionCodeSettings())
  489. try await user.delete()
  490. try await user.sendEmailVerification(beforeUpdatingEmail: "email")
  491. try await user.sendEmailVerification(
  492. beforeUpdatingEmail: "email",
  493. actionCodeSettings: ActionCodeSettings()
  494. )
  495. try await changeRequest.commitChanges()
  496. }
  497. }