SwiftAPI.swift 26 KB

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