SwiftAPI.swift 27 KB

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