SwiftAPI.swift 27 KB

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