SwiftAPI.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. import FirebaseAuth
  19. import FirebaseCore
  20. #if !os(macOS)
  21. import UIKit
  22. #endif
  23. /// This file tests public methods and enums. Each function maps to a public header file.
  24. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  25. class AuthAPI_hOnlyTests: XCTestCase {
  26. // Each function corresponds with a public header.
  27. func FIRActionCodeSettings_h() {
  28. let codeSettings = FirebaseAuth.ActionCodeSettings()
  29. codeSettings.setIOSBundleID("abc")
  30. codeSettings.setAndroidPackageName("name", installIfNotAvailable: true, minimumVersion: "10.0")
  31. let _: Bool = codeSettings.handleCodeInApp
  32. let _: Bool = codeSettings.androidInstallIfNotAvailable
  33. if let _: URL = codeSettings.url,
  34. let _: String = codeSettings.iOSBundleID,
  35. let _: String = codeSettings.androidPackageName,
  36. let _: String = codeSettings.androidMinimumVersion,
  37. let _: String = codeSettings.dynamicLinkDomain {}
  38. }
  39. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  40. func FIRAuthAdditionalUserInfo_h(credential: AuthCredential) async throws {
  41. let auth = FirebaseAuth.Auth.auth()
  42. let user = auth.currentUser!
  43. let authDataResult = try await user.reauthenticate(with: credential)
  44. let additionalUserInfo = authDataResult.additionalUserInfo!
  45. let _: String = additionalUserInfo.providerID
  46. let _: Bool = additionalUserInfo.isNewUser
  47. if let _: [String: Any] = additionalUserInfo.profile,
  48. let _: String = additionalUserInfo.username {}
  49. }
  50. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  51. func ActionCodeOperationTests() async throws {
  52. let auth = FirebaseAuth.Auth.auth()
  53. let info = try await auth.checkActionCode("code")
  54. let _: ActionCodeOperation = info.operation
  55. if let _: String = info.email,
  56. let _: String = info.previousEmail {}
  57. }
  58. func ActionCodeURL() {
  59. if let url = FirebaseAuth.ActionCodeURL(link: "string") {
  60. let _: ActionCodeOperation = url.operation
  61. if let _: String = url.apiKey,
  62. let _: String = url.code,
  63. let _: URL = url.continueURL,
  64. let _: String = url.languageCode {}
  65. }
  66. }
  67. func authProperties(auth: Auth) {
  68. let _: Bool = auth.shareAuthStateAcrossDevices
  69. if let _: FirebaseApp = auth.app,
  70. let _: User = auth.currentUser,
  71. let _: String = auth.languageCode,
  72. let _: AuthSettings = auth.settings,
  73. let _: String = auth.userAccessGroup,
  74. let _: String = auth.tenantID,
  75. let _: String = auth.customAuthDomain
  76. {}
  77. #if os(iOS)
  78. if let _: Data = auth.apnsToken {}
  79. auth.apnsToken = Data()
  80. #endif
  81. }
  82. func FIRAuth_h(credential: AuthCredential) throws {
  83. let auth = FirebaseAuth.Auth.auth()
  84. let user = auth.currentUser!
  85. auth.updateCurrentUser(user) { _ in
  86. }
  87. auth.signIn(withEmail: "abc@abc.com", password: "password") { result, error in
  88. }
  89. auth.signIn(withEmail: "abc@abc.com", link: "link") { result, error in
  90. }
  91. #if os(iOS)
  92. let provider = OAuthProvider(providerID: "abc")
  93. provider.getCredentialWith(nil) { credential, error in
  94. auth.signIn(with: credential!) { result, error in
  95. }
  96. }
  97. auth.signIn(with: OAuthProvider(providerID: "abc"), uiDelegate: nil) { result, error in
  98. }
  99. #endif
  100. auth.signInAnonymously { result, error in
  101. }
  102. auth.signIn(withCustomToken: "abc") { result, error in
  103. }
  104. auth.createUser(withEmail: "email", password: "password") { result, error in
  105. }
  106. auth.confirmPasswordReset(withCode: "code", newPassword: "password") { error in
  107. }
  108. auth.checkActionCode("abc") { codeInfo, error in
  109. }
  110. auth.verifyPasswordResetCode("code") { email, error in
  111. }
  112. auth.applyActionCode("code") { error in
  113. }
  114. auth.sendPasswordReset(withEmail: "email") { error in
  115. }
  116. let actionCodeSettings = ActionCodeSettings()
  117. auth.sendPasswordReset(withEmail: "email", actionCodeSettings: actionCodeSettings) { error in
  118. }
  119. auth.sendSignInLink(toEmail: "email", actionCodeSettings: actionCodeSettings) { error in
  120. }
  121. try auth.signOut()
  122. _ = auth.isSignIn(withEmailLink: "link")
  123. let handle = auth.addStateDidChangeListener { auth, user in
  124. }
  125. auth.removeStateDidChangeListener(handle)
  126. _ = auth.addIDTokenDidChangeListener { auth, user in
  127. }
  128. auth.removeIDTokenDidChangeListener(handle)
  129. auth.useAppLanguage()
  130. auth.useEmulator(withHost: "myHost", port: 123)
  131. #if os(iOS)
  132. _ = auth.canHandle(URL(fileURLWithPath: "/my/path"))
  133. auth.setAPNSToken(Data(), type: AuthAPNSTokenType.prod)
  134. _ = auth.canHandleNotification([:])
  135. #if !targetEnvironment(macCatalyst)
  136. auth.initializeRecaptchaConfig { _ in
  137. }
  138. #endif
  139. #endif
  140. auth.revokeToken(withAuthorizationCode: "A")
  141. try auth.useUserAccessGroup("abc")
  142. let nilUser = try auth.getStoredUser(forAccessGroup: "def")
  143. // If nilUser is not optional, this will raise a compiler error.
  144. // This condition does not need to execute, and may not if prior
  145. // functions throw.
  146. if let _ = nilUser {
  147. XCTAssert(true)
  148. }
  149. }
  150. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  151. func FIRAuth_hAsync(credential: AuthCredential) async throws {
  152. let auth = FirebaseAuth.Auth.auth()
  153. let user = auth.currentUser!
  154. try await auth.updateCurrentUser(user)
  155. _ = try await auth.signIn(withEmail: "abc@abc.com", password: "password")
  156. _ = try await auth.signIn(withEmail: "abc@abc.com", link: "link")
  157. _ = try await auth.signIn(with: credential)
  158. #if os(iOS) && !targetEnvironment(macCatalyst)
  159. try await auth.initializeRecaptchaConfig()
  160. #endif
  161. _ = try await auth.signIn(with: OAuthProvider(providerID: "abc"), uiDelegate: nil)
  162. _ = try await auth.signInAnonymously()
  163. _ = try await auth.signIn(withCustomToken: "abc")
  164. _ = try await auth.createUser(withEmail: "email", password: "password")
  165. _ = try await auth.confirmPasswordReset(withCode: "code", newPassword: "password")
  166. _ = try await auth.checkActionCode("abc")
  167. _ = try await auth.verifyPasswordResetCode("code")
  168. _ = try await auth.applyActionCode("code")
  169. _ = try await auth.sendPasswordReset(withEmail: "email")
  170. let actionCodeSettings = ActionCodeSettings()
  171. _ = try await auth.sendPasswordReset(
  172. withEmail: "email",
  173. actionCodeSettings: actionCodeSettings
  174. )
  175. _ = try await auth.sendSignInLink(toEmail: "email", actionCodeSettings: actionCodeSettings)
  176. try await auth.revokeToken(withAuthorizationCode: "string")
  177. }
  178. #if !os(macOS)
  179. func FIRAuthAPNSTokenType_h() {
  180. _ = AuthAPNSTokenType.unknown
  181. _ = AuthAPNSTokenType.sandbox
  182. _ = AuthAPNSTokenType.prod
  183. }
  184. #endif
  185. func authCredential(credential: AuthCredential) {
  186. let _: String = credential.provider
  187. }
  188. func authDataResult(result: AuthDataResult) {
  189. let _: User = result.user
  190. if let _: AdditionalUserInfo = result.additionalUserInfo,
  191. let _: AuthCredential = result.credential {}
  192. }
  193. func FIRAuthErrors_h() {
  194. _ = AuthErrorCode.invalidCustomToken
  195. _ = AuthErrorCode.customTokenMismatch
  196. _ = AuthErrorCode.invalidCredential
  197. _ = AuthErrorCode.userDisabled
  198. _ = AuthErrorCode.operationNotAllowed
  199. _ = AuthErrorCode.emailAlreadyInUse
  200. _ = AuthErrorCode.invalidEmail
  201. _ = AuthErrorCode.wrongPassword
  202. _ = AuthErrorCode.tooManyRequests
  203. _ = AuthErrorCode.userNotFound
  204. _ = AuthErrorCode.accountExistsWithDifferentCredential
  205. _ = AuthErrorCode.requiresRecentLogin
  206. _ = AuthErrorCode.providerAlreadyLinked
  207. _ = AuthErrorCode.noSuchProvider
  208. _ = AuthErrorCode.invalidUserToken
  209. _ = AuthErrorCode.networkError
  210. _ = AuthErrorCode.userTokenExpired
  211. _ = AuthErrorCode.invalidAPIKey
  212. _ = AuthErrorCode.userMismatch
  213. _ = AuthErrorCode.credentialAlreadyInUse
  214. _ = AuthErrorCode.weakPassword
  215. _ = AuthErrorCode.appNotAuthorized
  216. _ = AuthErrorCode.expiredActionCode
  217. _ = AuthErrorCode.invalidActionCode
  218. _ = AuthErrorCode.invalidMessagePayload
  219. _ = AuthErrorCode.invalidSender
  220. _ = AuthErrorCode.invalidRecipientEmail
  221. _ = AuthErrorCode.missingEmail
  222. _ = AuthErrorCode.missingIosBundleID
  223. _ = AuthErrorCode.missingAndroidPackageName
  224. _ = AuthErrorCode.unauthorizedDomain
  225. _ = AuthErrorCode.invalidContinueURI
  226. _ = AuthErrorCode.missingContinueURI
  227. _ = AuthErrorCode.missingPhoneNumber
  228. _ = AuthErrorCode.invalidPhoneNumber
  229. _ = AuthErrorCode.missingVerificationCode
  230. _ = AuthErrorCode.invalidVerificationCode
  231. _ = AuthErrorCode.missingVerificationID
  232. _ = AuthErrorCode.invalidVerificationID
  233. _ = AuthErrorCode.missingAppCredential
  234. _ = AuthErrorCode.invalidAppCredential
  235. _ = AuthErrorCode.sessionExpired
  236. _ = AuthErrorCode.quotaExceeded
  237. _ = AuthErrorCode.missingAppToken
  238. _ = AuthErrorCode.notificationNotForwarded
  239. _ = AuthErrorCode.appNotVerified
  240. _ = AuthErrorCode.captchaCheckFailed
  241. _ = AuthErrorCode.webContextAlreadyPresented
  242. _ = AuthErrorCode.webContextCancelled
  243. _ = AuthErrorCode.appVerificationUserInteractionFailure
  244. _ = AuthErrorCode.invalidClientID
  245. _ = AuthErrorCode.webNetworkRequestFailed
  246. _ = AuthErrorCode.webInternalError
  247. _ = AuthErrorCode.webSignInUserInteractionFailure
  248. _ = AuthErrorCode.localPlayerNotAuthenticated
  249. _ = AuthErrorCode.nullUser
  250. _ = AuthErrorCode.dynamicLinkNotActivated
  251. _ = AuthErrorCode.invalidProviderID
  252. _ = AuthErrorCode.tenantIDMismatch
  253. _ = AuthErrorCode.unsupportedTenantOperation
  254. _ = AuthErrorCode.invalidDynamicLinkDomain
  255. _ = AuthErrorCode.rejectedCredential
  256. _ = AuthErrorCode.gameKitNotLinked
  257. _ = AuthErrorCode.secondFactorRequired
  258. _ = AuthErrorCode.missingMultiFactorSession
  259. _ = AuthErrorCode.missingMultiFactorInfo
  260. _ = AuthErrorCode.invalidMultiFactorSession
  261. _ = AuthErrorCode.multiFactorInfoNotFound
  262. _ = AuthErrorCode.adminRestrictedOperation
  263. _ = AuthErrorCode.unverifiedEmail
  264. _ = AuthErrorCode.secondFactorAlreadyEnrolled
  265. _ = AuthErrorCode.maximumSecondFactorCountExceeded
  266. _ = AuthErrorCode.unsupportedFirstFactor
  267. _ = AuthErrorCode.emailChangeNeedsVerification
  268. _ = AuthErrorCode.missingOrInvalidNonce
  269. _ = AuthErrorCode.missingClientIdentifier
  270. _ = AuthErrorCode.recaptchaNotEnabled
  271. _ = AuthErrorCode.missingRecaptchaToken
  272. _ = AuthErrorCode.invalidRecaptchaToken
  273. _ = AuthErrorCode.invalidRecaptchaAction
  274. _ = AuthErrorCode.missingClientType
  275. _ = AuthErrorCode.missingRecaptchaVersion
  276. _ = AuthErrorCode.invalidRecaptchaVersion
  277. _ = AuthErrorCode.invalidReqType
  278. _ = AuthErrorCode.keychainError
  279. _ = AuthErrorCode.internalError
  280. _ = AuthErrorCode.malformedJWT
  281. }
  282. func authSettings(settings: AuthSettings) {
  283. let _: Bool = settings.isAppVerificationDisabledForTesting
  284. settings.isAppVerificationDisabledForTesting = true
  285. }
  286. func authTokenResult(result: AuthTokenResult) {
  287. let _: String = result.token
  288. let _: Date = result.expirationDate
  289. let _: Date = result.authDate
  290. let _: Date = result.issuedAtDate
  291. let _: String = result.signInProvider
  292. let _: String = result.signInSecondFactor
  293. let _: [String: Any] = result.claims
  294. }
  295. #if !os(macOS) && !os(watchOS)
  296. func FIRAuthUIDelegate_h() {
  297. class AuthUIImpl: NSObject, AuthUIDelegate {
  298. func present(_ viewControllerToPresent: UIViewController, animated flag: Bool,
  299. completion: (() -> Void)? = nil) {}
  300. func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {}
  301. }
  302. let obj = AuthUIImpl()
  303. obj.present(UIViewController(), animated: true) {}
  304. obj.dismiss(animated: false) {}
  305. }
  306. #endif
  307. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  308. func FIRAuthUIDelegate_hAsync() async {
  309. class AuthUIImpl: NSObject, AuthUIDelegate {
  310. func present(_ viewControllerToPresent: UIViewController, animated flag: Bool) async {}
  311. func dismiss(animated flag: Bool) async {}
  312. }
  313. let obj = AuthUIImpl()
  314. await obj.present(UIViewController(), animated: true)
  315. await obj.dismiss(animated: false)
  316. }
  317. func FIREmailAuthProvider_h() {
  318. _ = EmailAuthProvider.credential(withEmail: "e@email.com", password: "password")
  319. _ = EmailAuthProvider.credential(withEmail: "e@email.com", link: "link")
  320. }
  321. func FIRFacebookAuthProvider_h() {
  322. _ = FacebookAuthProvider.credential(withAccessToken: "token")
  323. }
  324. #if os(iOS)
  325. func FIRFederatedAuthProvider_h() {
  326. class FederatedAuthImplementation: NSObject, FederatedAuthProvider {
  327. func getCredentialWith(_ UIDelegate: AuthUIDelegate?,
  328. completion: ((AuthCredential?, Error?) -> Void)? = nil) {}
  329. }
  330. let obj = FederatedAuthImplementation()
  331. obj.getCredentialWith(nil) { _, _ in
  332. }
  333. }
  334. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  335. func FIRFedederatedAuthProvider_hAsync() async throws {
  336. class FederatedAuthImplementation: NSObject, FederatedAuthProvider {
  337. func credential(with UIDelegate: AuthUIDelegate?) async throws -> AuthCredential {
  338. return FacebookAuthProvider.credential(withAccessToken: "token")
  339. }
  340. }
  341. let obj = FederatedAuthImplementation()
  342. try await _ = obj.credential(with: nil)
  343. }
  344. #endif
  345. #if !os(watchOS)
  346. func FIRGameCenterAuthProvider_h() {
  347. GameCenterAuthProvider.getCredential { _, _ in
  348. }
  349. }
  350. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  351. func FIRGameCenterAuthProvider_hAsync() async throws {
  352. _ = try await GameCenterAuthProvider.getCredential()
  353. }
  354. #endif
  355. func FIRGitHubAuthProvider_h() {
  356. _ = GitHubAuthProvider.credential(withToken: "token")
  357. }
  358. func FIRGoogleAuthProvider_h() {
  359. _ = GoogleAuthProvider.credential(withIDToken: "token", accessToken: "aToken")
  360. }
  361. #if os(iOS)
  362. func FIRMultiFactor_h(obj: MultiFactor) {
  363. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  364. let credential = provider.credential(withVerificationID: "id",
  365. verificationCode: "code")
  366. obj.getSessionWithCompletion { _, _ in
  367. }
  368. obj
  369. .enroll(with: PhoneMultiFactorGenerator.assertion(with: credential),
  370. displayName: "name") { _ in
  371. }
  372. let mfi = obj.enrolledFactors[0]
  373. obj.unenroll(with: mfi) { _ in
  374. }
  375. obj.unenroll(withFactorUID: "uid") { _ in
  376. }
  377. let _: [MultiFactorInfo] = obj.enrolledFactors
  378. }
  379. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  380. func FIRMultiFactor_hAsync(obj: MultiFactor) async throws {
  381. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  382. let credential = provider.credential(withVerificationID: "id",
  383. verificationCode: "code")
  384. _ = try await obj.session()
  385. try await obj.enroll(
  386. with: PhoneMultiFactorGenerator.assertion(with: credential),
  387. displayName: "name"
  388. )
  389. let mfi = obj.enrolledFactors[0]
  390. try await obj.unenroll(with: mfi)
  391. try await obj.unenroll(withFactorUID: "uid")
  392. }
  393. func multiFactorAssertion(assertion: MultiFactorAssertion) {
  394. let _: String = assertion.factorID
  395. }
  396. func multiFactorInfo(mfi: MultiFactorInfo) {
  397. let _: String = mfi.uid
  398. let _: Date = mfi.enrollmentDate
  399. let _: String = mfi.factorID
  400. if let _: String = mfi.displayName {}
  401. }
  402. func FIRMultiFactorResolver_h(error: NSError) {
  403. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  404. let credential = provider.credential(withVerificationID: "id",
  405. verificationCode: "code")
  406. if let obj = error
  407. .userInfo[AuthErrorUserInfoMultiFactorResolverKey] as? MultiFactorResolver {
  408. obj.resolveSignIn(with: PhoneMultiFactorGenerator.assertion(with: credential)) { _, _ in
  409. }
  410. let _: MultiFactorSession = obj.session
  411. let _: [MultiFactorInfo] = obj.hints
  412. let _: Auth = obj.auth
  413. }
  414. }
  415. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  416. func FIRMultiFactorResolver_hAsync(error: NSError) async throws {
  417. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  418. let credential = provider.credential(withVerificationID: "id",
  419. verificationCode: "code")
  420. if let obj = error
  421. .userInfo[AuthErrorUserInfoMultiFactorResolverKey] as? MultiFactorResolver {
  422. _ = try await obj.resolveSignIn(with: PhoneMultiFactorGenerator.assertion(with: credential))
  423. }
  424. }
  425. #endif
  426. func oauthCredential(credential: OAuthCredential) {
  427. if let _: String = credential.idToken,
  428. let _: String = credential.accessToken,
  429. let _: String = credential.secret {}
  430. }
  431. func FIROAuthProvider_h() {
  432. let provider = OAuthProvider(providerID: "id", auth: FirebaseAuth.Auth.auth())
  433. _ = provider.providerID
  434. #if os(iOS)
  435. _ = OAuthProvider.credential(withProviderID: "id", idToken: "idToden", accessToken: "token")
  436. _ = OAuthProvider.credential(withProviderID: "id", accessToken: "token")
  437. _ = OAuthProvider.credential(withProviderID: "id", idToken: "idToken", rawNonce: "nonce",
  438. accessToken: "token")
  439. _ = OAuthProvider.credential(withProviderID: "id", idToken: "idToken", rawNonce: "nonce")
  440. _ = OAuthProvider.appleCredential(withIDToken: "idToken",
  441. rawNonce: "nonce",
  442. fullName: nil)
  443. provider.getCredentialWith(provider as? AuthUIDelegate) { credential, error in
  444. }
  445. #endif
  446. let _: String = provider.providerID
  447. if let _: [String] = provider.scopes,
  448. let _: [String: String] = provider.customParameters {}
  449. }
  450. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  451. func FIROAuthProvider_h() async throws {
  452. let provider = OAuthProvider(providerID: "abc")
  453. #if os(iOS)
  454. provider.getCredentialWith(provider as? AuthUIDelegate) { credential, error in
  455. }
  456. _ = try await provider.credential(with: provider as? AuthUIDelegate)
  457. #endif
  458. }
  459. #if os(iOS)
  460. func FIRPhoneAuthProvider_h(mfi: PhoneMultiFactorInfo) {
  461. _ = PhoneAuthProvider.provider()
  462. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  463. provider.verifyPhoneNumber("123", uiDelegate: nil) { _, _ in
  464. }
  465. provider.verifyPhoneNumber("123", uiDelegate: nil, multiFactorSession: nil) { _, _ in
  466. }
  467. provider.verifyPhoneNumber(
  468. with: mfi,
  469. uiDelegate: nil,
  470. multiFactorSession: nil
  471. ) { _, _ in
  472. }
  473. _ = provider.credential(withVerificationID: "id", verificationCode: "code")
  474. }
  475. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  476. func FIRPhoneAuthProvider_hAsync(mfi: PhoneMultiFactorInfo) async throws {
  477. _ = PhoneAuthProvider.provider()
  478. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  479. _ = try await provider.verifyPhoneNumber("123", uiDelegate: nil)
  480. _ = try await provider.verifyPhoneNumber("123", uiDelegate: nil, multiFactorSession: nil)
  481. _ = try await provider.verifyPhoneNumber(with: mfi, uiDelegate: nil,
  482. multiFactorSession: nil)
  483. _ = try await provider.verifyPhoneNumber("123", uiDelegate: nil, multiFactorSession: nil)
  484. }
  485. func FIRPhoneMultiFactorGenerator_h() {
  486. let credential = PhoneAuthProvider.provider().credential(withVerificationID: "id",
  487. verificationCode: "code")
  488. _ = PhoneMultiFactorGenerator.assertion(with: credential)
  489. }
  490. func phoneMultiFactorInfo(mfi: PhoneMultiFactorInfo) {
  491. let _: String = mfi.phoneNumber
  492. }
  493. func FIRTOTPSecret_h(session: MultiFactorSession) async throws {
  494. let obj = try await TOTPMultiFactorGenerator.generateSecret(with: session)
  495. _ = obj.sharedSecretKey()
  496. _ = obj.generateQRCodeURL(withAccountName: "name", issuer: "issuer")
  497. obj.openInOTPApp(withQRCodeURL: "url")
  498. }
  499. func FIRTOTPMultiFactorGenerator_h(session: MultiFactorSession, secret: TOTPSecret) {
  500. TOTPMultiFactorGenerator.generateSecret(with: session) { _, _ in
  501. }
  502. _ = TOTPMultiFactorGenerator.assertionForEnrollment(with: secret,
  503. oneTimePassword: "code")
  504. _ = TOTPMultiFactorGenerator.assertionForSignIn(
  505. withEnrollmentID: "id", oneTimePassword: "code"
  506. )
  507. }
  508. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  509. func FIRTOTPMultiFactorGenerator_hAsync(session: MultiFactorSession) async throws {
  510. _ = try await TOTPMultiFactorGenerator.generateSecret(with: session)
  511. }
  512. #endif
  513. func FIRTwitterAuthProvider_h() {
  514. _ = TwitterAuthProvider.credential(withToken: "token", secret: "secret")
  515. }
  516. func FIRUser_h() {
  517. let auth = FirebaseAuth.Auth.auth()
  518. let user = auth.currentUser!
  519. let credential = GoogleAuthProvider.credential(withIDToken: "token", accessToken: "aToken")
  520. user.updatePassword(to: "password") { _ in
  521. }
  522. let changeRequest = user.createProfileChangeRequest()
  523. user.reload { _ in
  524. }
  525. user.reauthenticate(with: credential) { _, _ in
  526. }
  527. #if os(iOS)
  528. let phoneCredential = PhoneAuthProvider.provider().credential(withVerificationID: "id",
  529. verificationCode: "code")
  530. user.updatePhoneNumber(phoneCredential) { _ in
  531. }
  532. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  533. user.reauthenticate(with: provider as! FederatedAuthProvider, uiDelegate: nil)
  534. user.link(with: provider as! FederatedAuthProvider, uiDelegate: nil) { _, _ in
  535. }
  536. #endif
  537. user.getIDTokenResult { _, _ in
  538. }
  539. user.getIDTokenResult(forcingRefresh: true) { _, _ in
  540. }
  541. user.getIDToken { _, _ in
  542. }
  543. user.getIDTokenForcingRefresh(true) { _, _ in
  544. }
  545. user.link(with: credential) { _, _ in
  546. }
  547. user.unlink(fromProvider: "abc") { _, _ in
  548. }
  549. user.sendEmailVerification { _ in
  550. }
  551. user.sendEmailVerification(with: ActionCodeSettings()) { _ in
  552. }
  553. user.delete { _ in
  554. }
  555. user.sendEmailVerification(beforeUpdatingEmail: "email") { _ in
  556. }
  557. user.sendEmailVerification(
  558. beforeUpdatingEmail: "email",
  559. actionCodeSettings: ActionCodeSettings()
  560. ) { _ in
  561. }
  562. changeRequest.commitChanges { _ in
  563. }
  564. let _: String = user.providerID
  565. let _: String = user.uid
  566. if let _: String = user.displayName,
  567. let _: URL = user.photoURL,
  568. let _: String = user.email,
  569. let _: String = user.phoneNumber {}
  570. }
  571. func userProperties(user: User) {
  572. let changeRequest = user.createProfileChangeRequest()
  573. let _: Bool = user.isAnonymous
  574. let _: Bool = user.isEmailVerified
  575. let _: [UserInfo] = user.providerData
  576. let _: UserMetadata = user.metadata
  577. #if os(iOS)
  578. let _: MultiFactor = user.multiFactor
  579. #endif
  580. if let _: String = user.refreshToken,
  581. let _: String = user.tenantID,
  582. let _: String = changeRequest.displayName,
  583. let _: URL = changeRequest.photoURL {}
  584. }
  585. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  586. func FIRUser_hAsync() async throws {
  587. let auth = FirebaseAuth.Auth.auth()
  588. let user = auth.currentUser!
  589. let credential = GoogleAuthProvider.credential(withIDToken: "token", accessToken: "aToken")
  590. try await user.updatePassword(to: "password")
  591. let changeRequest = user.createProfileChangeRequest()
  592. try await user.reload()
  593. try await user.reauthenticate(with: credential)
  594. #if os(iOS)
  595. let phoneCredential = PhoneAuthProvider.provider().credential(withVerificationID: "id",
  596. verificationCode: "code")
  597. try await user.updatePhoneNumber(phoneCredential)
  598. let provider = PhoneAuthProvider.provider(auth: FirebaseAuth.Auth.auth())
  599. try await user.reauthenticate(with: provider as! FederatedAuthProvider, uiDelegate: nil)
  600. try await user.link(with: provider as! FederatedAuthProvider, uiDelegate: nil)
  601. #endif
  602. _ = try await user.getIDTokenResult()
  603. _ = try await user.getIDTokenResult(forcingRefresh: true)
  604. _ = try await user.getIDToken()
  605. _ = try await user.link(with: credential)
  606. _ = try await user.unlink(fromProvider: "abc")
  607. try await user.sendEmailVerification()
  608. try await user.sendEmailVerification(with: ActionCodeSettings())
  609. try await user.delete()
  610. try await user.sendEmailVerification(beforeUpdatingEmail: "email")
  611. try await user.sendEmailVerification(
  612. beforeUpdatingEmail: "email",
  613. actionCodeSettings: ActionCodeSettings()
  614. )
  615. try await changeRequest.commitChanges()
  616. }
  617. func userInfoProperties(userInfo: UserInfo) {
  618. let _: String = userInfo.providerID
  619. let _: String = userInfo.uid
  620. if let _: String = userInfo.displayName,
  621. let _: URL = userInfo.photoURL,
  622. let _: String = userInfo.email,
  623. let _: String = userInfo.phoneNumber {}
  624. }
  625. func userMetadataProperties(metadata: UserMetadata) {
  626. if let _: Date = metadata.lastSignInDate,
  627. let _: Date = metadata.creationDate {}
  628. }
  629. }