PhoneAuthProvider.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import FirebaseCore
  15. import Foundation
  16. /// A concrete implementation of `AuthProvider` for phone auth providers.
  17. ///
  18. /// This class is available on iOS only.
  19. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  20. @objc(FIRPhoneAuthProvider) open class PhoneAuthProvider: NSObject {
  21. /// A string constant identifying the phone identity provider.
  22. @objc public static let id = "phone"
  23. #if os(iOS)
  24. /// Returns an instance of `PhoneAuthProvider` for the default `Auth` object.
  25. @objc(provider) open class func provider() -> PhoneAuthProvider {
  26. return PhoneAuthProvider(auth: Auth.auth())
  27. }
  28. /// Returns an instance of `PhoneAuthProvider` for the provided `Auth` object.
  29. /// - Parameter auth: The auth object to associate with the phone auth provider instance.
  30. @objc(providerWithAuth:)
  31. open class func provider(auth: Auth) -> PhoneAuthProvider {
  32. return PhoneAuthProvider(auth: auth)
  33. }
  34. /// Starts the phone number authentication flow by sending a verification code to the
  35. /// specified phone number.
  36. ///
  37. /// Possible error codes:
  38. /// * `AuthErrorCodeCaptchaCheckFailed` - Indicates that the reCAPTCHA token obtained by
  39. /// the Firebase Auth is invalid or has expired.
  40. /// * `AuthErrorCodeQuotaExceeded` - Indicates that the phone verification quota for this
  41. /// project has been exceeded.
  42. /// * `AuthErrorCodeInvalidPhoneNumber` - Indicates that the phone number provided is invalid.
  43. /// * `AuthErrorCodeMissingPhoneNumber` - Indicates that a phone number was not provided.
  44. /// - Parameter phoneNumber: The phone number to be verified.
  45. /// - Parameter uiDelegate: An object used to present the SFSafariViewController. The object is
  46. /// retained by this method until the completion block is executed.
  47. /// - Parameter completion: The callback to be invoked when the verification flow is finished.
  48. @objc(verifyPhoneNumber:UIDelegate:completion:)
  49. open func verifyPhoneNumber(_ phoneNumber: String,
  50. uiDelegate: AuthUIDelegate? = nil,
  51. completion: ((_: String?, _: Error?) -> Void)?) {
  52. verifyPhoneNumber(phoneNumber,
  53. uiDelegate: uiDelegate,
  54. multiFactorSession: nil,
  55. completion: completion)
  56. }
  57. /// Verify ownership of the second factor phone number by the current user.
  58. /// - Parameter phoneNumber: The phone number to be verified.
  59. /// - Parameter uiDelegate: An object used to present the SFSafariViewController. The object is
  60. /// retained by this method until the completion block is executed.
  61. /// - Parameter multiFactorSession: A session to identify the MFA flow. For enrollment, this
  62. /// identifies the user trying to enroll. For sign-in, this identifies that the user already
  63. /// passed the first factor challenge.
  64. /// - Parameter completion: The callback to be invoked when the verification flow is finished.
  65. @objc(verifyPhoneNumber:UIDelegate:multiFactorSession:completion:)
  66. open func verifyPhoneNumber(_ phoneNumber: String,
  67. uiDelegate: AuthUIDelegate? = nil,
  68. multiFactorSession: MultiFactorSession? = nil,
  69. completion: ((_: String?, _: Error?) -> Void)?) {
  70. guard AuthWebUtils.isCallbackSchemeRegistered(forCustomURLScheme: callbackScheme,
  71. urlTypes: auth.mainBundleUrlTypes) else {
  72. fatalError(
  73. "Please register custom URL scheme \(callbackScheme) in the app's Info.plist file."
  74. )
  75. }
  76. kAuthGlobalWorkQueue.async {
  77. Task {
  78. do {
  79. let verificationID = try await self.internalVerify(
  80. phoneNumber: phoneNumber,
  81. uiDelegate: uiDelegate,
  82. multiFactorSession: multiFactorSession
  83. )
  84. Auth.wrapMainAsync(callback: completion, withParam: verificationID, error: nil)
  85. } catch {
  86. Auth.wrapMainAsync(callback: completion, withParam: nil, error: error)
  87. }
  88. }
  89. }
  90. }
  91. /// Verify ownership of the second factor phone number by the current user.
  92. /// - Parameter phoneNumber: The phone number to be verified.
  93. /// - Parameter uiDelegate: An object used to present the SFSafariViewController. The object is
  94. /// retained by this method until the completion block is executed.
  95. /// - Parameter multiFactorSession: A session to identify the MFA flow. For enrollment, this
  96. /// identifies the user trying to enroll. For sign-in, this identifies that the user already
  97. /// passed the first factor challenge.
  98. /// - Returns: The verification ID
  99. @available(iOS 13, tvOS 13, macOS 10.15, watchOS 8, *)
  100. open func verifyPhoneNumber(_ phoneNumber: String,
  101. uiDelegate: AuthUIDelegate? = nil,
  102. multiFactorSession: MultiFactorSession? = nil) async throws
  103. -> String {
  104. guard AuthWebUtils.isCallbackSchemeRegistered(forCustomURLScheme: callbackScheme,
  105. urlTypes: auth.mainBundleUrlTypes) else {
  106. fatalError(
  107. "Please register custom URL scheme \(callbackScheme) in the app's Info.plist file."
  108. )
  109. }
  110. do {
  111. if let verificationID = try await internalVerify(
  112. phoneNumber: phoneNumber,
  113. uiDelegate: uiDelegate,
  114. multiFactorSession: multiFactorSession
  115. ) {
  116. return verificationID
  117. } else {
  118. throw AuthErrorUtils.invalidVerificationIDError(message: "Invalid verification ID")
  119. }
  120. } catch {
  121. throw error
  122. }
  123. }
  124. /// Verify ownership of the second factor phone number by the current user.
  125. /// - Parameter multiFactorInfo: The phone multi factor whose number need to be verified.
  126. /// - Parameter uiDelegate: An object used to present the SFSafariViewController. The object is
  127. /// retained by this method until the completion block is executed.
  128. /// - Parameter multiFactorSession: A session to identify the MFA flow. For enrollment, this
  129. /// identifies the user trying to enroll. For sign-in, this identifies that the user already
  130. /// passed the first factor challenge.
  131. /// - Parameter completion: The callback to be invoked when the verification flow is finished.
  132. @objc(verifyPhoneNumberWithMultiFactorInfo:UIDelegate:multiFactorSession:completion:)
  133. open func verifyPhoneNumber(with multiFactorInfo: PhoneMultiFactorInfo,
  134. uiDelegate: AuthUIDelegate? = nil,
  135. multiFactorSession: MultiFactorSession?,
  136. completion: ((_: String?, _: Error?) -> Void)?) {
  137. multiFactorSession?.multiFactorInfo = multiFactorInfo
  138. verifyPhoneNumber(multiFactorInfo.phoneNumber,
  139. uiDelegate: uiDelegate,
  140. multiFactorSession: multiFactorSession,
  141. completion: completion)
  142. }
  143. /// Verify ownership of the second factor phone number by the current user.
  144. /// - Parameter multiFactorInfo: The phone multi factor whose number need to be verified.
  145. /// - Parameter uiDelegate: An object used to present the SFSafariViewController. The object is
  146. /// retained by this method until the completion block is executed.
  147. /// - Parameter multiFactorSession: A session to identify the MFA flow. For enrollment, this
  148. /// identifies the user trying to enroll. For sign-in, this identifies that the user already
  149. /// passed the first factor challenge.
  150. /// - Returns: The verification ID.
  151. @available(iOS 13, tvOS 13, macOS 10.15, watchOS 8, *)
  152. open func verifyPhoneNumber(with multiFactorInfo: PhoneMultiFactorInfo,
  153. uiDelegate: AuthUIDelegate? = nil,
  154. multiFactorSession: MultiFactorSession?) async throws -> String {
  155. do {
  156. multiFactorSession?.multiFactorInfo = multiFactorInfo
  157. return try await verifyPhoneNumber(multiFactorInfo.phoneNumber,
  158. uiDelegate: uiDelegate,
  159. multiFactorSession: multiFactorSession)
  160. } catch {
  161. throw error
  162. }
  163. }
  164. /// Creates an `AuthCredential` for the phone number provider identified by the
  165. /// verification ID and verification code.
  166. ///
  167. /// - Parameter verificationID: The verification ID obtained from invoking
  168. /// verifyPhoneNumber:completion:
  169. /// - Parameter verificationCode: The verification code obtained from the user.
  170. /// - Returns: The corresponding phone auth credential for the verification ID and verification
  171. /// code provided.
  172. @objc(credentialWithVerificationID:verificationCode:)
  173. open func credential(withVerificationID verificationID: String,
  174. verificationCode: String) -> PhoneAuthCredential {
  175. return PhoneAuthCredential(withProviderID: PhoneAuthProvider.id,
  176. verificationID: verificationID,
  177. verificationCode: verificationCode)
  178. }
  179. private func internalVerify(phoneNumber: String,
  180. uiDelegate: AuthUIDelegate?,
  181. multiFactorSession: MultiFactorSession? = nil) async throws
  182. -> String? {
  183. guard phoneNumber.count > 0 else {
  184. throw AuthErrorUtils.missingPhoneNumberError(message: nil)
  185. }
  186. guard let manager = auth.notificationManager else {
  187. throw AuthErrorUtils.notificationNotForwardedError()
  188. }
  189. guard await manager.checkNotificationForwarding() else {
  190. throw AuthErrorUtils.notificationNotForwardedError()
  191. }
  192. return try await verifyClAndSendVerificationCode(toPhoneNumber: phoneNumber,
  193. retryOnInvalidAppCredential: true,
  194. multiFactorSession: multiFactorSession,
  195. uiDelegate: uiDelegate)
  196. }
  197. /// Starts the flow to verify the client via silent push notification.
  198. /// - Parameter retryOnInvalidAppCredential: Whether of not the flow should be retried if an
  199. /// AuthErrorCodeInvalidAppCredential error is returned from the backend.
  200. /// - Parameter phoneNumber: The phone number to be verified.
  201. /// - Parameter callback: The callback to be invoked on the global work queue when the flow is
  202. /// finished.
  203. private func verifyClAndSendVerificationCode(toPhoneNumber phoneNumber: String,
  204. retryOnInvalidAppCredential: Bool,
  205. uiDelegate: AuthUIDelegate?) async throws
  206. -> String? {
  207. let codeIdentity = try await verifyClient(withUIDelegate: uiDelegate)
  208. let request = SendVerificationCodeRequest(phoneNumber: phoneNumber,
  209. codeIdentity: codeIdentity,
  210. requestConfiguration: auth
  211. .requestConfiguration)
  212. do {
  213. let response = try await AuthBackend.call(with: request)
  214. return response.verificationID
  215. } catch {
  216. return try await handleVerifyErrorWithRetry(error: error,
  217. phoneNumber: phoneNumber,
  218. retryOnInvalidAppCredential: retryOnInvalidAppCredential,
  219. multiFactorSession: nil,
  220. uiDelegate: uiDelegate)
  221. }
  222. }
  223. /// Starts the flow to verify the client via silent push notification.
  224. /// - Parameter retryOnInvalidAppCredential: Whether of not the flow should be retried if an
  225. /// AuthErrorCodeInvalidAppCredential error is returned from the backend.
  226. /// - Parameter phoneNumber: The phone number to be verified.
  227. private func verifyClAndSendVerificationCode(toPhoneNumber phoneNumber: String,
  228. retryOnInvalidAppCredential: Bool,
  229. multiFactorSession session: MultiFactorSession?,
  230. uiDelegate: AuthUIDelegate?) async throws
  231. -> String? {
  232. if let settings = auth.settings,
  233. settings.isAppVerificationDisabledForTesting {
  234. let request = SendVerificationCodeRequest(
  235. phoneNumber: phoneNumber,
  236. codeIdentity: CodeIdentity.empty,
  237. requestConfiguration: auth.requestConfiguration
  238. )
  239. let response = try await AuthBackend.call(with: request)
  240. return response.verificationID
  241. }
  242. guard let session else {
  243. return try await verifyClAndSendVerificationCode(
  244. toPhoneNumber: phoneNumber,
  245. retryOnInvalidAppCredential: retryOnInvalidAppCredential,
  246. uiDelegate: uiDelegate
  247. )
  248. }
  249. let codeIdentity = try await verifyClient(withUIDelegate: uiDelegate)
  250. let startMFARequestInfo = AuthProtoStartMFAPhoneRequestInfo(phoneNumber: phoneNumber,
  251. codeIdentity: codeIdentity)
  252. do {
  253. if let idToken = session.idToken {
  254. let request = StartMFAEnrollmentRequest(idToken: idToken,
  255. enrollmentInfo: startMFARequestInfo,
  256. requestConfiguration: auth.requestConfiguration)
  257. let response = try await AuthBackend.call(with: request)
  258. return response.phoneSessionInfo?.sessionInfo
  259. } else {
  260. let request = StartMFASignInRequest(MFAPendingCredential: session.mfaPendingCredential,
  261. MFAEnrollmentID: session.multiFactorInfo?.uid,
  262. signInInfo: startMFARequestInfo,
  263. requestConfiguration: auth.requestConfiguration)
  264. let response = try await AuthBackend.call(with: request)
  265. return response.responseInfo?.sessionInfo
  266. }
  267. } catch {
  268. return try await handleVerifyErrorWithRetry(
  269. error: error,
  270. phoneNumber: phoneNumber,
  271. retryOnInvalidAppCredential: retryOnInvalidAppCredential,
  272. multiFactorSession: session,
  273. uiDelegate: uiDelegate
  274. )
  275. }
  276. }
  277. private func handleVerifyErrorWithRetry(error: Error,
  278. phoneNumber: String,
  279. retryOnInvalidAppCredential: Bool,
  280. multiFactorSession session: MultiFactorSession?,
  281. uiDelegate: AuthUIDelegate?) async throws -> String? {
  282. if (error as NSError).code == AuthErrorCode.invalidAppCredential.rawValue {
  283. if retryOnInvalidAppCredential {
  284. auth.appCredentialManager.clearCredential()
  285. return try await verifyClAndSendVerificationCode(toPhoneNumber: phoneNumber,
  286. retryOnInvalidAppCredential: false,
  287. multiFactorSession: session,
  288. uiDelegate: uiDelegate)
  289. }
  290. throw AuthErrorUtils.unexpectedResponse(deserializedResponse: nil, underlyingError: error)
  291. }
  292. throw error
  293. }
  294. /// Continues the flow to verify the client via silent push notification.
  295. private func verifyClient(withUIDelegate uiDelegate: AuthUIDelegate?) async throws
  296. -> CodeIdentity {
  297. // Remove the simulator check below after FCM supports APNs in simulators
  298. #if targetEnvironment(simulator)
  299. let environment = ProcessInfo().environment
  300. if environment["XCTestConfigurationFilePath"] == nil {
  301. return try await CodeIdentity
  302. .recaptcha(reCAPTCHAFlowWithUIDelegate(withUIDelegate: uiDelegate))
  303. }
  304. #endif
  305. if let credential = auth.appCredentialManager.credential {
  306. return CodeIdentity.credential(credential)
  307. }
  308. var token: AuthAPNSToken
  309. do {
  310. token = try await auth.tokenManager.getToken()
  311. } catch {
  312. return try await CodeIdentity
  313. .recaptcha(reCAPTCHAFlowWithUIDelegate(withUIDelegate: uiDelegate))
  314. }
  315. let request = VerifyClientRequest(withAppToken: token.string,
  316. isSandbox: token.type == AuthAPNSTokenType.sandbox,
  317. requestConfiguration: auth.requestConfiguration)
  318. do {
  319. let verifyResponse = try await AuthBackend.call(with: request)
  320. guard let receipt = verifyResponse.receipt,
  321. let timeout = verifyResponse.suggestedTimeOutDate?.timeIntervalSinceNow else {
  322. fatalError("Internal Auth Error: invalid VerifyClientResponse")
  323. }
  324. let credential = await
  325. auth.appCredentialManager.didStartVerification(withReceipt: receipt, timeout: timeout)
  326. if credential.secret == nil {
  327. AuthLog.logWarning(code: "I-AUT000014", message: "Failed to receive remote " +
  328. "notification to verify app identity within \(timeout) " +
  329. "second(s), falling back to reCAPTCHA verification.")
  330. return try await CodeIdentity
  331. .recaptcha(reCAPTCHAFlowWithUIDelegate(withUIDelegate: uiDelegate))
  332. }
  333. return CodeIdentity.credential(credential)
  334. } catch {
  335. let nserror = error as NSError
  336. // reCAPTCHA Flow if it's an invalid app credential or a missing app token.
  337. if (nserror.code == AuthErrorCode.internalError.rawValue &&
  338. (nserror.userInfo[NSUnderlyingErrorKey] as? NSError)?.code ==
  339. AuthErrorCode.invalidAppCredential.rawValue) ||
  340. nserror.code == AuthErrorCode.missingAppToken.rawValue {
  341. return try await CodeIdentity
  342. .recaptcha(reCAPTCHAFlowWithUIDelegate(withUIDelegate: uiDelegate))
  343. } else {
  344. throw error
  345. }
  346. }
  347. }
  348. /// Continues the flow to verify the client via silent push notification.
  349. private func reCAPTCHAFlowWithUIDelegate(withUIDelegate uiDelegate: AuthUIDelegate?) async throws
  350. -> String {
  351. let eventID = AuthWebUtils.randomString(withLength: 10)
  352. guard let url = try await reCAPTCHAURL(withEventID: eventID) else {
  353. fatalError(
  354. "Internal error: reCAPTCHAURL returned neither a value nor an error. Report issue"
  355. )
  356. }
  357. let callbackMatcher: (URL?) -> Bool = { callbackURL in
  358. AuthWebUtils.isExpectedCallbackURL(
  359. callbackURL,
  360. eventID: eventID,
  361. authType: self.kAuthTypeVerifyApp,
  362. callbackScheme: self.callbackScheme
  363. )
  364. }
  365. return try await withCheckedThrowingContinuation { continuation in
  366. self.auth.authURLPresenter.present(url,
  367. uiDelegate: uiDelegate,
  368. callbackMatcher: callbackMatcher) { callbackURL, error in
  369. if let error {
  370. continuation.resume(throwing: error)
  371. } else {
  372. do {
  373. try continuation.resume(returning: self.reCAPTCHAToken(forURL: callbackURL))
  374. } catch {
  375. continuation.resume(throwing: error)
  376. }
  377. }
  378. }
  379. }
  380. }
  381. /// Parses the reCAPTCHA URL and returns the reCAPTCHA token.
  382. /// - Parameter url: The url to be parsed for a reCAPTCHA token.
  383. /// - Returns: The reCAPTCHA token if successful.
  384. private func reCAPTCHAToken(forURL url: URL?) throws -> String {
  385. guard let url = url else {
  386. let reason = "Internal Auth Error: nil URL trying to access RECAPTCHA token"
  387. throw AuthErrorUtils.appVerificationUserInteractionFailure(reason: reason)
  388. }
  389. let actualURLComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
  390. if let queryItems = actualURLComponents?.queryItems,
  391. let deepLinkURL = AuthWebUtils.queryItemValue(name: "deep_link_id", from: queryItems) {
  392. let deepLinkComponents = URLComponents(string: deepLinkURL)
  393. if let queryItems = deepLinkComponents?.queryItems {
  394. if let token = AuthWebUtils.queryItemValue(name: "recaptchaToken", from: queryItems) {
  395. return token
  396. }
  397. if let firebaseError = AuthWebUtils.queryItemValue(
  398. name: "firebaseError",
  399. from: queryItems
  400. ) {
  401. if let errorData = firebaseError.data(using: .utf8) {
  402. var errorDict: [AnyHashable: Any]?
  403. do {
  404. errorDict = try JSONSerialization.jsonObject(with: errorData) as? [AnyHashable: Any]
  405. } catch {
  406. throw AuthErrorUtils.JSONSerializationError(underlyingError: error)
  407. }
  408. if let errorDict,
  409. let code = errorDict["code"] as? String,
  410. let message = errorDict["message"] as? String {
  411. throw AuthErrorUtils.urlResponseError(code: code, message: message)
  412. }
  413. }
  414. }
  415. }
  416. let reason = "An unknown error occurred with the following response: \(deepLinkURL)"
  417. throw AuthErrorUtils.appVerificationUserInteractionFailure(reason: reason)
  418. }
  419. let reason = "Failed to get url Components for url: \(url)"
  420. throw AuthErrorUtils.appVerificationUserInteractionFailure(reason: reason)
  421. }
  422. /// Constructs a URL used for opening a reCAPTCHA app verification flow using a given event ID.
  423. /// - Parameter eventID: The event ID used for this purpose.
  424. private func reCAPTCHAURL(withEventID eventID: String) async throws -> URL? {
  425. let authDomain = try await AuthWebUtils
  426. .fetchAuthDomain(withRequestConfiguration: auth.requestConfiguration)
  427. let bundleID = Bundle.main.bundleIdentifier
  428. let clientID = auth.app?.options.clientID
  429. let appID = auth.app?.options.googleAppID
  430. let apiKey = auth.requestConfiguration.apiKey
  431. let appCheck = auth.requestConfiguration.appCheck
  432. var queryItems = [URLQueryItem(name: "apiKey", value: apiKey),
  433. URLQueryItem(name: "authType", value: kAuthTypeVerifyApp),
  434. URLQueryItem(name: "ibi", value: bundleID ?? ""),
  435. URLQueryItem(name: "v", value: AuthBackend.authUserAgent()),
  436. URLQueryItem(name: "eventId", value: eventID)]
  437. if usingClientIDScheme {
  438. queryItems.append(URLQueryItem(name: "clientId", value: clientID))
  439. } else {
  440. queryItems.append(URLQueryItem(name: "appId", value: appID))
  441. }
  442. if let languageCode = auth.requestConfiguration.languageCode {
  443. queryItems.append(URLQueryItem(name: "hl", value: languageCode))
  444. }
  445. var components = URLComponents(string: "https://\(authDomain)/__/auth/handler?")
  446. components?.queryItems = queryItems
  447. if let appCheck {
  448. let tokenResult = await appCheck.getToken(forcingRefresh: false)
  449. if let error = tokenResult.error {
  450. AuthLog.logWarning(code: "I-AUT000018",
  451. message: "Error getting App Check token; using placeholder " +
  452. "token instead. Error: \(error)")
  453. }
  454. let appCheckTokenFragment = "fac=\(tokenResult.token)"
  455. components?.fragment = appCheckTokenFragment
  456. }
  457. return components?.url
  458. }
  459. private let auth: Auth
  460. private let callbackScheme: String
  461. private let usingClientIDScheme: Bool
  462. init(auth: Auth) {
  463. self.auth = auth
  464. if let clientID = auth.app?.options.clientID {
  465. let reverseClientIDScheme = clientID.components(separatedBy: ".").reversed()
  466. .joined(separator: ".")
  467. if AuthWebUtils.isCallbackSchemeRegistered(forCustomURLScheme: reverseClientIDScheme,
  468. urlTypes: auth.mainBundleUrlTypes) {
  469. callbackScheme = reverseClientIDScheme
  470. usingClientIDScheme = true
  471. return
  472. }
  473. }
  474. usingClientIDScheme = false
  475. if let appID = auth.app?.options.googleAppID {
  476. let dashedAppID = appID.replacingOccurrences(of: ":", with: "-")
  477. callbackScheme = "app-\(dashedAppID)"
  478. return
  479. }
  480. callbackScheme = ""
  481. }
  482. private let kAuthTypeVerifyApp = "verifyApp"
  483. #endif
  484. }