FIRAuthBackend.m 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. /*
  2. * Copyright 2017 Google
  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 "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  17. #if SWIFT_PACKAGE
  18. @import GTMSessionFetcherCore;
  19. #else
  20. #import <GTMSessionFetcher/GTMSessionFetcher.h>
  21. #import <GTMSessionFetcher/GTMSessionFetcherService.h>
  22. #endif
  23. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FirebaseAuth.h"
  24. #import "FirebaseAuth/Sources/Auth/FIRAuthGlobalWorkQueue.h"
  25. #import "FirebaseAuth/Sources/AuthProvider/OAuth/FIROAuthCredential_Internal.h"
  26. #import "FirebaseAuth/Sources/Backend/RPC/FIRCreateAuthURIRequest.h"
  27. #import "FirebaseAuth/Sources/Backend/RPC/FIRCreateAuthURIResponse.h"
  28. #import "FirebaseAuth/Sources/Backend/RPC/FIRDeleteAccountRequest.h"
  29. #import "FirebaseAuth/Sources/Backend/RPC/FIRDeleteAccountResponse.h"
  30. #import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInRequest.h"
  31. #import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInResponse.h"
  32. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoRequest.h"
  33. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoResponse.h"
  34. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetOOBConfirmationCodeRequest.h"
  35. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetOOBConfirmationCodeResponse.h"
  36. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetProjectConfigRequest.h"
  37. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetProjectConfigResponse.h"
  38. #import "FirebaseAuth/Sources/Backend/RPC/FIRResetPasswordRequest.h"
  39. #import "FirebaseAuth/Sources/Backend/RPC/FIRResetPasswordResponse.h"
  40. #import "FirebaseAuth/Sources/Backend/RPC/FIRSecureTokenRequest.h"
  41. #import "FirebaseAuth/Sources/Backend/RPC/FIRSecureTokenResponse.h"
  42. #import "FirebaseAuth/Sources/Backend/RPC/FIRSendVerificationCodeRequest.h"
  43. #import "FirebaseAuth/Sources/Backend/RPC/FIRSendVerificationCodeResponse.h"
  44. #import "FirebaseAuth/Sources/Backend/RPC/FIRSetAccountInfoRequest.h"
  45. #import "FirebaseAuth/Sources/Backend/RPC/FIRSetAccountInfoResponse.h"
  46. #import "FirebaseAuth/Sources/Backend/RPC/FIRSignInWithGameCenterRequest.h"
  47. #import "FirebaseAuth/Sources/Backend/RPC/FIRSignInWithGameCenterResponse.h"
  48. #import "FirebaseAuth/Sources/Backend/RPC/FIRSignUpNewUserRequest.h"
  49. #import "FirebaseAuth/Sources/Backend/RPC/FIRSignUpNewUserResponse.h"
  50. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionRequest.h"
  51. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionResponse.h"
  52. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyClientRequest.h"
  53. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyClientResponse.h"
  54. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyCustomTokenRequest.h"
  55. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyCustomTokenResponse.h"
  56. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyPasswordRequest.h"
  57. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyPasswordResponse.h"
  58. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyPhoneNumberRequest.h"
  59. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyPhoneNumberResponse.h"
  60. #import "FirebaseAuth/Sources/Utilities/FIRAuthErrorUtils.h"
  61. #import "FirebaseCore/Extension/FirebaseCoreInternal.h"
  62. #if TARGET_OS_IOS
  63. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRPhoneAuthProvider.h"
  64. #import "FirebaseAuth/Sources/AuthProvider/Phone/FIRPhoneAuthCredential_Internal.h"
  65. #import "FirebaseAuth/Sources/MultiFactor/Phone/FIRPhoneMultiFactorInfo+Internal.h"
  66. #endif
  67. NS_ASSUME_NONNULL_BEGIN
  68. /** @var kClientVersionHeader
  69. @brief HTTP header name for the client version.
  70. */
  71. static NSString *const kClientVersionHeader = @"X-Client-Version";
  72. /** @var kIosBundleIdentifierHeader
  73. @brief HTTP header name for iOS bundle ID.
  74. */
  75. static NSString *const kIosBundleIdentifierHeader = @"X-Ios-Bundle-Identifier";
  76. /** @var kFirebaseLocalHeader
  77. @brief HTTP header name for the firebase locale.
  78. */
  79. static NSString *const kFirebaseLocalHeader = @"X-Firebase-Locale";
  80. /** @var kFirebaseAppIDHeader
  81. @brief HTTP header name for the Firebase app ID.
  82. */
  83. static NSString *const kFirebaseAppIDHeader = @"X-Firebase-GMPID";
  84. /** @var kFirebaseHeartbeatHeader
  85. @brief HTTP header name for a Firebase heartbeats payload.
  86. */
  87. static NSString *const kFirebaseHeartbeatHeader = @"X-Firebase-Client";
  88. /** @var kFirebaseAuthCoreFrameworkMarker
  89. @brief The marker in the HTTP header that indicates the request comes from Firebase Auth Core.
  90. */
  91. static NSString *const kFirebaseAuthCoreFrameworkMarker = @"FirebaseCore-iOS";
  92. /** @var kJSONContentType
  93. @brief The value of the HTTP content-type header for JSON payloads.
  94. */
  95. static NSString *const kJSONContentType = @"application/json";
  96. /** @var kErrorDataKey
  97. @brief Key for error data in NSError returned by @c GTMSessionFetcher.
  98. */
  99. static NSString *const kErrorDataKey = @"data";
  100. /** @var kErrorKey
  101. @brief The key for the "error" value in JSON responses from the server.
  102. */
  103. static NSString *const kErrorKey = @"error";
  104. /** @var kErrorsKey
  105. @brief The key for the "errors" value in JSON responses from the server.
  106. */
  107. static NSString *const kErrorsKey = @"errors";
  108. /** @var kReasonKey
  109. @brief The key for the "reason" value in JSON responses from the server.
  110. */
  111. static NSString *const kReasonKey = @"reason";
  112. /** @var kInvalidKeyReasonValue
  113. @brief The value for the "reason" key indicating an invalid API Key was received by the server.
  114. */
  115. static NSString *const kInvalidKeyReasonValue = @"keyInvalid";
  116. /** @var kAppNotAuthorizedReasonValue
  117. @brief The value for the "reason" key indicating the App is not authorized to use Firebase
  118. Authentication.
  119. */
  120. static NSString *const kAppNotAuthorizedReasonValue = @"ipRefererBlocked";
  121. /** @var kErrorMessageKey
  122. @brief The key for an error's "message" value in JSON responses from the server.
  123. */
  124. static NSString *const kErrorMessageKey = @"message";
  125. /** @var kReturnIDPCredentialErrorMessageKey
  126. @brief The key for "errorMessage" value in JSON responses from the server, In case
  127. returnIDPCredential of a verifyAssertion request is set to @YES.
  128. */
  129. static NSString *const kReturnIDPCredentialErrorMessageKey = @"errorMessage";
  130. /** @var kUserNotFoundErrorMessage
  131. @brief This is the error message returned when the user is not found, which means the user
  132. account has been deleted given the token was once valid.
  133. */
  134. static NSString *const kUserNotFoundErrorMessage = @"USER_NOT_FOUND";
  135. /** @var kUserDeletedErrorMessage
  136. @brief This is the error message the server will respond with if the user entered an invalid
  137. email address.
  138. */
  139. static NSString *const kUserDeletedErrorMessage = @"EMAIL_NOT_FOUND";
  140. /** @var kInvalidLocalIDErrorMessage
  141. @brief This is the error message the server responds with if the user local id in the id token
  142. does not exit.
  143. */
  144. static NSString *const kInvalidLocalIDErrorMessage = @"INVALID_LOCAL_ID";
  145. /** @var kUserTokenExpiredErrorMessage
  146. @brief The error returned by the server if the token issue time is older than the account's
  147. valid_since time.
  148. */
  149. static NSString *const kUserTokenExpiredErrorMessage = @"TOKEN_EXPIRED";
  150. /** @var kTooManyRequestsErrorMessage
  151. @brief This is the error message the server will respond with if too many requests were made to
  152. a server method.
  153. */
  154. static NSString *const kTooManyRequestsErrorMessage = @"TOO_MANY_ATTEMPTS_TRY_LATER";
  155. /** @var kInvalidCustomTokenErrorMessage
  156. @brief This is the error message the server will respond with if there is a validation error
  157. with the custom token.
  158. */
  159. static NSString *const kInvalidCustomTokenErrorMessage = @"INVALID_CUSTOM_TOKEN";
  160. /** @var kCustomTokenMismatch
  161. @brief This is the error message the server will respond with if the service account and API key
  162. belong to different projects.
  163. */
  164. static NSString *const kCustomTokenMismatch = @"CREDENTIAL_MISMATCH";
  165. /** @var kInvalidCredentialErrorMessage
  166. @brief This is the error message the server responds with if the IDP token or requestUri is
  167. invalid.
  168. */
  169. static NSString *const kInvalidCredentialErrorMessage = @"INVALID_IDP_RESPONSE";
  170. /** @var kUserDisabledErrorMessage
  171. @brief The error returned by the server if the user account is diabled.
  172. */
  173. static NSString *const kUserDisabledErrorMessage = @"USER_DISABLED";
  174. /** @var kOperationNotAllowedErrorMessage
  175. @brief This is the error message the server will respond with if Admin disables IDP specified by
  176. provider.
  177. */
  178. static NSString *const kOperationNotAllowedErrorMessage = @"OPERATION_NOT_ALLOWED";
  179. /** @var kPasswordLoginDisabledErrorMessage
  180. @brief This is the error message the server responds with if password login is disabled.
  181. */
  182. static NSString *const kPasswordLoginDisabledErrorMessage = @"PASSWORD_LOGIN_DISABLED";
  183. /** @var kEmailAlreadyInUseErrorMessage
  184. @brief This is the error message the server responds with if the email address already exists.
  185. */
  186. static NSString *const kEmailAlreadyInUseErrorMessage = @"EMAIL_EXISTS";
  187. /** @var kInvalidEmailErrorMessage
  188. @brief The error returned by the server if the email is invalid.
  189. */
  190. static NSString *const kInvalidEmailErrorMessage = @"INVALID_EMAIL";
  191. /** @var kInvalidIdentifierErrorMessage
  192. @brief The error returned by the server if the identifier is invalid.
  193. */
  194. static NSString *const kInvalidIdentifierErrorMessage = @"INVALID_IDENTIFIER";
  195. /** @var kWrongPasswordErrorMessage
  196. @brief This is the error message the server will respond with if the user entered a wrong
  197. password.
  198. */
  199. static NSString *const kWrongPasswordErrorMessage = @"INVALID_PASSWORD";
  200. /** @var kCredentialTooOldErrorMessage
  201. @brief This is the error message the server responds with if account change is attempted 5
  202. minutes after signing in.
  203. */
  204. static NSString *const kCredentialTooOldErrorMessage = @"CREDENTIAL_TOO_OLD_LOGIN_AGAIN";
  205. /** @var kFederatedUserIDAlreadyLinkedMessage
  206. @brief This is the error message the server will respond with if the federated user ID has been
  207. already linked with another account.
  208. */
  209. static NSString *const kFederatedUserIDAlreadyLinkedMessage = @"FEDERATED_USER_ID_ALREADY_LINKED";
  210. /** @var kInvalidUserTokenErrorMessage
  211. @brief This is the error message the server responds with if user's saved auth credential is
  212. invalid, and the user needs to sign in again.
  213. */
  214. static NSString *const kInvalidUserTokenErrorMessage = @"INVALID_ID_TOKEN";
  215. /** @var kWeakPasswordErrorMessagePrefix
  216. @brief This is the prefix for the error message the server responds with if user's new password
  217. to be set is too weak.
  218. */
  219. static NSString *const kWeakPasswordErrorMessagePrefix = @"WEAK_PASSWORD";
  220. /** @var kExpiredActionCodeErrorMessage
  221. @brief This is the error message the server will respond with if the action code is expired.
  222. */
  223. static NSString *const kExpiredActionCodeErrorMessage = @"EXPIRED_OOB_CODE";
  224. /** @var kInvalidActionCodeErrorMessage
  225. @brief This is the error message the server will respond with if the action code is invalid.
  226. */
  227. static NSString *const kInvalidActionCodeErrorMessage = @"INVALID_OOB_CODE";
  228. /** @var kMissingEmailErrorMessage
  229. @brief This is the error message the server will respond with if the email address is missing
  230. during a "send password reset email" attempt.
  231. */
  232. static NSString *const kMissingEmailErrorMessage = @"MISSING_EMAIL";
  233. /** @var kInvalidSenderEmailErrorMessage
  234. @brief This is the error message the server will respond with if the sender email is invalid
  235. during a "send password reset email" attempt.
  236. */
  237. static NSString *const kInvalidSenderEmailErrorMessage = @"INVALID_SENDER";
  238. /** @var kInvalidMessagePayloadErrorMessage
  239. @brief This is the error message the server will respond with if there are invalid parameters in
  240. the payload during a "send password reset email" attempt.
  241. */
  242. static NSString *const kInvalidMessagePayloadErrorMessage = @"INVALID_MESSAGE_PAYLOAD";
  243. /** @var kInvalidRecipientEmailErrorMessage
  244. @brief This is the error message the server will respond with if the recipient email is invalid.
  245. */
  246. static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_EMAIL";
  247. /** @var kMissingIosBundleIDErrorMessage
  248. @brief This is the error message the server will respond with if iOS bundle ID is missing but
  249. the iOS App store ID is provided.
  250. */
  251. static NSString *const kMissingIosBundleIDErrorMessage = @"MISSING_IOS_BUNDLE_ID";
  252. /** @var kMissingAndroidPackageNameErrorMessage
  253. @brief This is the error message the server will respond with if Android Package Name is missing
  254. but the flag indicating the app should be installed is set to true.
  255. */
  256. static NSString *const kMissingAndroidPackageNameErrorMessage = @"MISSING_ANDROID_PACKAGE_NAME";
  257. /** @var kUnauthorizedDomainErrorMessage
  258. @brief This is the error message the server will respond with if the domain of the continue URL
  259. specified is not allowlisted in the Firebase console.
  260. */
  261. static NSString *const kUnauthorizedDomainErrorMessage = @"UNAUTHORIZED_DOMAIN";
  262. /** @var kInvalidProviderIDErrorMessage
  263. @brief This is the error message the server will respond with if the provider id given for the
  264. web operation is invalid.
  265. */
  266. static NSString *const kInvalidProviderIDErrorMessage = @"INVALID_PROVIDER_ID";
  267. /** @var kInvalidDynamicLinkDomainErrorMessage
  268. @brief This is the error message the server will respond with if the dynamic link domain
  269. provided in the request is invalid.
  270. */
  271. static NSString *const kInvalidDynamicLinkDomainErrorMessage = @"INVALID_DYNAMIC_LINK_DOMAIN";
  272. /** @var kInvalidContinueURIErrorMessage
  273. @brief This is the error message the server will respond with if the continue URL provided in
  274. the request is invalid.
  275. */
  276. static NSString *const kInvalidContinueURIErrorMessage = @"INVALID_CONTINUE_URI";
  277. /** @var kMissingContinueURIErrorMessage
  278. @brief This is the error message the server will respond with if there was no continue URI
  279. present in a request that required one.
  280. */
  281. static NSString *const kMissingContinueURIErrorMessage = @"MISSING_CONTINUE_URI";
  282. /** @var kInvalidPhoneNumberErrorMessage
  283. @brief This is the error message the server will respond with if an incorrectly formatted phone
  284. number is provided.
  285. */
  286. static NSString *const kInvalidPhoneNumberErrorMessage = @"INVALID_PHONE_NUMBER";
  287. /** @var kInvalidVerificationCodeErrorMessage
  288. @brief This is the error message the server will respond with if an invalid verification code is
  289. provided.
  290. */
  291. static NSString *const kInvalidVerificationCodeErrorMessage = @"INVALID_CODE";
  292. /** @var kInvalidSessionInfoErrorMessage
  293. @brief This is the error message the server will respond with if an invalid session info
  294. (verification ID) is provided.
  295. */
  296. static NSString *const kInvalidSessionInfoErrorMessage = @"INVALID_SESSION_INFO";
  297. /** @var kSessionExpiredErrorMessage
  298. @brief This is the error message the server will respond with if the SMS code has expired before
  299. it is used.
  300. */
  301. static NSString *const kSessionExpiredErrorMessage = @"SESSION_EXPIRED";
  302. /** @var kMissingOrInvalidNonceErrorMessage
  303. @brief This is the error message the server will respond with if the nonce is missing or
  304. invalid.
  305. */
  306. static NSString *const kMissingOrInvalidNonceErrorMessage = @"MISSING_OR_INVALID_NONCE";
  307. /** @var kMissingAppTokenErrorMessage
  308. @brief This is the error message the server will respond with if the APNS token is missing in a
  309. verifyClient request.
  310. */
  311. static NSString *const kMissingAppTokenErrorMessage = @"MISSING_IOS_APP_TOKEN";
  312. /** @var kMissingAppCredentialErrorMessage
  313. @brief This is the error message the server will respond with if the app token is missing in a
  314. sendVerificationCode request.
  315. */
  316. static NSString *const kMissingAppCredentialErrorMessage = @"MISSING_APP_CREDENTIAL";
  317. /** @var kInvalidAppCredentialErrorMessage
  318. @brief This is the error message the server will respond with if the app credential in a
  319. sendVerificationCode request is invalid.
  320. */
  321. static NSString *const kInvalidAppCredentialErrorMessage = @"INVALID_APP_CREDENTIAL";
  322. /** @var kQuoutaExceededErrorMessage
  323. @brief This is the error message the server will respond with if the quota for SMS text messages
  324. has been exceeded for the project.
  325. */
  326. static NSString *const kQuoutaExceededErrorMessage = @"QUOTA_EXCEEDED";
  327. /** @var kAppNotVerifiedErrorMessage
  328. @brief This is the error message the server will respond with if Firebase could not verify the
  329. app during a phone authentication flow.
  330. */
  331. static NSString *const kAppNotVerifiedErrorMessage = @"APP_NOT_VERIFIED";
  332. /** @var kMissingClientIdentifier
  333. @brief This is the error message the server will respond with if Firebase could not verify the
  334. app during a phone authentication flow when a real phone number is used and app verification
  335. is disabled for testing.
  336. */
  337. static NSString *const kMissingClientIdentifier = @"MISSING_CLIENT_IDENTIFIER";
  338. /** @var kCaptchaCheckFailedErrorMessage
  339. @brief This is the error message the server will respond with if the reCAPTCHA token provided is
  340. invalid.
  341. */
  342. static NSString *const kCaptchaCheckFailedErrorMessage = @"CAPTCHA_CHECK_FAILED";
  343. /** @var kTenantIDMismatch
  344. @brief This is the error message the server will respond with if the tenant id mismatches.
  345. */
  346. static NSString *const kTenantIDMismatch = @"TENANT_ID_MISMATCH";
  347. /** @var kUnsupportedTenantOperation
  348. @brief This is the error message the server will respond with if the operation does not support
  349. multi-tenant.
  350. */
  351. static NSString *const kUnsupportedTenantOperation = @"UNSUPPORTED_TENANT_OPERATION";
  352. /** @var kMissingMFAPendingCredentialErrorMessage
  353. @brief This is the error message the server will respond with if the MFA pending credential is
  354. missing.
  355. */
  356. static NSString *const kMissingMFAPendingCredentialErrorMessage = @"MISSING_MFA_PENDING_CREDENTIAL";
  357. /** @var kMissingMFAEnrollmentIDErrorMessage
  358. @brief This is the error message the server will respond with if the MFA enrollment ID is missing.
  359. */
  360. static NSString *const kMissingMFAEnrollmentIDErrorMessage = @"MISSING_MFA_ENROLLMENT_ID";
  361. /** @var kInvalidMFAPendingCredentialErrorMessage
  362. @brief This is the error message the server will respond with if the MFA pending credential is
  363. invalid.
  364. */
  365. static NSString *const kInvalidMFAPendingCredentialErrorMessage = @"INVALID_MFA_PENDING_CREDENTIAL";
  366. /** @var kMFAEnrollmentNotFoundErrorMessage
  367. @brief This is the error message the server will respond with if the MFA enrollment info is not
  368. found.
  369. */
  370. static NSString *const kMFAEnrollmentNotFoundErrorMessage = @"MFA_ENROLLMENT_NOT_FOUND";
  371. /** @var kAdminOnlyOperationErrorMessage
  372. @brief This is the error message the server will respond with if the operation is admin only.
  373. */
  374. static NSString *const kAdminOnlyOperationErrorMessage = @"ADMIN_ONLY_OPERATION";
  375. /** @var kUnverifiedEmailErrorMessage
  376. @brief This is the error message the server will respond with if the email is unverified.
  377. */
  378. static NSString *const kUnverifiedEmailErrorMessage = @"UNVERIFIED_EMAIL";
  379. /** @var kSecondFactorExistsErrorMessage
  380. @brief This is the error message the server will respond with if the second factor already exsists.
  381. */
  382. static NSString *const kSecondFactorExistsErrorMessage = @"SECOND_FACTOR_EXISTS";
  383. /** @var kSecondFactorLimitExceededErrorMessage
  384. @brief This is the error message the server will respond with if the number of second factor
  385. reaches the limit.
  386. */
  387. static NSString *const kSecondFactorLimitExceededErrorMessage = @"SECOND_FACTOR_LIMIT_EXCEEDED";
  388. /** @var kUnsupportedFirstFactorErrorMessage
  389. @brief This is the error message the server will respond with if the first factor doesn't support
  390. MFA.
  391. */
  392. static NSString *const kUnsupportedFirstFactorErrorMessage = @"UNSUPPORTED_FIRST_FACTOR";
  393. /** @var kBlockingCloudFunctionErrorResponse
  394. @brief This is the error message blocking Cloud Functions.
  395. */
  396. static NSString *const kBlockingCloudFunctionErrorResponse = @"BLOCKING_FUNCTION_ERROR_RESPONSE";
  397. /** @var kEmailChangeNeedsVerificationErrorMessage
  398. @brief This is the error message the server will respond with if changing an unverified email.
  399. */
  400. static NSString *const kEmailChangeNeedsVerificationErrorMessage =
  401. @"EMAIL_CHANGE_NEEDS_VERIFICATION";
  402. /** @var kInvalidPendingToken
  403. @brief Generic IDP error codes.
  404. */
  405. static NSString *const kInvalidPendingToken = @"INVALID_PENDING_TOKEN";
  406. /** @var gBackendImplementation
  407. @brief The singleton FIRAuthBackendImplementation instance to use.
  408. */
  409. static id<FIRAuthBackendImplementation> gBackendImplementation;
  410. /** @class FIRAuthBackendRPCImplementation
  411. @brief The default RPC-based backend implementation.
  412. */
  413. @interface FIRAuthBackendRPCImplementation : NSObject <FIRAuthBackendImplementation>
  414. /** @property RPCIssuer
  415. @brief An instance of FIRAuthBackendRPCIssuer for making RPC requests. Allows the RPC
  416. requests/responses to be easily faked.
  417. */
  418. @property(nonatomic, strong) id<FIRAuthBackendRPCIssuer> RPCIssuer;
  419. @end
  420. @implementation FIRAuthBackend
  421. + (id<FIRAuthBackendImplementation>)implementation {
  422. if (!gBackendImplementation) {
  423. gBackendImplementation = [[FIRAuthBackendRPCImplementation alloc] init];
  424. }
  425. return gBackendImplementation;
  426. }
  427. + (void)setBackendImplementation:(id<FIRAuthBackendImplementation>)backendImplementation {
  428. gBackendImplementation = backendImplementation;
  429. }
  430. + (void)setDefaultBackendImplementationWithRPCIssuer:
  431. (nullable id<FIRAuthBackendRPCIssuer>)RPCIssuer {
  432. FIRAuthBackendRPCImplementation *defaultImplementation =
  433. [[FIRAuthBackendRPCImplementation alloc] init];
  434. if (RPCIssuer) {
  435. defaultImplementation.RPCIssuer = RPCIssuer;
  436. }
  437. gBackendImplementation = defaultImplementation;
  438. }
  439. + (void)createAuthURI:(FIRCreateAuthURIRequest *)request
  440. callback:(FIRCreateAuthURIResponseCallback)callback {
  441. [[self implementation] createAuthURI:request callback:callback];
  442. }
  443. + (void)getAccountInfo:(FIRGetAccountInfoRequest *)request
  444. callback:(FIRGetAccountInfoResponseCallback)callback {
  445. [[self implementation] getAccountInfo:request callback:callback];
  446. }
  447. + (void)getProjectConfig:(FIRGetProjectConfigRequest *)request
  448. callback:(FIRGetProjectConfigResponseCallback)callback {
  449. [[self implementation] getProjectConfig:request callback:callback];
  450. }
  451. + (void)setAccountInfo:(FIRSetAccountInfoRequest *)request
  452. callback:(FIRSetAccountInfoResponseCallback)callback {
  453. [[self implementation] setAccountInfo:request callback:callback];
  454. }
  455. + (void)verifyAssertion:(FIRVerifyAssertionRequest *)request
  456. callback:(FIRVerifyAssertionResponseCallback)callback {
  457. [[self implementation] verifyAssertion:request callback:callback];
  458. }
  459. + (void)verifyCustomToken:(FIRVerifyCustomTokenRequest *)request
  460. callback:(FIRVerifyCustomTokenResponseCallback)callback {
  461. [[self implementation] verifyCustomToken:request callback:callback];
  462. }
  463. + (void)verifyPassword:(FIRVerifyPasswordRequest *)request
  464. callback:(FIRVerifyPasswordResponseCallback)callback {
  465. [[self implementation] verifyPassword:request callback:callback];
  466. }
  467. + (void)emailLinkSignin:(FIREmailLinkSignInRequest *)request
  468. callback:(FIREmailLinkSigninResponseCallback)callback {
  469. [[self implementation] emailLinkSignin:request callback:callback];
  470. }
  471. + (void)secureToken:(FIRSecureTokenRequest *)request
  472. callback:(FIRSecureTokenResponseCallback)callback {
  473. [[self implementation] secureToken:request callback:callback];
  474. }
  475. + (void)getOOBConfirmationCode:(FIRGetOOBConfirmationCodeRequest *)request
  476. callback:(FIRGetOOBConfirmationCodeResponseCallback)callback {
  477. [[self implementation] getOOBConfirmationCode:request callback:callback];
  478. }
  479. + (void)signUpNewUser:(FIRSignUpNewUserRequest *)request
  480. callback:(FIRSignupNewUserCallback)callback {
  481. [[self implementation] signUpNewUser:request callback:callback];
  482. }
  483. + (void)deleteAccount:(FIRDeleteAccountRequest *)request callback:(FIRDeleteCallBack)callback {
  484. [[self implementation] deleteAccount:request callback:callback];
  485. }
  486. + (void)signInWithGameCenter:(FIRSignInWithGameCenterRequest *)request
  487. callback:(FIRSignInWithGameCenterResponseCallback)callback {
  488. [[self implementation] signInWithGameCenter:request callback:callback];
  489. }
  490. #if TARGET_OS_IOS
  491. + (void)sendVerificationCode:(FIRSendVerificationCodeRequest *)request
  492. callback:(FIRSendVerificationCodeResponseCallback)callback {
  493. [[self implementation] sendVerificationCode:request callback:callback];
  494. }
  495. + (void)verifyPhoneNumber:(FIRVerifyPhoneNumberRequest *)request
  496. callback:(FIRVerifyPhoneNumberResponseCallback)callback {
  497. [[self implementation] verifyPhoneNumber:request callback:callback];
  498. }
  499. + (void)verifyClient:(id)request callback:(FIRVerifyClientResponseCallback)callback {
  500. [[self implementation] verifyClient:request callback:callback];
  501. }
  502. #endif
  503. + (void)resetPassword:(FIRResetPasswordRequest *)request
  504. callback:(FIRResetPasswordCallback)callback {
  505. [[self implementation] resetPassword:request callback:callback];
  506. }
  507. + (NSString *)authUserAgent {
  508. return [NSString stringWithFormat:@"FirebaseAuth.iOS/%@ %@", FIRFirebaseVersion(),
  509. GTMFetcherStandardUserAgentString(nil)];
  510. }
  511. + (NSMutableURLRequest *)requestWithURL:(NSURL *)URL
  512. contentType:(NSString *)contentType
  513. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  514. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
  515. [request setValue:contentType forHTTPHeaderField:@"Content-Type"];
  516. NSString *additionalFrameworkMarker =
  517. requestConfiguration.additionalFrameworkMarker ?: kFirebaseAuthCoreFrameworkMarker;
  518. NSString *clientVersion = [NSString
  519. stringWithFormat:@"iOS/FirebaseSDK/%@/%@", FIRFirebaseVersion(), additionalFrameworkMarker];
  520. [request setValue:clientVersion forHTTPHeaderField:kClientVersionHeader];
  521. NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
  522. [request setValue:bundleID forHTTPHeaderField:kIosBundleIdentifierHeader];
  523. NSString *appID = requestConfiguration.appID;
  524. [request setValue:appID forHTTPHeaderField:kFirebaseAppIDHeader];
  525. [request setValue:FIRHeaderValueFromHeartbeatsPayload(
  526. [requestConfiguration.heartbeatLogger flushHeartbeatsIntoPayload])
  527. forHTTPHeaderField:kFirebaseHeartbeatHeader];
  528. NSArray<NSString *> *preferredLocalizations = [NSBundle mainBundle].preferredLocalizations;
  529. if (preferredLocalizations.count) {
  530. NSString *acceptLanguage = preferredLocalizations.firstObject;
  531. [request setValue:acceptLanguage forHTTPHeaderField:@"Accept-Language"];
  532. }
  533. NSString *languageCode = requestConfiguration.languageCode;
  534. if (languageCode.length) {
  535. [request setValue:languageCode forHTTPHeaderField:kFirebaseLocalHeader];
  536. }
  537. return request;
  538. }
  539. @end
  540. @interface FIRAuthBackendRPCIssuerImplementation : NSObject <FIRAuthBackendRPCIssuer>
  541. @end
  542. @implementation FIRAuthBackendRPCIssuerImplementation {
  543. /** @var The session fetcher service.
  544. */
  545. GTMSessionFetcherService *_fetcherService;
  546. }
  547. - (instancetype)init {
  548. self = [super init];
  549. if (self) {
  550. _fetcherService = [[GTMSessionFetcherService alloc] init];
  551. _fetcherService.userAgent = [FIRAuthBackend authUserAgent];
  552. _fetcherService.callbackQueue = FIRAuthGlobalWorkQueue();
  553. // Avoid reusing the session to prevent
  554. // https://github.com/firebase/firebase-ios-sdk/issues/1261
  555. _fetcherService.reuseSession = NO;
  556. }
  557. return self;
  558. }
  559. - (void)asyncPostToURLWithRequestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
  560. URL:(NSURL *)URL
  561. body:(nullable NSData *)body
  562. contentType:(NSString *)contentType
  563. completionHandler:
  564. (void (^)(NSData *_Nullable, NSError *_Nullable))handler {
  565. NSMutableURLRequest *request = [FIRAuthBackend requestWithURL:URL
  566. contentType:contentType
  567. requestConfiguration:requestConfiguration];
  568. GTMSessionFetcher *fetcher = [_fetcherService fetcherWithRequest:request];
  569. NSString *emulatorHostAndPort = requestConfiguration.emulatorHostAndPort;
  570. if (emulatorHostAndPort) {
  571. fetcher.allowLocalhostRequest = YES;
  572. fetcher.allowedInsecureSchemes = @[ @"http" ];
  573. }
  574. fetcher.bodyData = body;
  575. [fetcher beginFetchWithCompletionHandler:handler];
  576. }
  577. @end
  578. @implementation FIRAuthBackendRPCImplementation
  579. - (instancetype)init {
  580. self = [super init];
  581. if (self) {
  582. _RPCIssuer = [[FIRAuthBackendRPCIssuerImplementation alloc] init];
  583. }
  584. return self;
  585. }
  586. - (void)createAuthURI:(FIRCreateAuthURIRequest *)request
  587. callback:(FIRCreateAuthURIResponseCallback)callback {
  588. FIRCreateAuthURIResponse *response = [[FIRCreateAuthURIResponse alloc] init];
  589. [self postWithRequest:request
  590. response:response
  591. callback:^(NSError *error) {
  592. if (error) {
  593. callback(nil, error);
  594. } else {
  595. callback(response, nil);
  596. }
  597. }];
  598. }
  599. - (void)getAccountInfo:(FIRGetAccountInfoRequest *)request
  600. callback:(FIRGetAccountInfoResponseCallback)callback {
  601. FIRGetAccountInfoResponse *response = [[FIRGetAccountInfoResponse alloc] init];
  602. [self postWithRequest:request
  603. response:response
  604. callback:^(NSError *error) {
  605. if (error) {
  606. callback(nil, error);
  607. } else {
  608. callback(response, nil);
  609. }
  610. }];
  611. }
  612. - (void)getProjectConfig:(FIRGetProjectConfigRequest *)request
  613. callback:(FIRGetProjectConfigResponseCallback)callback {
  614. FIRGetProjectConfigResponse *response = [[FIRGetProjectConfigResponse alloc] init];
  615. [self postWithRequest:request
  616. response:response
  617. callback:^(NSError *error) {
  618. if (error) {
  619. callback(nil, error);
  620. } else {
  621. callback(response, nil);
  622. }
  623. }];
  624. }
  625. - (void)setAccountInfo:(FIRSetAccountInfoRequest *)request
  626. callback:(FIRSetAccountInfoResponseCallback)callback {
  627. FIRSetAccountInfoResponse *response = [[FIRSetAccountInfoResponse alloc] init];
  628. [self postWithRequest:request
  629. response:response
  630. callback:^(NSError *error) {
  631. if (error) {
  632. callback(nil, error);
  633. } else {
  634. callback(response, nil);
  635. }
  636. }];
  637. }
  638. - (void)verifyAssertion:(FIRVerifyAssertionRequest *)request
  639. callback:(FIRVerifyAssertionResponseCallback)callback {
  640. FIRVerifyAssertionResponse *response = [[FIRVerifyAssertionResponse alloc] init];
  641. [self
  642. postWithRequest:request
  643. response:response
  644. callback:^(NSError *error) {
  645. if (error) {
  646. callback(nil, error);
  647. } else {
  648. if (!response.IDToken && response.MFAInfo) {
  649. #if TARGET_OS_IOS
  650. NSMutableArray<FIRMultiFactorInfo *> *multiFactorInfo = [NSMutableArray array];
  651. for (FIRAuthProtoMFAEnrollment *MFAEnrollment in response.MFAInfo) {
  652. FIRPhoneMultiFactorInfo *info =
  653. [[FIRPhoneMultiFactorInfo alloc] initWithProto:MFAEnrollment];
  654. [multiFactorInfo addObject:info];
  655. }
  656. NSError *multiFactorRequiredError = [FIRAuthErrorUtils
  657. secondFactorRequiredErrorWithPendingCredential:response.MFAPendingCredential
  658. hints:multiFactorInfo
  659. auth:request.requestConfiguration
  660. .auth];
  661. callback(nil, multiFactorRequiredError);
  662. #endif
  663. } else {
  664. callback(response, nil);
  665. }
  666. }
  667. }];
  668. }
  669. - (void)verifyCustomToken:(FIRVerifyCustomTokenRequest *)request
  670. callback:(FIRVerifyCustomTokenResponseCallback)callback {
  671. FIRVerifyCustomTokenResponse *response = [[FIRVerifyCustomTokenResponse alloc] init];
  672. [self postWithRequest:request
  673. response:response
  674. callback:^(NSError *error) {
  675. if (error) {
  676. callback(nil, error);
  677. } else {
  678. callback(response, nil);
  679. }
  680. }];
  681. }
  682. - (void)verifyPassword:(FIRVerifyPasswordRequest *)request
  683. callback:(FIRVerifyPasswordResponseCallback)callback {
  684. FIRVerifyPasswordResponse *response = [[FIRVerifyPasswordResponse alloc] init];
  685. [self
  686. postWithRequest:request
  687. response:response
  688. callback:^(NSError *error) {
  689. if (error) {
  690. callback(nil, error);
  691. } else {
  692. if (!response.IDToken && response.MFAInfo) {
  693. #if TARGET_OS_IOS
  694. NSMutableArray<FIRMultiFactorInfo *> *multiFactorInfo = [NSMutableArray array];
  695. for (FIRAuthProtoMFAEnrollment *MFAEnrollment in response.MFAInfo) {
  696. FIRPhoneMultiFactorInfo *info =
  697. [[FIRPhoneMultiFactorInfo alloc] initWithProto:MFAEnrollment];
  698. [multiFactorInfo addObject:info];
  699. }
  700. NSError *multiFactorRequiredError = [FIRAuthErrorUtils
  701. secondFactorRequiredErrorWithPendingCredential:response.MFAPendingCredential
  702. hints:multiFactorInfo
  703. auth:request.requestConfiguration
  704. .auth];
  705. callback(nil, multiFactorRequiredError);
  706. #endif
  707. } else {
  708. callback(response, nil);
  709. }
  710. }
  711. }];
  712. }
  713. - (void)emailLinkSignin:(FIREmailLinkSignInRequest *)request
  714. callback:(FIREmailLinkSigninResponseCallback)callback {
  715. FIREmailLinkSignInResponse *response = [[FIREmailLinkSignInResponse alloc] init];
  716. [self
  717. postWithRequest:request
  718. response:response
  719. callback:^(NSError *error) {
  720. if (error) {
  721. callback(nil, error);
  722. } else {
  723. if (!response.IDToken && response.MFAInfo) {
  724. #if TARGET_OS_IOS
  725. NSMutableArray<FIRMultiFactorInfo *> *multiFactorInfo = [NSMutableArray array];
  726. for (FIRAuthProtoMFAEnrollment *MFAEnrollment in response.MFAInfo) {
  727. FIRPhoneMultiFactorInfo *info =
  728. [[FIRPhoneMultiFactorInfo alloc] initWithProto:MFAEnrollment];
  729. [multiFactorInfo addObject:info];
  730. }
  731. NSError *multiFactorRequiredError = [FIRAuthErrorUtils
  732. secondFactorRequiredErrorWithPendingCredential:response.MFAPendingCredential
  733. hints:multiFactorInfo
  734. auth:request.requestConfiguration
  735. .auth];
  736. callback(nil, multiFactorRequiredError);
  737. #endif
  738. } else {
  739. callback(response, nil);
  740. }
  741. }
  742. }];
  743. }
  744. - (void)secureToken:(FIRSecureTokenRequest *)request
  745. callback:(FIRSecureTokenResponseCallback)callback {
  746. FIRSecureTokenResponse *response = [[FIRSecureTokenResponse alloc] init];
  747. [self postWithRequest:request
  748. response:response
  749. callback:^(NSError *error) {
  750. if (error) {
  751. callback(nil, error);
  752. } else {
  753. callback(response, nil);
  754. }
  755. }];
  756. }
  757. - (void)getOOBConfirmationCode:(FIRGetOOBConfirmationCodeRequest *)request
  758. callback:(FIRGetOOBConfirmationCodeResponseCallback)callback {
  759. FIRGetOOBConfirmationCodeResponse *response = [[FIRGetOOBConfirmationCodeResponse alloc] init];
  760. [self postWithRequest:request
  761. response:response
  762. callback:^(NSError *error) {
  763. if (error) {
  764. callback(nil, error);
  765. } else {
  766. callback(response, nil);
  767. }
  768. }];
  769. }
  770. - (void)signUpNewUser:(FIRSignUpNewUserRequest *)request
  771. callback:(FIRSignupNewUserCallback)callback {
  772. FIRSignUpNewUserResponse *response = [[FIRSignUpNewUserResponse alloc] init];
  773. [self postWithRequest:request
  774. response:response
  775. callback:^(NSError *error) {
  776. if (error) {
  777. callback(nil, error);
  778. } else {
  779. callback(response, nil);
  780. }
  781. }];
  782. }
  783. - (void)deleteAccount:(FIRDeleteAccountRequest *)request callback:(FIRDeleteCallBack)callback {
  784. FIRDeleteAccountResponse *response = [[FIRDeleteAccountResponse alloc] init];
  785. [self postWithRequest:request response:response callback:callback];
  786. }
  787. #if TARGET_OS_IOS
  788. - (void)sendVerificationCode:(FIRSendVerificationCodeRequest *)request
  789. callback:(FIRSendVerificationCodeResponseCallback)callback {
  790. FIRSendVerificationCodeResponse *response = [[FIRSendVerificationCodeResponse alloc] init];
  791. [self postWithRequest:request
  792. response:response
  793. callback:^(NSError *error) {
  794. if (error) {
  795. callback(nil, error);
  796. } else {
  797. callback(response, error);
  798. }
  799. }];
  800. }
  801. - (void)verifyPhoneNumber:(FIRVerifyPhoneNumberRequest *)request
  802. callback:(FIRVerifyPhoneNumberResponseCallback)callback {
  803. FIRVerifyPhoneNumberResponse *response = [[FIRVerifyPhoneNumberResponse alloc] init];
  804. [self
  805. postWithRequest:request
  806. response:response
  807. callback:^(NSError *error) {
  808. if (error) {
  809. callback(nil, error);
  810. return;
  811. }
  812. // Check whether or not the successful response is actually the special case phone
  813. // auth flow that returns a temporary proof and phone number.
  814. if (response.phoneNumber.length && response.temporaryProof.length) {
  815. FIRPhoneAuthCredential *credential =
  816. [[FIRPhoneAuthCredential alloc] initWithTemporaryProof:response.temporaryProof
  817. phoneNumber:response.phoneNumber
  818. providerID:FIRPhoneAuthProviderID];
  819. callback(nil, [FIRAuthErrorUtils credentialAlreadyInUseErrorWithMessage:nil
  820. credential:credential
  821. email:nil]);
  822. return;
  823. }
  824. callback(response, nil);
  825. }];
  826. }
  827. - (void)verifyClient:(id)request callback:(FIRVerifyClientResponseCallback)callback {
  828. FIRVerifyClientResponse *response = [[FIRVerifyClientResponse alloc] init];
  829. [self postWithRequest:request
  830. response:response
  831. callback:^(NSError *error) {
  832. if (error) {
  833. callback(nil, error);
  834. return;
  835. }
  836. callback(response, nil);
  837. }];
  838. }
  839. #endif
  840. - (void)resetPassword:(FIRResetPasswordRequest *)request
  841. callback:(FIRResetPasswordCallback)callback {
  842. FIRResetPasswordResponse *response = [[FIRResetPasswordResponse alloc] init];
  843. [self postWithRequest:request
  844. response:response
  845. callback:^(NSError *error) {
  846. if (error) {
  847. callback(nil, error);
  848. return;
  849. }
  850. callback(response, nil);
  851. }];
  852. }
  853. - (void)signInWithGameCenter:(FIRSignInWithGameCenterRequest *)request
  854. callback:(FIRSignInWithGameCenterResponseCallback)callback {
  855. FIRSignInWithGameCenterResponse *response = [[FIRSignInWithGameCenterResponse alloc] init];
  856. [self postWithRequest:request
  857. response:response
  858. callback:^(NSError *error) {
  859. if (error) {
  860. if (callback) {
  861. callback(nil, error);
  862. }
  863. } else {
  864. if (callback) {
  865. callback(response, nil);
  866. }
  867. }
  868. }];
  869. }
  870. #pragma mark - Generic RPC handling methods
  871. /** @fn postWithRequest:response:callback:
  872. @brief Calls the RPC using HTTP POST.
  873. @remarks Possible error responses:
  874. @see FIRAuthInternalErrorCodeRPCRequestEncodingError
  875. @see FIRAuthInternalErrorCodeJSONSerializationError
  876. @see FIRAuthInternalErrorCodeNetworkError
  877. @see FIRAuthInternalErrorCodeUnexpectedErrorResponse
  878. @see FIRAuthInternalErrorCodeUnexpectedResponse
  879. @see FIRAuthInternalErrorCodeRPCResponseDecodingError
  880. @param request The request.
  881. @param response The empty response to be filled.
  882. @param callback The callback for both success and failure.
  883. */
  884. - (void)postWithRequest:(id<FIRAuthRPCRequest>)request
  885. response:(id<FIRAuthRPCResponse>)response
  886. callback:(void (^)(NSError *_Nullable error))callback {
  887. NSError *error;
  888. NSData *bodyData;
  889. if ([request containsPostBody]) {
  890. id postBody = [request unencodedHTTPRequestBodyWithError:&error];
  891. if (!postBody) {
  892. callback([FIRAuthErrorUtils RPCRequestEncodingErrorWithUnderlyingError:error]);
  893. return;
  894. }
  895. NSJSONWritingOptions JSONWritingOptions = 0;
  896. #if DEBUG
  897. JSONWritingOptions |= NSJSONWritingPrettyPrinted;
  898. #endif
  899. if ([NSJSONSerialization isValidJSONObject:postBody]) {
  900. bodyData = [NSJSONSerialization dataWithJSONObject:postBody
  901. options:JSONWritingOptions
  902. error:&error];
  903. if (!bodyData) {
  904. // This is an untested case. This happens exclusively when there is an error in the
  905. // framework implementation of dataWithJSONObject:options:error:. This shouldn't normally
  906. // occur as isValidJSONObject: should return NO in any case we should encounter an error.
  907. error = [FIRAuthErrorUtils JSONSerializationErrorWithUnderlyingError:error];
  908. }
  909. } else {
  910. error = [FIRAuthErrorUtils JSONSerializationErrorForUnencodableType];
  911. }
  912. if (!bodyData) {
  913. callback(error);
  914. return;
  915. }
  916. }
  917. [_RPCIssuer
  918. asyncPostToURLWithRequestConfiguration:[request requestConfiguration]
  919. URL:[request requestURL]
  920. body:bodyData
  921. contentType:kJSONContentType
  922. completionHandler:^(NSData *data, NSError *error) {
  923. // If there is an error with no body data at all, then this must be a
  924. // network error.
  925. if (error && !data) {
  926. callback([FIRAuthErrorUtils networkErrorWithUnderlyingError:error]);
  927. return;
  928. }
  929. // Try to decode the HTTP response data which may contain either a
  930. // successful response or error message.
  931. NSError *jsonError;
  932. NSDictionary *dictionary =
  933. [NSJSONSerialization JSONObjectWithData:data
  934. options:NSJSONReadingMutableLeaves
  935. error:&jsonError];
  936. if (!dictionary) {
  937. if (error) {
  938. // We have an error, but we couldn't decode the body, so we have no
  939. // additional information other than the raw response and the
  940. // original NSError (the jsonError is infered by the error code
  941. // (FIRAuthErrorCodeUnexpectedHTTPResponse, and is irrelevant.)
  942. callback([FIRAuthErrorUtils
  943. unexpectedErrorResponseWithData:data
  944. underlyingError:error]);
  945. } else {
  946. // This is supposed to be a "successful" response, but we couldn't
  947. // deserialize the body.
  948. callback([FIRAuthErrorUtils unexpectedResponseWithData:data
  949. underlyingError:jsonError]);
  950. }
  951. return;
  952. }
  953. if (![dictionary isKindOfClass:[NSDictionary class]]) {
  954. if (error) {
  955. callback([FIRAuthErrorUtils
  956. unexpectedErrorResponseWithDeserializedResponse:dictionary
  957. underlyingError:error]);
  958. } else {
  959. callback([FIRAuthErrorUtils
  960. unexpectedResponseWithDeserializedResponse:dictionary]);
  961. }
  962. return;
  963. }
  964. // At this point we either have an error with successfully decoded
  965. // details in the body, or we have a response which must pass further
  966. // validation before we know it's truly successful. We deal with the
  967. // case where we have an error with successfully decoded error details
  968. // first:
  969. if (error) {
  970. NSDictionary *errorDictionary = dictionary[kErrorKey];
  971. if ([errorDictionary isKindOfClass:[NSDictionary class]]) {
  972. id<NSObject> errorMessage = errorDictionary[kErrorMessageKey];
  973. if ([errorMessage isKindOfClass:[NSString class]]) {
  974. NSString *errorMessageString = (NSString *)errorMessage;
  975. // Contruct client error.
  976. NSError *clientError = [[self class]
  977. clientErrorWithServerErrorMessage:errorMessageString
  978. errorDictionary:errorDictionary
  979. response:response];
  980. if (clientError) {
  981. callback(clientError);
  982. return;
  983. }
  984. }
  985. // Not a message we know, return the message directly.
  986. if (errorMessage) {
  987. NSError *unexpecterErrorResponse = [FIRAuthErrorUtils
  988. unexpectedErrorResponseWithDeserializedResponse:
  989. errorDictionary
  990. underlyingError:error];
  991. callback(unexpecterErrorResponse);
  992. return;
  993. }
  994. }
  995. // No error message at all, return the decoded response.
  996. callback([FIRAuthErrorUtils
  997. unexpectedErrorResponseWithDeserializedResponse:dictionary
  998. underlyingError:error]);
  999. return;
  1000. }
  1001. // Finally, we try to populate the response object with the JSON
  1002. // values.
  1003. if (![response setWithDictionary:dictionary error:&error]) {
  1004. callback([FIRAuthErrorUtils
  1005. RPCResponseDecodingErrorWithDeserializedResponse:dictionary
  1006. underlyingError:error]);
  1007. return;
  1008. }
  1009. // In case returnIDPCredential of a verifyAssertion request is set to
  1010. // @YES, the server may return a 200 with a response that may contain a
  1011. // server error.
  1012. if ([request isKindOfClass:[FIRVerifyAssertionRequest class]]) {
  1013. FIRVerifyAssertionRequest *verifyAssertionRequest =
  1014. (FIRVerifyAssertionRequest *)request;
  1015. if (verifyAssertionRequest.returnIDPCredential) {
  1016. NSString *errorMessage =
  1017. dictionary[kReturnIDPCredentialErrorMessageKey];
  1018. if ([errorMessage isKindOfClass:[NSString class]]) {
  1019. NSString *errorString = (NSString *)errorMessage;
  1020. NSError *clientError =
  1021. [[self class] clientErrorWithServerErrorMessage:errorString
  1022. errorDictionary:@{}
  1023. response:response];
  1024. if (clientError) {
  1025. callback(clientError);
  1026. return;
  1027. }
  1028. }
  1029. }
  1030. }
  1031. // Success! The response object originally passed in can be used by the
  1032. // caller.
  1033. callback(nil);
  1034. }];
  1035. }
  1036. /** @fn clientErrorWithServerErrorMessage:errorDictionary:
  1037. @brief Translates known server errors to client errors.
  1038. @param serverErrorMessage The error message from the server.
  1039. @param errorDictionary The error part of the response from the server.
  1040. @param response The response from the server RPC.
  1041. @return A client error, if any.
  1042. */
  1043. + (nullable NSError *)clientErrorWithServerErrorMessage:(NSString *)serverErrorMessage
  1044. errorDictionary:(NSDictionary *)errorDictionary
  1045. response:(id<FIRAuthRPCResponse>)response {
  1046. NSString *shortErrorMessage = serverErrorMessage;
  1047. NSString *serverDetailErrorMessage;
  1048. NSRange colonRange = [serverErrorMessage rangeOfString:@":"];
  1049. if (colonRange.location != NSNotFound) {
  1050. shortErrorMessage = [serverErrorMessage substringToIndex:colonRange.location];
  1051. shortErrorMessage =
  1052. [shortErrorMessage stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  1053. serverDetailErrorMessage = [serverErrorMessage substringFromIndex:colonRange.location + 1];
  1054. serverDetailErrorMessage = [serverDetailErrorMessage
  1055. stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  1056. }
  1057. // Delegate the responsibility for constructing the client error to the response object,
  1058. // if possible.
  1059. SEL clientErrorWithServerErrorMessageSelector = @selector(clientErrorWithShortErrorMessage:
  1060. detailErrorMessage:);
  1061. if ([response respondsToSelector:clientErrorWithServerErrorMessageSelector]) {
  1062. NSError *error = [response clientErrorWithShortErrorMessage:shortErrorMessage
  1063. detailErrorMessage:serverDetailErrorMessage];
  1064. if (error) {
  1065. return error;
  1066. }
  1067. }
  1068. if ([shortErrorMessage isEqualToString:kUserNotFoundErrorMessage]) {
  1069. return [FIRAuthErrorUtils userNotFoundErrorWithMessage:serverDetailErrorMessage];
  1070. }
  1071. if ([shortErrorMessage isEqualToString:kUserDeletedErrorMessage]) {
  1072. return [FIRAuthErrorUtils userNotFoundErrorWithMessage:serverDetailErrorMessage];
  1073. }
  1074. if ([shortErrorMessage isEqualToString:kInvalidLocalIDErrorMessage]) {
  1075. // This case shouldn't be necessary but it is for now: b/27908364 .
  1076. return [FIRAuthErrorUtils userNotFoundErrorWithMessage:serverDetailErrorMessage];
  1077. }
  1078. if ([shortErrorMessage isEqualToString:kUserTokenExpiredErrorMessage]) {
  1079. return [FIRAuthErrorUtils userTokenExpiredErrorWithMessage:serverDetailErrorMessage];
  1080. }
  1081. if ([shortErrorMessage isEqualToString:kTooManyRequestsErrorMessage]) {
  1082. return [FIRAuthErrorUtils tooManyRequestsErrorWithMessage:serverDetailErrorMessage];
  1083. }
  1084. if ([shortErrorMessage isEqualToString:kInvalidCustomTokenErrorMessage]) {
  1085. return [FIRAuthErrorUtils invalidCustomTokenErrorWithMessage:serverDetailErrorMessage];
  1086. }
  1087. if ([shortErrorMessage isEqualToString:kCustomTokenMismatch]) {
  1088. return [FIRAuthErrorUtils customTokenMistmatchErrorWithMessage:serverDetailErrorMessage];
  1089. }
  1090. if ([shortErrorMessage isEqualToString:kInvalidCredentialErrorMessage] ||
  1091. [shortErrorMessage isEqualToString:kInvalidPendingToken]) {
  1092. return [FIRAuthErrorUtils invalidCredentialErrorWithMessage:serverDetailErrorMessage];
  1093. }
  1094. if ([shortErrorMessage isEqualToString:kUserDisabledErrorMessage]) {
  1095. return [FIRAuthErrorUtils userDisabledErrorWithMessage:serverDetailErrorMessage];
  1096. }
  1097. if ([shortErrorMessage isEqualToString:kOperationNotAllowedErrorMessage]) {
  1098. return [FIRAuthErrorUtils operationNotAllowedErrorWithMessage:serverDetailErrorMessage];
  1099. }
  1100. if ([shortErrorMessage isEqualToString:kPasswordLoginDisabledErrorMessage]) {
  1101. return [FIRAuthErrorUtils operationNotAllowedErrorWithMessage:serverDetailErrorMessage];
  1102. }
  1103. if ([shortErrorMessage isEqualToString:kEmailAlreadyInUseErrorMessage]) {
  1104. return [FIRAuthErrorUtils emailAlreadyInUseErrorWithEmail:nil];
  1105. }
  1106. if ([shortErrorMessage isEqualToString:kInvalidEmailErrorMessage]) {
  1107. return [FIRAuthErrorUtils invalidEmailErrorWithMessage:serverDetailErrorMessage];
  1108. }
  1109. // "INVALID_IDENTIFIER" can be returned by createAuthURI RPC. Considering email addresses are
  1110. // currently the only identifiers, we surface the FIRAuthErrorCodeInvalidEmail error code in this
  1111. // case.
  1112. if ([shortErrorMessage isEqualToString:kInvalidIdentifierErrorMessage]) {
  1113. return [FIRAuthErrorUtils invalidEmailErrorWithMessage:serverDetailErrorMessage];
  1114. }
  1115. if ([shortErrorMessage isEqualToString:kWrongPasswordErrorMessage]) {
  1116. return [FIRAuthErrorUtils wrongPasswordErrorWithMessage:serverDetailErrorMessage];
  1117. }
  1118. if ([shortErrorMessage isEqualToString:kCredentialTooOldErrorMessage]) {
  1119. return [FIRAuthErrorUtils requiresRecentLoginErrorWithMessage:serverDetailErrorMessage];
  1120. }
  1121. if ([shortErrorMessage isEqualToString:kInvalidUserTokenErrorMessage]) {
  1122. return [FIRAuthErrorUtils invalidUserTokenErrorWithMessage:serverDetailErrorMessage];
  1123. }
  1124. if ([shortErrorMessage isEqualToString:kFederatedUserIDAlreadyLinkedMessage]) {
  1125. FIROAuthCredential *credential;
  1126. NSString *email;
  1127. if ([response isKindOfClass:[FIRVerifyAssertionResponse class]]) {
  1128. FIRVerifyAssertionResponse *verifyAssertion = (FIRVerifyAssertionResponse *)response;
  1129. credential = [[FIROAuthCredential alloc] initWithVerifyAssertionResponse:verifyAssertion];
  1130. email = verifyAssertion.email;
  1131. }
  1132. return [FIRAuthErrorUtils credentialAlreadyInUseErrorWithMessage:serverDetailErrorMessage
  1133. credential:credential
  1134. email:email];
  1135. }
  1136. if ([shortErrorMessage isEqualToString:kWeakPasswordErrorMessagePrefix]) {
  1137. return [FIRAuthErrorUtils weakPasswordErrorWithServerResponseReason:serverDetailErrorMessage];
  1138. }
  1139. if ([shortErrorMessage isEqualToString:kExpiredActionCodeErrorMessage]) {
  1140. return [FIRAuthErrorUtils expiredActionCodeErrorWithMessage:serverDetailErrorMessage];
  1141. }
  1142. if ([shortErrorMessage isEqualToString:kInvalidActionCodeErrorMessage]) {
  1143. return [FIRAuthErrorUtils invalidActionCodeErrorWithMessage:serverDetailErrorMessage];
  1144. }
  1145. if ([shortErrorMessage isEqualToString:kMissingEmailErrorMessage]) {
  1146. return [FIRAuthErrorUtils missingEmailErrorWithMessage:serverDetailErrorMessage];
  1147. }
  1148. if ([shortErrorMessage isEqualToString:kInvalidSenderEmailErrorMessage]) {
  1149. return [FIRAuthErrorUtils invalidSenderErrorWithMessage:serverDetailErrorMessage];
  1150. }
  1151. if ([shortErrorMessage isEqualToString:kInvalidMessagePayloadErrorMessage]) {
  1152. return [FIRAuthErrorUtils invalidMessagePayloadErrorWithMessage:serverDetailErrorMessage];
  1153. }
  1154. if ([shortErrorMessage isEqualToString:kInvalidRecipientEmailErrorMessage]) {
  1155. return [FIRAuthErrorUtils invalidRecipientEmailErrorWithMessage:serverDetailErrorMessage];
  1156. }
  1157. if ([shortErrorMessage isEqualToString:kMissingIosBundleIDErrorMessage]) {
  1158. return [FIRAuthErrorUtils missingIosBundleIDErrorWithMessage:serverDetailErrorMessage];
  1159. }
  1160. if ([shortErrorMessage isEqualToString:kMissingAndroidPackageNameErrorMessage]) {
  1161. return [FIRAuthErrorUtils missingAndroidPackageNameErrorWithMessage:serverDetailErrorMessage];
  1162. }
  1163. if ([shortErrorMessage isEqualToString:kUnauthorizedDomainErrorMessage]) {
  1164. return [FIRAuthErrorUtils unauthorizedDomainErrorWithMessage:serverDetailErrorMessage];
  1165. }
  1166. if ([shortErrorMessage isEqualToString:kInvalidContinueURIErrorMessage]) {
  1167. return [FIRAuthErrorUtils invalidContinueURIErrorWithMessage:serverDetailErrorMessage];
  1168. }
  1169. if ([shortErrorMessage isEqualToString:kInvalidProviderIDErrorMessage]) {
  1170. return [FIRAuthErrorUtils invalidProviderIDErrorWithMessage:serverDetailErrorMessage];
  1171. }
  1172. if ([shortErrorMessage isEqualToString:kInvalidDynamicLinkDomainErrorMessage]) {
  1173. return [FIRAuthErrorUtils invalidDynamicLinkDomainErrorWithMessage:serverDetailErrorMessage];
  1174. }
  1175. if ([shortErrorMessage isEqualToString:kMissingContinueURIErrorMessage]) {
  1176. return [FIRAuthErrorUtils missingContinueURIErrorWithMessage:serverDetailErrorMessage];
  1177. }
  1178. if ([shortErrorMessage isEqualToString:kInvalidPhoneNumberErrorMessage]) {
  1179. return [FIRAuthErrorUtils invalidPhoneNumberErrorWithMessage:serverDetailErrorMessage];
  1180. }
  1181. if ([shortErrorMessage isEqualToString:kInvalidSessionInfoErrorMessage]) {
  1182. return [FIRAuthErrorUtils invalidVerificationIDErrorWithMessage:serverDetailErrorMessage];
  1183. }
  1184. if ([shortErrorMessage isEqualToString:kInvalidVerificationCodeErrorMessage]) {
  1185. return [FIRAuthErrorUtils invalidVerificationCodeErrorWithMessage:serverDetailErrorMessage];
  1186. }
  1187. if ([shortErrorMessage isEqualToString:kSessionExpiredErrorMessage]) {
  1188. return [FIRAuthErrorUtils sessionExpiredErrorWithMessage:serverDetailErrorMessage];
  1189. }
  1190. if ([shortErrorMessage isEqualToString:kMissingAppTokenErrorMessage]) {
  1191. return [FIRAuthErrorUtils missingAppTokenErrorWithUnderlyingError:nil];
  1192. }
  1193. if ([shortErrorMessage isEqualToString:kMissingAppCredentialErrorMessage]) {
  1194. return [FIRAuthErrorUtils missingAppCredentialWithMessage:serverDetailErrorMessage];
  1195. }
  1196. if ([shortErrorMessage isEqualToString:kInvalidAppCredentialErrorMessage]) {
  1197. return [FIRAuthErrorUtils invalidAppCredentialWithMessage:serverDetailErrorMessage];
  1198. }
  1199. if ([shortErrorMessage isEqualToString:kQuoutaExceededErrorMessage]) {
  1200. return [FIRAuthErrorUtils quotaExceededErrorWithMessage:serverErrorMessage];
  1201. }
  1202. if ([shortErrorMessage isEqualToString:kAppNotVerifiedErrorMessage]) {
  1203. return [FIRAuthErrorUtils appNotVerifiedErrorWithMessage:serverErrorMessage];
  1204. }
  1205. if ([shortErrorMessage isEqualToString:kMissingClientIdentifier]) {
  1206. return [FIRAuthErrorUtils missingClientIdentifierErrorWithMessage:serverErrorMessage];
  1207. }
  1208. if ([shortErrorMessage isEqualToString:kCaptchaCheckFailedErrorMessage]) {
  1209. return [FIRAuthErrorUtils captchaCheckFailedErrorWithMessage:serverErrorMessage];
  1210. }
  1211. if ([shortErrorMessage isEqualToString:kMissingOrInvalidNonceErrorMessage]) {
  1212. return [FIRAuthErrorUtils missingOrInvalidNonceErrorWithMessage:serverDetailErrorMessage];
  1213. }
  1214. if ([shortErrorMessage isEqualToString:kMissingMFAPendingCredentialErrorMessage]) {
  1215. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeMissingMultiFactorSession
  1216. message:serverErrorMessage];
  1217. }
  1218. if ([shortErrorMessage isEqualToString:kMissingMFAEnrollmentIDErrorMessage]) {
  1219. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeMissingMultiFactorInfo
  1220. message:serverErrorMessage];
  1221. }
  1222. if ([shortErrorMessage isEqualToString:kInvalidMFAPendingCredentialErrorMessage]) {
  1223. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeInvalidMultiFactorSession
  1224. message:serverErrorMessage];
  1225. }
  1226. if ([shortErrorMessage isEqualToString:kMFAEnrollmentNotFoundErrorMessage]) {
  1227. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeMultiFactorInfoNotFound
  1228. message:serverErrorMessage];
  1229. }
  1230. if ([shortErrorMessage isEqualToString:kAdminOnlyOperationErrorMessage]) {
  1231. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeAdminRestrictedOperation
  1232. message:serverErrorMessage];
  1233. }
  1234. if ([shortErrorMessage isEqualToString:kUnverifiedEmailErrorMessage]) {
  1235. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeUnverifiedEmail
  1236. message:serverErrorMessage];
  1237. }
  1238. if ([shortErrorMessage isEqualToString:kSecondFactorExistsErrorMessage]) {
  1239. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeSecondFactorAlreadyEnrolled
  1240. message:serverErrorMessage];
  1241. }
  1242. if ([shortErrorMessage isEqualToString:kSecondFactorLimitExceededErrorMessage]) {
  1243. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeMaximumSecondFactorCountExceeded
  1244. message:serverErrorMessage];
  1245. }
  1246. if ([shortErrorMessage isEqualToString:kUnsupportedFirstFactorErrorMessage]) {
  1247. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeUnsupportedFirstFactor
  1248. message:serverErrorMessage];
  1249. }
  1250. if ([shortErrorMessage isEqualToString:kEmailChangeNeedsVerificationErrorMessage]) {
  1251. return [FIRAuthErrorUtils errorWithCode:FIRAuthInternalErrorCodeEmailChangeNeedsVerification
  1252. message:serverErrorMessage];
  1253. }
  1254. if ([shortErrorMessage isEqualToString:kTenantIDMismatch]) {
  1255. return [FIRAuthErrorUtils tenantIDMismatchError];
  1256. }
  1257. if ([shortErrorMessage isEqualToString:kUnsupportedTenantOperation]) {
  1258. return [FIRAuthErrorUtils unsupportedTenantOperationError];
  1259. }
  1260. if ([shortErrorMessage isEqualToString:kBlockingCloudFunctionErrorResponse]) {
  1261. return
  1262. [FIRAuthErrorUtils blockingCloudFunctionServerResponseWithMessage:serverDetailErrorMessage];
  1263. }
  1264. // In this case we handle an error that might be specified in the underlying errors dictionary,
  1265. // the error message in determined based on the @c reason key in the dictionary.
  1266. if (errorDictionary[kErrorsKey]) {
  1267. // Check for underlying error with reason = keyInvalid;
  1268. id underlyingErrors = errorDictionary[kErrorsKey];
  1269. if ([underlyingErrors isKindOfClass:[NSArray class]]) {
  1270. NSArray *underlyingErrorsArray = (NSArray *)underlyingErrors;
  1271. for (id underlyingError in underlyingErrorsArray) {
  1272. if ([underlyingError isKindOfClass:[NSDictionary class]]) {
  1273. NSDictionary *underlyingErrorDictionary = (NSDictionary *)underlyingError;
  1274. NSString *reason = underlyingErrorDictionary[kReasonKey];
  1275. if ([reason hasPrefix:kInvalidKeyReasonValue]) {
  1276. return [FIRAuthErrorUtils invalidAPIKeyError];
  1277. }
  1278. if ([reason isEqualToString:kAppNotAuthorizedReasonValue]) {
  1279. return [FIRAuthErrorUtils appNotAuthorizedError];
  1280. }
  1281. }
  1282. }
  1283. }
  1284. }
  1285. return nil;
  1286. }
  1287. @end
  1288. NS_ASSUME_NONNULL_END