FIRAuthErrorUtils.m 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  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/Utilities/FIRAuthErrorUtils.h"
  17. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuthCredential.h"
  18. #import "FirebaseAuth/Sources/MultiFactor/FIRMultiFactorResolver+Internal.h"
  19. NS_ASSUME_NONNULL_BEGIN
  20. NSString *const FIRAuthErrorDomain = @"FIRAuthErrorDomain";
  21. NSString *const FIRAuthInternalErrorDomain = @"FIRAuthInternalErrorDomain";
  22. NSString *const FIRAuthErrorUserInfoDeserializedResponseKey =
  23. @"FIRAuthErrorUserInfoDeserializedResponseKey";
  24. NSString *const FIRAuthErrorUserInfoDataKey = @"FIRAuthErrorUserInfoDataKey";
  25. NSString *const FIRAuthErrorUserInfoEmailKey = @"FIRAuthErrorUserInfoEmailKey";
  26. NSString *const FIRAuthErrorUserInfoUpdatedCredentialKey =
  27. @"FIRAuthErrorUserInfoUpdatedCredentialKey";
  28. NSString *const FIRAuthErrorUserInfoNameKey = @"FIRAuthErrorUserInfoNameKey";
  29. NSString *const FIRAuthErrorUserInfoMultiFactorResolverKey =
  30. @"FIRAuthErrorUserInfoMultiFactorResolverKey";
  31. /** @var kServerErrorDetailMarker
  32. @brief This marker indicates that the server error message contains a detail error message which
  33. should be used instead of the hardcoded client error message.
  34. */
  35. static NSString *const kServerErrorDetailMarker = @" : ";
  36. #pragma mark - URL response error codes
  37. /** @var kURLResponseErrorCodeInvalidClientID
  38. @brief Error code that indicates that the client ID provided was invalid.
  39. */
  40. static NSString *const kURLResponseErrorCodeInvalidClientID = @"auth/invalid-oauth-client-id";
  41. /** @var kURLResponseErrorCodeNetworkRequestFailed
  42. @brief Error code that indicates that a network request within the SFSafariViewController or
  43. WKWebView failed.
  44. */
  45. static NSString *const kURLResponseErrorCodeNetworkRequestFailed = @"auth/network-request-failed";
  46. /** @var kURLResponseErrorCodeInternalError
  47. @brief Error code that indicates that an internal error occurred within the
  48. SFSafariViewController or WKWebView failed.
  49. */
  50. static NSString *const kURLResponseErrorCodeInternalError = @"auth/internal-error";
  51. #pragma mark - Standard Error Messages
  52. /** @var kFIRAuthErrorMessageInvalidCustomToken
  53. @brief Message for @c FIRAuthErrorCodeInvalidCustomToken error code.
  54. */
  55. static NSString *const kFIRAuthErrorMessageInvalidCustomToken =
  56. @"The custom token format is "
  57. "incorrect. Please check the documentation.";
  58. /** @var kFIRAuthErrorMessageCustomTokenMismatch
  59. @brief Message for @c FIRAuthErrorCodeCustomTokenMismatch error code.
  60. */
  61. static NSString *const kFIRAuthErrorMessageCustomTokenMismatch = @"The custom token corresponds to "
  62. "a different audience or issuer.";
  63. /** @var kFIRAuthErrorMessageInvalidEmail
  64. @brief Message for @c FIRAuthErrorCodeInvalidEmail error code.
  65. */
  66. static NSString *const kFIRAuthErrorMessageInvalidEmail = @"The email address is badly formatted.";
  67. /** @var kFIRAuthErrorMessageInvalidCredential
  68. @brief Message for @c FIRAuthErrorCodeInvalidCredential error code.
  69. */
  70. static NSString *const kFIRAuthErrorMessageInvalidCredential = @"The supplied auth credential is "
  71. "malformed or has expired.";
  72. /** @var kFIRAuthErrorMessageUserDisabled
  73. @brief Message for @c FIRAuthErrorCodeUserDisabled error code.
  74. */
  75. static NSString *const kFIRAuthErrorMessageUserDisabled = @"The user account has been disabled by "
  76. "an administrator.";
  77. /** @var kFIRAuthErrorMessageEmailAlreadyInUse
  78. @brief Message for @c FIRAuthErrorCodeEmailAlreadyInUse error code.
  79. */
  80. static NSString *const kFIRAuthErrorMessageEmailAlreadyInUse = @"The email address is already in "
  81. "use by another account.";
  82. /** @var kFIRAuthErrorMessageWrongPassword
  83. @brief Message for @c FIRAuthErrorCodeWrongPassword error code.
  84. */
  85. static NSString *const kFIRAuthErrorMessageWrongPassword = @"The password is invalid or the user "
  86. "does not have a password.";
  87. /** @var kFIRAuthErrorMessageTooManyRequests
  88. @brief Message for @c FIRAuthErrorCodeTooManyRequests error code.
  89. */
  90. static NSString *const kFIRAuthErrorMessageTooManyRequests =
  91. @"We have blocked all requests from "
  92. "this device due to unusual activity. Try again later.";
  93. /** @var kFIRAuthErrorMessageAccountExistsWithDifferentCredential
  94. @brief Message for @c FIRAuthErrorCodeAccountExistsWithDifferentCredential error code.
  95. */
  96. static NSString *const kFIRAuthErrorMessageAccountExistsWithDifferentCredential =
  97. @"An account "
  98. "already exists with the same email address but different sign-in credentials. Sign in using "
  99. "a "
  100. "provider associated with this email address.";
  101. /** @var kFIRAuthErrorMessageRequiresRecentLogin
  102. @brief Message for @c FIRAuthErrorCodeRequiresRecentLogin error code.
  103. */
  104. static NSString *const kFIRAuthErrorMessageRequiresRecentLogin =
  105. @"This operation is sensitive and "
  106. "requires recent authentication. Log in again before retrying this request.";
  107. /** @var kFIRAuthErrorMessageProviderAlreadyLinked
  108. @brief Message for @c FIRAuthErrorCodeProviderAlreadyExists error code.
  109. */
  110. static NSString *const kFIRAuthErrorMessageProviderAlreadyLinked =
  111. @"[ERROR_PROVIDER_ALREADY_LINKED] - User can only be linked to one identity for the given "
  112. "provider.";
  113. /** @var kFIRAuthErrorMessageNoSuchProvider
  114. @brief Message for @c FIRAuthErrorCodeNoSuchProvider error code.
  115. */
  116. static NSString *const kFIRAuthErrorMessageNoSuchProvider = @"User was not linked to an account "
  117. "with the given provider.";
  118. /** @var kFIRAuthErrorMessageInvalidUserToken
  119. @brief Message for @c FIRAuthErrorCodeInvalidUserToken error code.
  120. */
  121. static NSString *const kFIRAuthErrorMessageInvalidUserToken =
  122. @"This user's credential isn't valid "
  123. "for this project. This can happen if the user's token has been tampered with, or if the user "
  124. "doesn’t belong to the project associated with the API key used in your request.";
  125. /** @var kFIRAuthErrorMessageNetworkError
  126. @brief Message for @c FIRAuthErrorCodeNetworkError error code.
  127. */
  128. static NSString *const kFIRAuthErrorMessageNetworkError =
  129. @"Network error (such as timeout, "
  130. "interrupted connection or unreachable host) has occurred.";
  131. /** @var kFIRAuthErrorMessageKeychainError
  132. @brief Message for @c FIRAuthErrorCodeKeychainError error code.
  133. */
  134. static NSString *const kFIRAuthErrorMessageKeychainError =
  135. @"An error occurred when accessing the "
  136. "keychain. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo dictionary "
  137. "will contain more information about the error encountered";
  138. /** @var kFIRAuthErrorMessageUserTokenExpired
  139. @brief Message for @c FIRAuthErrorCodeTokenExpired error code.
  140. */
  141. static NSString *const kFIRAuthErrorMessageUserTokenExpired =
  142. @"The user's credential is no longer "
  143. "valid. The user must sign in again.";
  144. /** @var kFIRAuthErrorMessageUserNotFound
  145. @brief Message for @c FIRAuthErrorCodeUserNotFound error code.
  146. */
  147. static NSString *const kFIRAuthErrorMessageUserNotFound =
  148. @"There is no user record corresponding "
  149. "to this identifier. The user may have been deleted.";
  150. /** @var kFIRAuthErrorMessageInvalidAPIKey
  151. @brief Message for @c FIRAuthErrorCodeInvalidAPIKey error code.
  152. @remarks This error is not thrown by the server.
  153. */
  154. static NSString *const kFIRAuthErrorMessageInvalidAPIKey = @"An invalid API Key was supplied in "
  155. "the request.";
  156. /** @var kFIRAuthErrorMessageUserMismatch.
  157. @brief Message for @c FIRAuthErrorCodeInvalidAPIKey error code.
  158. */
  159. static NSString *const FIRAuthErrorMessageUserMismatch =
  160. @"The supplied credentials do not "
  161. "correspond to the previously signed in user.";
  162. /** @var kFIRAuthErrorMessageCredentialAlreadyInUse
  163. @brief Message for @c FIRAuthErrorCodeCredentialAlreadyInUse error code.
  164. */
  165. static NSString *const kFIRAuthErrorMessageCredentialAlreadyInUse =
  166. @"This credential is already "
  167. "associated with a different user account.";
  168. /** @var kFIRAuthErrorMessageOperationNotAllowed
  169. @brief Message for @c FIRAuthErrorCodeOperationNotAllowed error code.
  170. */
  171. static NSString *const kFIRAuthErrorMessageOperationNotAllowed =
  172. @"The given sign-in provider is "
  173. "disabled for this Firebase project. Enable it in the Firebase console, under the sign-in "
  174. "method tab of the Auth section.";
  175. /** @var kFIRAuthErrorMessageWeakPassword
  176. @brief Message for @c FIRAuthErrorCodeWeakPassword error code.
  177. */
  178. static NSString *const kFIRAuthErrorMessageWeakPassword = @"The password must be 6 characters long "
  179. "or more.";
  180. /** @var kFIRAuthErrorMessageAppNotAuthorized
  181. @brief Message for @c FIRAuthErrorCodeAppNotAuthorized error code.
  182. */
  183. static NSString *const kFIRAuthErrorMessageAppNotAuthorized =
  184. @"This app is not authorized to use "
  185. "Firebase Authentication with the provided API key. Review your key configuration in the "
  186. "Google API console and ensure that it accepts requests from your app's bundle ID.";
  187. /** @var kFIRAuthErrorMessageExpiredActionCode
  188. @brief Message for @c FIRAuthErrorCodeExpiredActionCode error code.
  189. */
  190. static NSString *const kFIRAuthErrorMessageExpiredActionCode = @"The action code has expired.";
  191. /** @var kFIRAuthErrorMessageInvalidActionCode
  192. @brief Message for @c FIRAuthErrorCodeInvalidActionCode error code.
  193. */
  194. static NSString *const kFIRAuthErrorMessageInvalidActionCode =
  195. @"The action code is invalid. This "
  196. "can happen if the code is malformed, expired, or has already been used.";
  197. /** @var kFIRAuthErrorMessageInvalidMessagePayload
  198. @brief Message for @c FIRAuthErrorCodeInvalidMessagePayload error code.
  199. */
  200. static NSString *const kFIRAuthErrorMessageInvalidMessagePayload =
  201. @"The action code is invalid. "
  202. "This can happen if the code is malformed, expired, or has already been used.";
  203. /** @var kFIRAuthErrorMessageInvalidSender
  204. @brief Message for @c FIRAuthErrorCodeInvalidSender error code.
  205. */
  206. static NSString *const kFIRAuthErrorMessageInvalidSender =
  207. @"The email template corresponding to "
  208. "this action contains invalid characters in its message. Please fix by going to the Auth "
  209. "email "
  210. "templates section in the Firebase Console.";
  211. /** @var kFIRAuthErrorMessageInvalidRecipientEmail
  212. @brief Message for @c FIRAuthErrorCodeInvalidRecipient error code.
  213. */
  214. static NSString *const kFIRAuthErrorMessageInvalidRecipientEmail =
  215. @"The action code is invalid. "
  216. "This can happen if the code is malformed, expired, or has already been used.";
  217. /** @var kFIRAuthErrorMessageMissingIosBundleID
  218. @brief Message for @c FIRAuthErrorCodeMissingIosbundleID error code.
  219. */
  220. static NSString *const kFIRAuthErrorMessageMissingIosBundleID =
  221. @"An iOS Bundle ID must be provided if an App Store ID is provided.";
  222. /** @var kFIRAuthErrorMessageMissingAndroidPackageName
  223. @brief Message for @c FIRAuthErrorCodeMissingAndroidPackageName error code.
  224. */
  225. static NSString *const kFIRAuthErrorMessageMissingAndroidPackageName =
  226. @"An Android Package Name must be provided if the Android App is required to be installed.";
  227. /** @var kFIRAuthErrorMessageUnauthorizedDomain
  228. @brief Message for @c FIRAuthErrorCodeUnauthorizedDomain error code.
  229. */
  230. static NSString *const kFIRAuthErrorMessageUnauthorizedDomain =
  231. @"The domain of the continue URL "
  232. "is not allowlisted. Please allowlist the domain in the Firebase console.";
  233. /** @var kFIRAuthErrorMessageInvalidContinueURI
  234. @brief Message for @c FIRAuthErrorCodeInvalidContinueURI error code.
  235. */
  236. static NSString *const kFIRAuthErrorMessageInvalidContinueURI =
  237. @"The continue URL provided in the request is invalid.";
  238. /** @var kFIRAuthErrorMessageMissingEmail
  239. @brief Message for @c FIRAuthErrorCodeMissingEmail error code.
  240. */
  241. static NSString *const kFIRAuthErrorMessageMissingEmail = @"An email address must be provided.";
  242. /** @var kFIRAuthErrorMessageMissingContinueURI
  243. @brief Message for @c FIRAuthErrorCodeMissingContinueURI error code.
  244. */
  245. static NSString *const kFIRAuthErrorMessageMissingContinueURI =
  246. @"A continue URL must be provided in the request.";
  247. /** @var kFIRAuthErrorMessageMissingPhoneNumber
  248. @brief Message for @c FIRAuthErrorCodeMissingPhoneNumber error code.
  249. */
  250. static NSString *const kFIRAuthErrorMessageMissingPhoneNumber =
  251. @"To send verification codes, provide a phone number for the recipient.";
  252. /** @var kFIRAuthErrorMessageInvalidPhoneNumber
  253. @brief Message for @c FIRAuthErrorCodeInvalidPhoneNumber error code.
  254. */
  255. static NSString *const kFIRAuthErrorMessageInvalidPhoneNumber =
  256. @"The format of the phone number provided is incorrect. Please enter the phone number in a "
  257. "format that can be parsed into E.164 format. E.164 phone numbers are written in the format "
  258. "[+][country code][subscriber number including area code].";
  259. /** @var kFIRAuthErrorMessageMissingVerificationCode
  260. @brief Message for @c FIRAuthErrorCodeMissingVerificationCode error code.
  261. */
  262. static NSString *const kFIRAuthErrorMessageMissingVerificationCode =
  263. @"The phone auth credential was created with an empty SMS verification Code.";
  264. /** @var kFIRAuthErrorMessageInvalidVerificationCode
  265. @brief Message for @c FIRAuthErrorCodeInvalidVerificationCode error code.
  266. */
  267. static NSString *const kFIRAuthErrorMessageInvalidVerificationCode =
  268. @"The multifactor verification code used to create the auth credential is invalid."
  269. @"Re-collect the verification code and be sure to use the verification code provided by the "
  270. @"user.";
  271. /** @var kFIRAuthErrorMessageMissingVerificationID
  272. @brief Message for @c FIRAuthErrorCodeInvalidVerificationID error code.
  273. */
  274. static NSString *const kFIRAuthErrorMessageMissingVerificationID =
  275. @"The phone auth credential was created with an empty verification ID.";
  276. /** @var kFIRAuthErrorMessageInvalidVerificationID
  277. @brief Message for @c FIRAuthErrorCodeInvalidVerificationID error code.
  278. */
  279. static NSString *const kFIRAuthErrorMessageInvalidVerificationID =
  280. @"The verification ID used to create the phone auth credential is invalid.";
  281. /** @var kFIRAuthErrorMessageLocalPlayerNotAuthenticated
  282. @brief Message for @c FIRAuthErrorCodeLocalPlayerNotAuthenticated error code.
  283. */
  284. static NSString *const kFIRAuthErrorMessageLocalPlayerNotAuthenticated =
  285. @"The local player is not authenticated. Please log the local player in to Game Center.";
  286. /** @var kFIRAuthErrorMessageGameKitNotLinked
  287. @brief Message for @c kFIRAuthErrorMessageGameKitNotLinked error code.
  288. */
  289. static NSString *const kFIRAuthErrorMessageGameKitNotLinked =
  290. @"The GameKit framework is not linked. Please turn on the Game Center capability.";
  291. /** @var kFIRAuthErrorMessageSessionExpired
  292. @brief Message for @c FIRAuthErrorCodeSessionExpired error code.
  293. */
  294. static NSString *const kFIRAuthErrorMessageSessionExpired =
  295. @"The SMS code has expired. Please "
  296. @"re-send the verification code to try again.";
  297. /** @var kFIRAuthErrorMessageMissingAppCredential
  298. @brief Message for @c FIRAuthErrorCodeMissingAppCredential error code.
  299. */
  300. static NSString *const kFIRAuthErrorMessageMissingAppCredential =
  301. @"The phone verification request "
  302. "is missing an APNs Device token. Firebase Auth automatically detects APNs Device Tokens, "
  303. "however, if method swizzling is disabled, the APNs token must be set via the APNSToken "
  304. "property on FIRAuth or by calling setAPNSToken:type on FIRAuth.";
  305. /** @var kFIRAuthErrorMessageInvalidAppCredential
  306. @brief Message for @c FIRAuthErrorCodeInvalidAppCredential error code.
  307. */
  308. static NSString *const kFIRAuthErrorMessageInvalidAppCredential =
  309. @"The APNs device token provided "
  310. "is either incorrect or does not match the private certificate uploaded to the Firebase "
  311. "Console.";
  312. /** @var kFIRAuthErrorMessageQuotaExceeded
  313. @brief Message for @c FIRAuthErrorCodeQuotaExceeded error code.
  314. */
  315. static NSString *const kFIRAuthErrorMessageQuotaExceeded = @"The quota for this operation "
  316. "has been exceeded.";
  317. /** @var kFIRAuthErrorMessageMissingAppToken
  318. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  319. */
  320. static NSString *const kFIRAuthErrorMessageMissingAppToken =
  321. @"There seems to be a problem with "
  322. "your project's Firebase phone number authentication set-up, please make sure to follow the "
  323. "instructions found at https://firebase.google.com/docs/auth/ios/phone-auth";
  324. /** @var kFIRAuthErrorMessageMissingAppToken
  325. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  326. */
  327. static NSString *const kFIRAuthErrorMessageNotificationNotForwarded =
  328. @"If app delegate swizzling "
  329. "is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to "
  330. "FIRAuth's canHandleNotificaton: method.";
  331. /** @var kFIRAuthErrorMessageAppNotVerified
  332. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  333. */
  334. static NSString *const kFIRAuthErrorMessageAppNotVerified =
  335. @"Firebase could not retrieve the "
  336. "silent push notification and therefore could not verify your app. Ensure that you configured "
  337. "your app correctly to receive push notifications.";
  338. /** @var kFIRAuthErrorMessageCaptchaCheckFailed
  339. @brief Message for @c FIRAuthErrorCodeCaptchaCheckFailed error code.
  340. */
  341. static NSString *const kFIRAuthErrorMessageCaptchaCheckFailed =
  342. @"The reCAPTCHA response token "
  343. "provided is either invalid, expired or already";
  344. /** @var kFIRAuthErrorMessageWebContextAlreadyPresented
  345. @brief Message for @c FIRAuthErrorCodeWebContextAlreadyPresented error code.
  346. */
  347. static NSString *const kFIRAuthErrorMessageWebContextAlreadyPresented =
  348. @"User interaction is "
  349. "still ongoing, another view cannot be presented.";
  350. /** @var kFIRAuthErrorMessageWebContextCancelled
  351. @brief Message for @c FIRAuthErrorCodeWebContextCancelled error code.
  352. */
  353. static NSString *const kFIRAuthErrorMessageWebContextCancelled = @"The interaction was cancelled "
  354. "by the user.";
  355. /** @var kFIRAuthErrorMessageInvalidClientID
  356. @brief Message for @c FIRAuthErrorCodeInvalidClientID error code.
  357. */
  358. static NSString *const kFIRAuthErrorMessageInvalidClientID =
  359. @"The OAuth client ID provided is "
  360. "either invalid or does not match the specified API key.";
  361. /** @var kFIRAuthErrorMessageWebRequestFailed
  362. @brief Message for @c FIRAuthErrorCodeWebRequestFailed error code.
  363. */
  364. static NSString *const kFIRAuthErrorMessageWebRequestFailed =
  365. @"A network error (such as timeout, "
  366. "interrupted connection, or unreachable host) has occurred within the web context.";
  367. /** @var kFIRAuthErrorMessageWebInternalError
  368. @brief Message for @c FIRAuthErrorCodeWebInternalError error code.
  369. */
  370. static NSString *const kFIRAuthErrorMessageWebInternalError =
  371. @"An internal error has occurred "
  372. "within the SFSafariViewController or WKWebView.";
  373. /** @var kFIRAuthErrorMessageAppVerificationUserInteractionFailure
  374. @brief Message for @c FIRAuthErrorCodeInvalidClientID error code.
  375. */
  376. static NSString *const kFIRAuthErrorMessageAppVerificationUserInteractionFailure =
  377. @"The app "
  378. "verification process has failed, print and inspect the error details for more information";
  379. /** @var kFIRAuthErrorMessageNullUser
  380. @brief Message for @c FIRAuthErrorCodeNullUser error code.
  381. */
  382. static NSString *const kFIRAuthErrorMessageNullUser =
  383. @"A null user object was provided as the "
  384. "argument for an operation which requires a non-null user object.";
  385. /** @var kFIRAuthErrorMessageInvalidProviderID
  386. @brief Message for @c FIRAuthErrorCodeInvalidProviderID error code.
  387. */
  388. static NSString *const kFIRAuthErrorMessageInvalidProviderID =
  389. @"The provider ID provided for the "
  390. "attempted web operation is invalid.";
  391. /** @var kFIRAuthErrorMessageInvalidDynamicLinkDomain
  392. @brief Message for @c kFIRAuthErrorMessageInvalidDynamicLinkDomain error code.
  393. */
  394. static NSString *const kFIRAuthErrorMessageInvalidDynamicLinkDomain =
  395. @"The "
  396. "Firebase Dynamic Link domain used is either not configured or is unauthorized "
  397. "for the current project.";
  398. /** @var kFIRAuthErrorMessageInternalError
  399. @brief Message for @c FIRAuthErrorCodeInternalError error code.
  400. */
  401. static NSString *const kFIRAuthErrorMessageInternalError =
  402. @"An internal error has occurred, "
  403. "print and inspect the error details for more information.";
  404. /** @var kFIRAuthErrorMessageMalformedJWT
  405. @brief Error message constant describing @c FIRAuthErrorCodeMalformedJWT errors.
  406. */
  407. static NSString *const kFIRAuthErrorMessageMalformedJWT =
  408. @"Failed to parse JWT. Check the userInfo dictionary for the full token.";
  409. /** @var kFIRAuthErrorMessageSecondFactorRequired
  410. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  411. */
  412. static NSString *const kFIRAuthErrorMessageSecondFactorRequired =
  413. @"Please complete a second factor challenge to finish signing into this account.";
  414. /** @var kFIRAuthErrorMessageSecondFactorRequired
  415. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  416. */
  417. static NSString *const FIRAuthErrorMessageMissingMultiFactorSession =
  418. @"The request is missing proof of first factor successful sign-in.";
  419. /** @var kFIRAuthErrorMessageSecondFactorRequired
  420. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  421. */
  422. static NSString *const FIRAuthErrorMessageMissingMultiFactorInfo =
  423. @"No second factor identifier is provided.";
  424. /** @var kFIRAuthErrorMessageSecondFactorRequired
  425. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  426. */
  427. static NSString *const FIRAuthErrorMessageInvalidMultiFactorSession =
  428. @"The request does not contain a valid proof of first factor successful sign-in.";
  429. /** @var kFIRAuthErrorMessageSecondFactorRequired
  430. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  431. */
  432. static NSString *const FIRAuthErrorMessageMultiFactorInfoNotFound =
  433. @"The user does not have a second factor matching the identifier provided.";
  434. /** @var kFIRAuthErrorMessageSecondFactorRequired
  435. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  436. */
  437. static NSString *const FIRAuthErrorMessageAdminRestrictedOperation =
  438. @"This operation is restricted to administrators only.";
  439. /** @var kFIRAuthErrorMessageSecondFactorRequired
  440. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  441. */
  442. static NSString *const FIRAuthErrorMessageUnverifiedEmail =
  443. @"The operation requires a verified email.";
  444. /** @var kFIRAuthErrorMessageSecondFactorRequired
  445. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  446. */
  447. static NSString *const FIRAuthErrorMessageSecondFactorAlreadyEnrolled =
  448. @"The second factor is already enrolled on this account.";
  449. /** @var kFIRAuthErrorMessageSecondFactorRequired
  450. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  451. */
  452. static NSString *const FIRAuthErrorMessageMaximumSecondFactorCountExceeded =
  453. @"The maximum allowed number of second factors on a user has been exceeded.";
  454. /** @var kFIRAuthErrorMessageSecondFactorRequired
  455. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  456. */
  457. static NSString *const FIRAuthErrorMessageUnsupportedFirstFactor =
  458. @"Enrolling a second factor or signing in with a multi-factor account requires sign-in with a "
  459. @"supported first factor.";
  460. /** @var kFIRAuthErrorMessageSecondFactorRequired
  461. @brief Message for @c kFIRAuthErrorMessageSecondFactorRequired error code.
  462. */
  463. static NSString *const FIRAuthErrorMessageEmailChangeNeedsVerification =
  464. @"Multi-factor users must always have a verified email.";
  465. /** @var kFIRAuthErrorMessageDynamicLinkNotActivated
  466. @brief Error message constant describing @c FIRAuthErrorCodeDynamicLinkNotActivated errors.
  467. */
  468. static NSString *const kFIRAuthErrorMessageDynamicLinkNotActivated =
  469. @"Please activate Dynamic Links in the Firebase Console and agree to the terms and conditions.";
  470. /** @var kFIRAuthErrorMessageRejectedCredential
  471. @brief Error message constant describing @c FIRAuthErrorCodeRejectedCredential errors.
  472. */
  473. static NSString *const kFIRAuthErrorMessageRejectedCredential =
  474. @"The request contains malformed or mismatching credentials.";
  475. /** @var kFIRAuthErrorMessageMissingClientIdentifier
  476. @brief Error message constant describing @c FIRAuthErrorCodeMissingClientIdentifier errors.
  477. */
  478. static NSString *const kFIRAuthErrorMessageMissingClientIdentifier =
  479. @"The request does not contain a client identifier.";
  480. /** @var kFIRAuthErrorMessageMissingOrInvalidNonce
  481. @brief Error message constant describing @c FIRAuthErrorCodeMissingOrInvalidNonce errors.
  482. */
  483. static NSString *const kFIRAuthErrorMessageMissingOrInvalidNonce =
  484. @"The request contains malformed or mismatched credentials.";
  485. /** @var kFIRAuthErrorMessageTenantIDMismatch.
  486. @brief Message for @c FIRAuthErrorCodeTenantIDMismatch error code.
  487. */
  488. static NSString *const kFIRAuthErrorMessageTenantIDMismatch =
  489. @"The provided user's tenant ID does"
  490. "not match the Auth instance's tenant ID.";
  491. /** @var kFIRAuthErrorMessageUnsupportedTenantOperation
  492. @brief Message for @c FIRAuthErrorCodeUnsupportedTenantOperation error code.
  493. */
  494. static NSString *const kFIRAuthErrorMessageUnsupportedTenantOperation =
  495. @"This operation is not"
  496. "supported in a multi-tenant context.";
  497. /** @var kFIRAuthErrorMessageBlockingCloudFunctionReturnedError
  498. @brief Message for @c FIRAuthErrorCodeBlockingCloudFunctionError error code.
  499. */
  500. static NSString *const kFIRAuthErrorMessageBlockingCloudFunctionReturnedError =
  501. @"Blocking cloud function returned an error.";
  502. static NSString *const kFIRAuthErrorMessageRecaptchaNotEnabled =
  503. @"reCAPTCHA Enterprise is not enabled for this project.";
  504. static NSString *const kFIRAuthErrorMessageMissingRecaptchaToken =
  505. @"The backend request is missing the reCAPTCHA verification token.";
  506. static NSString *const kFIRAuthErrorMessageInvalidRecaptchaToken =
  507. @"The reCAPTCHA verification token is invalid or has expired.";
  508. static NSString *const kFIRAuthErrorMessageInvalidRecaptchaAction =
  509. @"The reCAPTCHA verification failed due to an invalid action.";
  510. static NSString *const kFIRAuthErrorMessageMissingClientType =
  511. @"The request is missing a client type or the client type is invalid.";
  512. static NSString *const kFIRAuthErrorMessageMissingRecaptchaVersion =
  513. @"The request is missing the reCAPTCHA version parameter.";
  514. static NSString *const kFIRAuthErrorMessageInvalidRecaptchaVersion =
  515. @"The request specifies an invalid version of reCAPTCHA.";
  516. static NSString *const kFIRAuthErrorMessageInvalidReqType =
  517. @"The request is not supported or is invalid.";
  518. // TODO(chuanr): point the link to GCIP doc once available.
  519. static NSString *const kFIRAuthErrorMessageRecaptchaSDKNotLinked =
  520. @"The reCAPTCHA SDK is not linked to your app. See "
  521. @"https://cloud.google.com/recaptcha-enterprise/docs/instrument-ios-apps";
  522. static NSString *const kFIRAuthErrorMessageInvalidLoginCredentials =
  523. @"Login credentials invalid. It is possible that the email/password combination does not "
  524. @"exist.";
  525. static NSString *const kFIRAuthErrorMessageMissingPasskeyEnrollment =
  526. @"Cannot find the passkey linked to the current account.";
  527. /** @var FIRAuthErrorDescription
  528. @brief The error descrioption, based on the error code.
  529. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  530. */
  531. static NSString *FIRAuthErrorDescription(FIRAuthErrorCode code) {
  532. switch (code) {
  533. case FIRAuthErrorCodeInvalidCustomToken:
  534. return kFIRAuthErrorMessageInvalidCustomToken;
  535. case FIRAuthErrorCodeCustomTokenMismatch:
  536. return kFIRAuthErrorMessageCustomTokenMismatch;
  537. case FIRAuthErrorCodeInvalidEmail:
  538. return kFIRAuthErrorMessageInvalidEmail;
  539. case FIRAuthErrorCodeInvalidCredential:
  540. return kFIRAuthErrorMessageInvalidCredential;
  541. case FIRAuthErrorCodeUserDisabled:
  542. return kFIRAuthErrorMessageUserDisabled;
  543. case FIRAuthErrorCodeEmailAlreadyInUse:
  544. return kFIRAuthErrorMessageEmailAlreadyInUse;
  545. case FIRAuthErrorCodeWrongPassword:
  546. return kFIRAuthErrorMessageWrongPassword;
  547. case FIRAuthErrorCodeTooManyRequests:
  548. return kFIRAuthErrorMessageTooManyRequests;
  549. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  550. return kFIRAuthErrorMessageAccountExistsWithDifferentCredential;
  551. case FIRAuthErrorCodeRequiresRecentLogin:
  552. return kFIRAuthErrorMessageRequiresRecentLogin;
  553. case FIRAuthErrorCodeProviderAlreadyLinked:
  554. return kFIRAuthErrorMessageProviderAlreadyLinked;
  555. case FIRAuthErrorCodeNoSuchProvider:
  556. return kFIRAuthErrorMessageNoSuchProvider;
  557. case FIRAuthErrorCodeInvalidUserToken:
  558. return kFIRAuthErrorMessageInvalidUserToken;
  559. case FIRAuthErrorCodeNetworkError:
  560. return kFIRAuthErrorMessageNetworkError;
  561. case FIRAuthErrorCodeKeychainError:
  562. return kFIRAuthErrorMessageKeychainError;
  563. case FIRAuthErrorCodeUserTokenExpired:
  564. return kFIRAuthErrorMessageUserTokenExpired;
  565. case FIRAuthErrorCodeUserNotFound:
  566. return kFIRAuthErrorMessageUserNotFound;
  567. case FIRAuthErrorCodeInvalidAPIKey:
  568. return kFIRAuthErrorMessageInvalidAPIKey;
  569. case FIRAuthErrorCodeCredentialAlreadyInUse:
  570. return kFIRAuthErrorMessageCredentialAlreadyInUse;
  571. case FIRAuthErrorCodeInternalError:
  572. return kFIRAuthErrorMessageInternalError;
  573. case FIRAuthErrorCodeUserMismatch:
  574. return FIRAuthErrorMessageUserMismatch;
  575. case FIRAuthErrorCodeOperationNotAllowed:
  576. return kFIRAuthErrorMessageOperationNotAllowed;
  577. case FIRAuthErrorCodeWeakPassword:
  578. return kFIRAuthErrorMessageWeakPassword;
  579. case FIRAuthErrorCodeAppNotAuthorized:
  580. return kFIRAuthErrorMessageAppNotAuthorized;
  581. case FIRAuthErrorCodeExpiredActionCode:
  582. return kFIRAuthErrorMessageExpiredActionCode;
  583. case FIRAuthErrorCodeInvalidActionCode:
  584. return kFIRAuthErrorMessageInvalidActionCode;
  585. case FIRAuthErrorCodeInvalidSender:
  586. return kFIRAuthErrorMessageInvalidSender;
  587. case FIRAuthErrorCodeInvalidMessagePayload:
  588. return kFIRAuthErrorMessageInvalidMessagePayload;
  589. case FIRAuthErrorCodeInvalidRecipientEmail:
  590. return kFIRAuthErrorMessageInvalidRecipientEmail;
  591. case FIRAuthErrorCodeMissingIosBundleID:
  592. return kFIRAuthErrorMessageMissingIosBundleID;
  593. case FIRAuthErrorCodeMissingAndroidPackageName:
  594. return kFIRAuthErrorMessageMissingAndroidPackageName;
  595. case FIRAuthErrorCodeUnauthorizedDomain:
  596. return kFIRAuthErrorMessageUnauthorizedDomain;
  597. case FIRAuthErrorCodeInvalidContinueURI:
  598. return kFIRAuthErrorMessageInvalidContinueURI;
  599. case FIRAuthErrorCodeMissingContinueURI:
  600. return kFIRAuthErrorMessageMissingContinueURI;
  601. case FIRAuthErrorCodeMissingEmail:
  602. return kFIRAuthErrorMessageMissingEmail;
  603. case FIRAuthErrorCodeMissingPhoneNumber:
  604. return kFIRAuthErrorMessageMissingPhoneNumber;
  605. case FIRAuthErrorCodeInvalidPhoneNumber:
  606. return kFIRAuthErrorMessageInvalidPhoneNumber;
  607. case FIRAuthErrorCodeMissingVerificationCode:
  608. return kFIRAuthErrorMessageMissingVerificationCode;
  609. case FIRAuthErrorCodeInvalidVerificationCode:
  610. return kFIRAuthErrorMessageInvalidVerificationCode;
  611. case FIRAuthErrorCodeMissingVerificationID:
  612. return kFIRAuthErrorMessageMissingVerificationID;
  613. case FIRAuthErrorCodeInvalidVerificationID:
  614. return kFIRAuthErrorMessageInvalidVerificationID;
  615. case FIRAuthErrorCodeSessionExpired:
  616. return kFIRAuthErrorMessageSessionExpired;
  617. case FIRAuthErrorCodeMissingAppCredential:
  618. return kFIRAuthErrorMessageMissingAppCredential;
  619. case FIRAuthErrorCodeInvalidAppCredential:
  620. return kFIRAuthErrorMessageInvalidAppCredential;
  621. case FIRAuthErrorCodeQuotaExceeded:
  622. return kFIRAuthErrorMessageQuotaExceeded;
  623. case FIRAuthErrorCodeMissingAppToken:
  624. return kFIRAuthErrorMessageMissingAppToken;
  625. case FIRAuthErrorCodeNotificationNotForwarded:
  626. return kFIRAuthErrorMessageNotificationNotForwarded;
  627. case FIRAuthErrorCodeAppNotVerified:
  628. return kFIRAuthErrorMessageAppNotVerified;
  629. case FIRAuthErrorCodeCaptchaCheckFailed:
  630. return kFIRAuthErrorMessageCaptchaCheckFailed;
  631. case FIRAuthErrorCodeWebContextAlreadyPresented:
  632. return kFIRAuthErrorMessageWebContextAlreadyPresented;
  633. case FIRAuthErrorCodeWebContextCancelled:
  634. return kFIRAuthErrorMessageWebContextCancelled;
  635. case FIRAuthErrorCodeInvalidClientID:
  636. return kFIRAuthErrorMessageInvalidClientID;
  637. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  638. return kFIRAuthErrorMessageAppVerificationUserInteractionFailure;
  639. case FIRAuthErrorCodeWebNetworkRequestFailed:
  640. return kFIRAuthErrorMessageWebRequestFailed;
  641. case FIRAuthErrorCodeNullUser:
  642. return kFIRAuthErrorMessageNullUser;
  643. case FIRAuthErrorCodeInvalidProviderID:
  644. return kFIRAuthErrorMessageInvalidProviderID;
  645. case FIRAuthErrorCodeInvalidDynamicLinkDomain:
  646. return kFIRAuthErrorMessageInvalidDynamicLinkDomain;
  647. case FIRAuthErrorCodeWebInternalError:
  648. return kFIRAuthErrorMessageWebInternalError;
  649. case FIRAuthErrorCodeWebSignInUserInteractionFailure:
  650. return kFIRAuthErrorMessageAppVerificationUserInteractionFailure;
  651. case FIRAuthErrorCodeMalformedJWT:
  652. return kFIRAuthErrorMessageMalformedJWT;
  653. case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
  654. return kFIRAuthErrorMessageLocalPlayerNotAuthenticated;
  655. case FIRAuthErrorCodeGameKitNotLinked:
  656. return kFIRAuthErrorMessageGameKitNotLinked;
  657. case FIRAuthErrorCodeSecondFactorRequired:
  658. return kFIRAuthErrorMessageSecondFactorRequired;
  659. case FIRAuthErrorCodeMissingMultiFactorSession:
  660. return FIRAuthErrorMessageMissingMultiFactorSession;
  661. case FIRAuthErrorCodeMissingMultiFactorInfo:
  662. return FIRAuthErrorMessageMissingMultiFactorInfo;
  663. case FIRAuthErrorCodeInvalidMultiFactorSession:
  664. return FIRAuthErrorMessageInvalidMultiFactorSession;
  665. case FIRAuthErrorCodeMultiFactorInfoNotFound:
  666. return FIRAuthErrorMessageMultiFactorInfoNotFound;
  667. case FIRAuthErrorCodeAdminRestrictedOperation:
  668. return FIRAuthErrorMessageAdminRestrictedOperation;
  669. case FIRAuthErrorCodeUnverifiedEmail:
  670. return FIRAuthErrorMessageUnverifiedEmail;
  671. case FIRAuthErrorCodeSecondFactorAlreadyEnrolled:
  672. return FIRAuthErrorMessageSecondFactorAlreadyEnrolled;
  673. case FIRAuthErrorCodeMaximumSecondFactorCountExceeded:
  674. return FIRAuthErrorMessageMaximumSecondFactorCountExceeded;
  675. case FIRAuthErrorCodeUnsupportedFirstFactor:
  676. return FIRAuthErrorMessageUnsupportedFirstFactor;
  677. case FIRAuthErrorCodeEmailChangeNeedsVerification:
  678. return FIRAuthErrorMessageEmailChangeNeedsVerification;
  679. case FIRAuthErrorCodeDynamicLinkNotActivated:
  680. return kFIRAuthErrorMessageDynamicLinkNotActivated;
  681. case FIRAuthErrorCodeRejectedCredential:
  682. return kFIRAuthErrorMessageRejectedCredential;
  683. case FIRAuthErrorCodeMissingClientIdentifier:
  684. return kFIRAuthErrorMessageMissingClientIdentifier;
  685. case FIRAuthErrorCodeMissingOrInvalidNonce:
  686. return kFIRAuthErrorMessageMissingOrInvalidNonce;
  687. case FIRAuthErrorCodeTenantIDMismatch:
  688. return kFIRAuthErrorMessageTenantIDMismatch;
  689. case FIRAuthErrorCodeUnsupportedTenantOperation:
  690. return kFIRAuthErrorMessageUnsupportedTenantOperation;
  691. case FIRAuthErrorCodeBlockingCloudFunctionError:
  692. return kFIRAuthErrorMessageBlockingCloudFunctionReturnedError;
  693. case FIRAuthErrorCodeRecaptchaNotEnabled:
  694. return kFIRAuthErrorMessageRecaptchaNotEnabled;
  695. case FIRAuthErrorCodeMissingRecaptchaToken:
  696. return kFIRAuthErrorMessageMissingRecaptchaToken;
  697. case FIRAuthErrorCodeInvalidRecaptchaToken:
  698. return kFIRAuthErrorMessageInvalidRecaptchaToken;
  699. case FIRAuthErrorCodeInvalidRecaptchaAction:
  700. return kFIRAuthErrorMessageInvalidRecaptchaAction;
  701. case FIRAuthErrorCodeMissingClientType:
  702. return kFIRAuthErrorMessageMissingClientType;
  703. case FIRAuthErrorCodeMissingRecaptchaVersion:
  704. return kFIRAuthErrorMessageMissingRecaptchaVersion;
  705. case FIRAuthErrorCodeInvalidRecaptchaVersion:
  706. return kFIRAuthErrorMessageInvalidRecaptchaVersion;
  707. case FIRAuthErrorCodeInvalidReqType:
  708. return kFIRAuthErrorMessageInvalidReqType;
  709. case FIRAuthErrorCodeRecaptchaSDKNotLinked:
  710. return kFIRAuthErrorMessageRecaptchaSDKNotLinked;
  711. case FIRAuthErrorCodePasskeyEnrollmentNotFound:
  712. return kFIRAuthErrorMessageMissingPasskeyEnrollment;
  713. }
  714. }
  715. /** @var FIRAuthErrorCodeString
  716. @brief The error short string, based on the error code.
  717. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  718. */
  719. static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
  720. switch (code) {
  721. case FIRAuthErrorCodeInvalidCustomToken:
  722. return @"ERROR_INVALID_CUSTOM_TOKEN";
  723. case FIRAuthErrorCodeCustomTokenMismatch:
  724. return @"ERROR_CUSTOM_TOKEN_MISMATCH";
  725. case FIRAuthErrorCodeInvalidEmail:
  726. return @"ERROR_INVALID_EMAIL";
  727. case FIRAuthErrorCodeInvalidCredential:
  728. return @"ERROR_INVALID_CREDENTIAL";
  729. case FIRAuthErrorCodeUserDisabled:
  730. return @"ERROR_USER_DISABLED";
  731. case FIRAuthErrorCodeEmailAlreadyInUse:
  732. return @"ERROR_EMAIL_ALREADY_IN_USE";
  733. case FIRAuthErrorCodeWrongPassword:
  734. return @"ERROR_WRONG_PASSWORD";
  735. case FIRAuthErrorCodeTooManyRequests:
  736. return @"ERROR_TOO_MANY_REQUESTS";
  737. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  738. return @"ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL";
  739. case FIRAuthErrorCodeRequiresRecentLogin:
  740. return @"ERROR_REQUIRES_RECENT_LOGIN";
  741. case FIRAuthErrorCodeProviderAlreadyLinked:
  742. return @"ERROR_PROVIDER_ALREADY_LINKED";
  743. case FIRAuthErrorCodeNoSuchProvider:
  744. return @"ERROR_NO_SUCH_PROVIDER";
  745. case FIRAuthErrorCodeInvalidUserToken:
  746. return @"ERROR_INVALID_USER_TOKEN";
  747. case FIRAuthErrorCodeNetworkError:
  748. return @"ERROR_NETWORK_REQUEST_FAILED";
  749. case FIRAuthErrorCodeKeychainError:
  750. return @"ERROR_KEYCHAIN_ERROR";
  751. case FIRAuthErrorCodeMissingClientType:
  752. return @"ERROR_MISSING_CLIENT_TYPE";
  753. case FIRAuthErrorCodeUserTokenExpired:
  754. return @"ERROR_USER_TOKEN_EXPIRED";
  755. case FIRAuthErrorCodeUserNotFound:
  756. return @"ERROR_USER_NOT_FOUND";
  757. case FIRAuthErrorCodeInvalidAPIKey:
  758. return @"ERROR_INVALID_API_KEY";
  759. case FIRAuthErrorCodeCredentialAlreadyInUse:
  760. return @"ERROR_CREDENTIAL_ALREADY_IN_USE";
  761. case FIRAuthErrorCodeInternalError:
  762. return @"ERROR_INTERNAL_ERROR";
  763. case FIRAuthErrorCodeUserMismatch:
  764. return @"ERROR_USER_MISMATCH";
  765. case FIRAuthErrorCodeOperationNotAllowed:
  766. return @"ERROR_OPERATION_NOT_ALLOWED";
  767. case FIRAuthErrorCodeWeakPassword:
  768. return @"ERROR_WEAK_PASSWORD";
  769. case FIRAuthErrorCodeAppNotAuthorized:
  770. return @"ERROR_APP_NOT_AUTHORIZED";
  771. case FIRAuthErrorCodeExpiredActionCode:
  772. return @"ERROR_EXPIRED_ACTION_CODE";
  773. case FIRAuthErrorCodeInvalidActionCode:
  774. return @"ERROR_INVALID_ACTION_CODE";
  775. case FIRAuthErrorCodeInvalidMessagePayload:
  776. return @"ERROR_INVALID_MESSAGE_PAYLOAD";
  777. case FIRAuthErrorCodeInvalidSender:
  778. return @"ERROR_INVALID_SENDER";
  779. case FIRAuthErrorCodeInvalidRecipientEmail:
  780. return @"ERROR_INVALID_RECIPIENT_EMAIL";
  781. case FIRAuthErrorCodeMissingIosBundleID:
  782. return @"ERROR_MISSING_IOS_BUNDLE_ID";
  783. case FIRAuthErrorCodeMissingAndroidPackageName:
  784. return @"ERROR_MISSING_ANDROID_PKG_NAME";
  785. case FIRAuthErrorCodeUnauthorizedDomain:
  786. return @"ERROR_UNAUTHORIZED_DOMAIN";
  787. case FIRAuthErrorCodeInvalidContinueURI:
  788. return @"ERROR_INVALID_CONTINUE_URI";
  789. case FIRAuthErrorCodeMissingContinueURI:
  790. return @"ERROR_MISSING_CONTINUE_URI";
  791. case FIRAuthErrorCodeMissingEmail:
  792. return @"ERROR_MISSING_EMAIL";
  793. case FIRAuthErrorCodeMissingPhoneNumber:
  794. return @"ERROR_MISSING_PHONE_NUMBER";
  795. case FIRAuthErrorCodeInvalidPhoneNumber:
  796. return @"ERROR_INVALID_PHONE_NUMBER";
  797. case FIRAuthErrorCodeMissingVerificationCode:
  798. return @"ERROR_MISSING_VERIFICATION_CODE";
  799. case FIRAuthErrorCodeInvalidVerificationCode:
  800. return @"ERROR_INVALID_VERIFICATION_CODE";
  801. case FIRAuthErrorCodeMissingVerificationID:
  802. return @"ERROR_MISSING_VERIFICATION_ID";
  803. case FIRAuthErrorCodeInvalidVerificationID:
  804. return @"ERROR_INVALID_VERIFICATION_ID";
  805. case FIRAuthErrorCodeSessionExpired:
  806. return @"ERROR_SESSION_EXPIRED";
  807. case FIRAuthErrorCodeMissingAppCredential:
  808. return @"MISSING_APP_CREDENTIAL";
  809. case FIRAuthErrorCodeInvalidAppCredential:
  810. return @"INVALID_APP_CREDENTIAL";
  811. case FIRAuthErrorCodeQuotaExceeded:
  812. return @"ERROR_QUOTA_EXCEEDED";
  813. case FIRAuthErrorCodeMissingAppToken:
  814. return @"ERROR_MISSING_APP_TOKEN";
  815. case FIRAuthErrorCodeNotificationNotForwarded:
  816. return @"ERROR_NOTIFICATION_NOT_FORWARDED";
  817. case FIRAuthErrorCodeAppNotVerified:
  818. return @"ERROR_APP_NOT_VERIFIED";
  819. case FIRAuthErrorCodeCaptchaCheckFailed:
  820. return @"ERROR_CAPTCHA_CHECK_FAILED";
  821. case FIRAuthErrorCodeWebContextAlreadyPresented:
  822. return @"ERROR_WEB_CONTEXT_ALREADY_PRESENTED";
  823. case FIRAuthErrorCodeWebContextCancelled:
  824. return @"ERROR_WEB_CONTEXT_CANCELLED";
  825. case FIRAuthErrorCodeInvalidClientID:
  826. return @"ERROR_INVALID_CLIENT_ID";
  827. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  828. return @"ERROR_APP_VERIFICATION_FAILED";
  829. case FIRAuthErrorCodeWebNetworkRequestFailed:
  830. return @"ERROR_WEB_NETWORK_REQUEST_FAILED";
  831. case FIRAuthErrorCodeNullUser:
  832. return @"ERROR_NULL_USER";
  833. case FIRAuthErrorCodeInvalidProviderID:
  834. return @"ERROR_INVALID_PROVIDER_ID";
  835. case FIRAuthErrorCodeInvalidDynamicLinkDomain:
  836. return @"ERROR_INVALID_DYNAMIC_LINK_DOMAIN";
  837. case FIRAuthErrorCodeWebInternalError:
  838. return @"ERROR_WEB_INTERNAL_ERROR";
  839. case FIRAuthErrorCodeWebSignInUserInteractionFailure:
  840. return @"ERROR_WEB_USER_INTERACTION_FAILURE";
  841. case FIRAuthErrorCodeMalformedJWT:
  842. return @"ERROR_MALFORMED_JWT";
  843. case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
  844. return @"ERROR_LOCAL_PLAYER_NOT_AUTHENTICATED";
  845. case FIRAuthErrorCodeGameKitNotLinked:
  846. return @"ERROR_GAME_KIT_NOT_LINKED";
  847. case FIRAuthErrorCodeSecondFactorRequired:
  848. return @"ERROR_SECOND_FACTOR_REQUIRED";
  849. case FIRAuthErrorCodeMissingMultiFactorSession:
  850. return @"ERROR_MISSING_MULTI_FACTOR_SESSION";
  851. case FIRAuthErrorCodeMissingMultiFactorInfo:
  852. return @"ERROR_MISSING_MULTI_FACTOR_INFO";
  853. case FIRAuthErrorCodeInvalidMultiFactorSession:
  854. return @"ERROR_INVALID_MULTI_FACTOR_SESSION";
  855. case FIRAuthErrorCodeMultiFactorInfoNotFound:
  856. return @"ERROR_MULTI_FACTOR_INFO_NOT_FOUND";
  857. case FIRAuthErrorCodeAdminRestrictedOperation:
  858. return @"ERROR_ADMIN_RESTRICTED_OPERATION";
  859. case FIRAuthErrorCodeUnverifiedEmail:
  860. return @"ERROR_UNVERIFIED_EMAIL";
  861. case FIRAuthErrorCodeSecondFactorAlreadyEnrolled:
  862. return @"ERROR_SECOND_FACTOR_ALREADY_ENROLLED";
  863. case FIRAuthErrorCodeMaximumSecondFactorCountExceeded:
  864. return @"ERROR_MAXIMUM_SECOND_FACTOR_COUNT_EXCEEDED";
  865. case FIRAuthErrorCodeUnsupportedFirstFactor:
  866. return @"ERROR_UNSUPPORTED_FIRST_FACTOR";
  867. case FIRAuthErrorCodeEmailChangeNeedsVerification:
  868. return @"ERROR_EMAIL_CHANGE_NEEDS_VERIFICATION";
  869. case FIRAuthErrorCodeDynamicLinkNotActivated:
  870. return @"ERROR_DYNAMIC_LINK_NOT_ACTIVATED";
  871. case FIRAuthErrorCodeRejectedCredential:
  872. return @"ERROR_REJECTED_CREDENTIAL";
  873. case FIRAuthErrorCodeMissingClientIdentifier:
  874. return @"ERROR_MISSING_CLIENT_IDENTIFIER";
  875. case FIRAuthErrorCodeMissingOrInvalidNonce:
  876. return @"ERROR_MISSING_OR_INVALID_NONCE";
  877. case FIRAuthErrorCodeTenantIDMismatch:
  878. return @"ERROR_TENANT_ID_MISMATCH";
  879. case FIRAuthErrorCodeUnsupportedTenantOperation:
  880. return @"ERROR_UNSUPPORTED_TENANT_OPERATION";
  881. case FIRAuthErrorCodeBlockingCloudFunctionError:
  882. return @"ERROR_BLOCKING_CLOUD_FUNCTION_RETURNED_ERROR";
  883. case FIRAuthErrorCodeRecaptchaNotEnabled:
  884. return @"ERROR_RECAPTCHA_NOT_ENABLED";
  885. case FIRAuthErrorCodeMissingRecaptchaToken:
  886. return @"ERROR_MISSING_RECAPTCHA_TOKEN";
  887. case FIRAuthErrorCodeInvalidRecaptchaToken:
  888. return @"ERROR_INVALID_RECAPTCHA_TOKEN";
  889. case FIRAuthErrorCodeInvalidRecaptchaAction:
  890. return @"ERROR_INVALID_RECAPTCHA_ACTION";
  891. case FIRAuthErrorCodeMissingRecaptchaVersion:
  892. return @"ERROR_MISSING_RECAPTCHA_VERSION";
  893. case FIRAuthErrorCodeInvalidRecaptchaVersion:
  894. return @"ERROR_INVALID_RECAPTCHA_VERSION";
  895. case FIRAuthErrorCodeInvalidReqType:
  896. return @"ERROR_INVALID_REQ_TYPE";
  897. case FIRAuthErrorCodeRecaptchaSDKNotLinked:
  898. return @"ERROR_RECAPTCHA_SDK_NOT_LINKED";
  899. case FIRAuthErrorCodePasskeyEnrollmentNotFound:
  900. return @"ERROR_PASSKEY_ENROLLMENT_NOT_FOUND";
  901. }
  902. }
  903. @implementation FIRAuthErrorUtils
  904. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code {
  905. return [self errorWithCode:code message:nil];
  906. }
  907. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code message:(nullable NSString *)message {
  908. NSDictionary *userInfo = nil;
  909. if (message.length) {
  910. userInfo = @{NSLocalizedDescriptionKey : message};
  911. }
  912. return [self errorWithCode:code userInfo:userInfo];
  913. }
  914. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  915. underlyingError:(nullable NSError *)underlyingError {
  916. NSDictionary *errorUserInfo;
  917. if (underlyingError) {
  918. errorUserInfo = @{NSUnderlyingErrorKey : underlyingError};
  919. }
  920. return [self errorWithCode:code userInfo:errorUserInfo];
  921. }
  922. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  923. userInfo:(nullable NSDictionary *)userInfo {
  924. BOOL isPublic = (code & FIRAuthPublicErrorCodeFlag) == FIRAuthPublicErrorCodeFlag;
  925. if (isPublic) {
  926. // This is a public error. Return it as a public error and add a description.
  927. NSInteger errorCode = code & ~FIRAuthPublicErrorCodeFlag;
  928. NSMutableDictionary *errorUserInfo = [NSMutableDictionary dictionary];
  929. if (userInfo) {
  930. [errorUserInfo addEntriesFromDictionary:userInfo];
  931. }
  932. if (!errorUserInfo[NSLocalizedDescriptionKey]) {
  933. errorUserInfo[NSLocalizedDescriptionKey] = FIRAuthErrorDescription(errorCode);
  934. }
  935. errorUserInfo[FIRAuthErrorUserInfoNameKey] = FIRAuthErrorCodeString(errorCode);
  936. return [NSError errorWithDomain:FIRAuthErrorDomain code:errorCode userInfo:errorUserInfo];
  937. } else {
  938. // This is an internal error. Wrap it in an internal error.
  939. NSError *error = [NSError errorWithDomain:FIRAuthInternalErrorDomain
  940. code:code
  941. userInfo:userInfo];
  942. return [self errorWithCode:FIRAuthInternalErrorCodeInternalError underlyingError:error];
  943. }
  944. }
  945. + (NSError *)RPCRequestEncodingErrorWithUnderlyingError:(NSError *)underlyingError {
  946. return [self errorWithCode:FIRAuthInternalErrorCodeRPCRequestEncodingError
  947. underlyingError:underlyingError];
  948. }
  949. + (NSError *)JSONSerializationErrorForUnencodableType {
  950. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError];
  951. }
  952. + (NSError *)JSONSerializationErrorWithUnderlyingError:(NSError *)underlyingError {
  953. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError
  954. underlyingError:underlyingError];
  955. }
  956. + (NSError *)networkErrorWithUnderlyingError:(NSError *)underlyingError {
  957. return [self errorWithCode:FIRAuthInternalErrorCodeNetworkError underlyingError:underlyingError];
  958. }
  959. + (NSError *)unexpectedErrorResponseWithData:(NSData *)data
  960. underlyingError:(NSError *)underlyingError {
  961. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  962. if (data) {
  963. userInfo[FIRAuthErrorUserInfoDataKey] = data;
  964. }
  965. if (underlyingError) {
  966. userInfo[NSUnderlyingErrorKey] = underlyingError;
  967. }
  968. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse
  969. userInfo:[userInfo copy]];
  970. }
  971. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse {
  972. NSDictionary *userInfo;
  973. if (deserializedResponse) {
  974. userInfo = @{
  975. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse,
  976. };
  977. }
  978. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse userInfo:userInfo];
  979. }
  980. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse
  981. underlyingError:(NSError *)underlyingError {
  982. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  983. if (deserializedResponse) {
  984. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  985. }
  986. if (underlyingError) {
  987. userInfo[NSUnderlyingErrorKey] = underlyingError;
  988. }
  989. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse
  990. userInfo:[userInfo copy]];
  991. }
  992. + (NSError *)malformedJWTErrorWithToken:(NSString *)token
  993. underlyingError:(NSError *_Nullable)underlyingError {
  994. NSMutableDictionary *userInfo =
  995. [NSMutableDictionary dictionaryWithObject:kFIRAuthErrorMessageMalformedJWT
  996. forKey:NSLocalizedDescriptionKey];
  997. [userInfo setObject:token forKey:FIRAuthErrorUserInfoDataKey];
  998. if (underlyingError != nil) {
  999. [userInfo setObject:underlyingError forKey:NSUnderlyingErrorKey];
  1000. }
  1001. return [self errorWithCode:FIRAuthInternalErrorCodeMalformedJWT userInfo:[userInfo copy]];
  1002. }
  1003. + (NSError *)unexpectedResponseWithData:(NSData *)data underlyingError:(NSError *)underlyingError {
  1004. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1005. if (data) {
  1006. userInfo[FIRAuthErrorUserInfoDataKey] = data;
  1007. }
  1008. if (underlyingError) {
  1009. userInfo[NSUnderlyingErrorKey] = underlyingError;
  1010. }
  1011. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:[userInfo copy]];
  1012. }
  1013. + (NSError *)unexpectedResponseWithDeserializedResponse:(id)deserializedResponse {
  1014. NSDictionary *userInfo;
  1015. if (deserializedResponse) {
  1016. userInfo = @{
  1017. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse,
  1018. };
  1019. }
  1020. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:userInfo];
  1021. }
  1022. + (NSError *)unexpectedResponseWithDeserializedResponse:(nullable id)deserializedResponse
  1023. underlyingError:(NSError *)underlyingError {
  1024. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1025. if (deserializedResponse) {
  1026. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  1027. }
  1028. if (underlyingError) {
  1029. userInfo[NSUnderlyingErrorKey] = underlyingError;
  1030. }
  1031. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:[userInfo copy]];
  1032. }
  1033. + (NSError *)RPCResponseDecodingErrorWithDeserializedResponse:(id)deserializedResponse
  1034. underlyingError:(NSError *)underlyingError {
  1035. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1036. if (deserializedResponse) {
  1037. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  1038. }
  1039. if (underlyingError) {
  1040. userInfo[NSUnderlyingErrorKey] = underlyingError;
  1041. }
  1042. return [self errorWithCode:FIRAuthInternalErrorCodeRPCResponseDecodingError
  1043. userInfo:[userInfo copy]];
  1044. }
  1045. + (NSError *)emailAlreadyInUseErrorWithEmail:(nullable NSString *)email {
  1046. NSDictionary *userInfo;
  1047. if (email.length) {
  1048. userInfo = @{
  1049. FIRAuthErrorUserInfoEmailKey : email,
  1050. };
  1051. }
  1052. return [self errorWithCode:FIRAuthInternalErrorCodeEmailAlreadyInUse userInfo:userInfo];
  1053. }
  1054. + (NSError *)userDisabledErrorWithMessage:(nullable NSString *)message {
  1055. return [self errorWithCode:FIRAuthInternalErrorCodeUserDisabled message:message];
  1056. }
  1057. + (NSError *)wrongPasswordErrorWithMessage:(nullable NSString *)message {
  1058. return [self errorWithCode:FIRAuthInternalErrorCodeWrongPassword message:message];
  1059. }
  1060. + (NSError *)tooManyRequestsErrorWithMessage:(nullable NSString *)message {
  1061. return [self errorWithCode:FIRAuthInternalErrorCodeTooManyRequests message:message];
  1062. }
  1063. + (NSError *)invalidCustomTokenErrorWithMessage:(nullable NSString *)message {
  1064. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCustomToken message:message];
  1065. }
  1066. + (NSError *)customTokenMistmatchErrorWithMessage:(nullable NSString *)message {
  1067. return [self errorWithCode:FIRAuthInternalErrorCodeCustomTokenMismatch message:message];
  1068. }
  1069. + (NSError *)invalidCredentialErrorWithMessage:(nullable NSString *)message {
  1070. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCredential message:message];
  1071. }
  1072. + (NSError *)requiresRecentLoginErrorWithMessage:(nullable NSString *)message {
  1073. return [self errorWithCode:FIRAuthInternalErrorCodeRequiresRecentLogin message:message];
  1074. }
  1075. + (NSError *)invalidUserTokenErrorWithMessage:(nullable NSString *)message {
  1076. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidUserToken message:message];
  1077. }
  1078. + (NSError *)invalidEmailErrorWithMessage:(nullable NSString *)message {
  1079. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidEmail message:message];
  1080. }
  1081. + (NSError *)accountExistsWithDifferentCredentialErrorWithEmail:(nullable NSString *)email
  1082. updatedCredential:
  1083. (nullable FIRAuthCredential *)updatedCredential {
  1084. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1085. if (email) {
  1086. userInfo[FIRAuthErrorUserInfoEmailKey] = email;
  1087. }
  1088. if (updatedCredential) {
  1089. userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey] = updatedCredential;
  1090. }
  1091. return [self errorWithCode:FIRAuthInternalErrorCodeAccountExistsWithDifferentCredential
  1092. userInfo:userInfo];
  1093. }
  1094. + (NSError *)providerAlreadyLinkedError {
  1095. return [self errorWithCode:FIRAuthInternalErrorCodeProviderAlreadyLinked];
  1096. }
  1097. + (NSError *)noSuchProviderError {
  1098. return [self errorWithCode:FIRAuthInternalErrorCodeNoSuchProvider];
  1099. }
  1100. + (NSError *)userTokenExpiredErrorWithMessage:(nullable NSString *)message {
  1101. return [self errorWithCode:FIRAuthInternalErrorCodeUserTokenExpired message:message];
  1102. }
  1103. + (NSError *)userNotFoundErrorWithMessage:(nullable NSString *)message {
  1104. return [self errorWithCode:FIRAuthInternalErrorCodeUserNotFound message:message];
  1105. }
  1106. + (NSError *)passkeyEnrollmentNotFoundError {
  1107. return [self errorWithCode:FIRAuthInternalPasskeyEnrollmentNotFound];
  1108. }
  1109. + (NSError *)invalidAPIKeyError {
  1110. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAPIKey];
  1111. }
  1112. + (NSError *)userMismatchError {
  1113. return [self errorWithCode:FIRAuthInternalErrorCodeUserMismatch];
  1114. }
  1115. + (NSError *)credentialAlreadyInUseErrorWithMessage:(nullable NSString *)message
  1116. credential:(nullable FIRAuthCredential *)credential
  1117. email:(nullable NSString *)email {
  1118. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1119. if (credential) {
  1120. userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey] = credential;
  1121. }
  1122. if (email.length) {
  1123. userInfo[FIRAuthErrorUserInfoEmailKey] = email;
  1124. }
  1125. if (userInfo.count) {
  1126. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse userInfo:userInfo];
  1127. }
  1128. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse message:message];
  1129. }
  1130. + (NSError *)operationNotAllowedErrorWithMessage:(nullable NSString *)message {
  1131. return [self errorWithCode:FIRAuthInternalErrorCodeOperationNotAllowed message:message];
  1132. }
  1133. + (NSError *)weakPasswordErrorWithServerResponseReason:(nullable NSString *)reason {
  1134. NSDictionary *userInfo;
  1135. if (reason.length) {
  1136. userInfo = @{
  1137. NSLocalizedFailureReasonErrorKey : reason,
  1138. };
  1139. }
  1140. return [self errorWithCode:FIRAuthInternalErrorCodeWeakPassword userInfo:userInfo];
  1141. }
  1142. + (NSError *)appNotAuthorizedError {
  1143. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotAuthorized];
  1144. }
  1145. + (NSError *)expiredActionCodeErrorWithMessage:(nullable NSString *)message {
  1146. return [self errorWithCode:FIRAuthInternalErrorCodeExpiredActionCode message:message];
  1147. }
  1148. + (NSError *)invalidActionCodeErrorWithMessage:(nullable NSString *)message {
  1149. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidActionCode message:message];
  1150. }
  1151. + (NSError *)invalidMessagePayloadErrorWithMessage:(nullable NSString *)message {
  1152. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidMessagePayload message:message];
  1153. }
  1154. + (NSError *)invalidSenderErrorWithMessage:(nullable NSString *)message {
  1155. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidSender message:message];
  1156. }
  1157. + (NSError *)invalidRecipientEmailErrorWithMessage:(nullable NSString *)message {
  1158. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidRecipientEmail message:message];
  1159. }
  1160. + (NSError *)missingIosBundleIDErrorWithMessage:(nullable NSString *)message {
  1161. return [self errorWithCode:FIRAuthinternalErrorCodeMissingIosBundleID message:message];
  1162. }
  1163. + (NSError *)missingAndroidPackageNameErrorWithMessage:(nullable NSString *)message {
  1164. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAndroidPackageName message:message];
  1165. }
  1166. + (NSError *)unauthorizedDomainErrorWithMessage:(nullable NSString *)message {
  1167. return [self errorWithCode:FIRAuthInternalErrorCodeUnauthorizedDomain message:message];
  1168. }
  1169. + (NSError *)invalidContinueURIErrorWithMessage:(nullable NSString *)message {
  1170. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidContinueURI message:message];
  1171. }
  1172. + (NSError *)missingContinueURIErrorWithMessage:(nullable NSString *)message {
  1173. return [self errorWithCode:FIRAuthInternalErrorCodeMissingContinueURI message:message];
  1174. }
  1175. + (NSError *)missingEmailErrorWithMessage:(nullable NSString *)message {
  1176. return [self errorWithCode:FIRAuthInternalErrorCodeMissingEmail message:message];
  1177. }
  1178. + (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message {
  1179. return [self errorWithCode:FIRAuthInternalErrorCodeMissingPhoneNumber message:message];
  1180. }
  1181. + (NSError *)invalidPhoneNumberErrorWithMessage:(nullable NSString *)message {
  1182. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidPhoneNumber message:message];
  1183. }
  1184. + (NSError *)missingVerificationCodeErrorWithMessage:(nullable NSString *)message {
  1185. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationCode message:message];
  1186. }
  1187. + (NSError *)invalidVerificationCodeErrorWithMessage:(nullable NSString *)message {
  1188. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationCode message:message];
  1189. }
  1190. + (NSError *)missingVerificationIDErrorWithMessage:(nullable NSString *)message {
  1191. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationID message:message];
  1192. }
  1193. + (NSError *)invalidVerificationIDErrorWithMessage:(nullable NSString *)message {
  1194. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationID message:message];
  1195. }
  1196. + (NSError *)sessionExpiredErrorWithMessage:(nullable NSString *)message {
  1197. return [self errorWithCode:FIRAuthInternalErrorCodeSessionExpired message:message];
  1198. }
  1199. + (NSError *)missingAppCredentialWithMessage:(nullable NSString *)message {
  1200. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppCredential message:message];
  1201. }
  1202. + (NSError *)invalidAppCredentialWithMessage:(nullable NSString *)message {
  1203. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAppCredential message:message];
  1204. }
  1205. + (NSError *)quotaExceededErrorWithMessage:(nullable NSString *)message {
  1206. return [self errorWithCode:FIRAuthInternalErrorCodeQuotaExceeded message:message];
  1207. }
  1208. + (NSError *)missingAppTokenErrorWithUnderlyingError:(nullable NSError *)underlyingError {
  1209. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppToken
  1210. underlyingError:underlyingError];
  1211. }
  1212. + (NSError *)localPlayerNotAuthenticatedError {
  1213. return [self errorWithCode:FIRAuthInternalErrorCodeLocalPlayerNotAuthenticated];
  1214. }
  1215. + (NSError *)gameKitNotLinkedError {
  1216. return [self errorWithCode:FIRAuthInternalErrorCodeGameKitNotLinked];
  1217. }
  1218. #if TARGET_OS_IOS
  1219. + (NSError *)secondFactorRequiredErrorWithPendingCredential:(NSString *)MFAPendingCredential
  1220. hints:(NSArray<FIRMultiFactorInfo *> *)hints
  1221. auth:(FIRAuth *)auth {
  1222. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1223. if (MFAPendingCredential && hints) {
  1224. FIRMultiFactorResolver *resolver =
  1225. [[FIRMultiFactorResolver alloc] initWithMFAPendingCredential:MFAPendingCredential
  1226. hints:hints
  1227. auth:auth];
  1228. userInfo[FIRAuthErrorUserInfoMultiFactorResolverKey] = resolver;
  1229. }
  1230. return [self errorWithCode:FIRAuthInternalErrorCodeSecondFactorRequired userInfo:userInfo];
  1231. }
  1232. #endif
  1233. + (NSError *)notificationNotForwardedError {
  1234. return [self errorWithCode:FIRAuthInternalErrorCodeNotificationNotForwarded];
  1235. }
  1236. + (NSError *)appNotVerifiedErrorWithMessage:(nullable NSString *)message {
  1237. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotVerified message:message];
  1238. }
  1239. + (NSError *)missingClientIdentifierErrorWithMessage:(nullable NSString *)message {
  1240. return [self errorWithCode:FIRAuthInternalErrorCodeMissingClientIdentifier message:message];
  1241. }
  1242. + (NSError *)missingClientTypeErrorWithMessage:(nullable NSString *)message {
  1243. return [self errorWithCode:FIRAuthInternalErrorCodeMissingClientType message:message];
  1244. }
  1245. + (NSError *)captchaCheckFailedErrorWithMessage:(nullable NSString *)message {
  1246. return [self errorWithCode:FIRAuthInternalErrorCodeCaptchaCheckFailed message:message];
  1247. }
  1248. + (NSError *)webContextAlreadyPresentedErrorWithMessage:(nullable NSString *)message {
  1249. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextAlreadyPresented message:message];
  1250. }
  1251. + (NSError *)webContextCancelledErrorWithMessage:(nullable NSString *)message {
  1252. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextCancelled message:message];
  1253. }
  1254. + (NSError *)appVerificationUserInteractionFailureWithReason:(NSString *)reason {
  1255. NSDictionary *userInfo;
  1256. if (reason.length) {
  1257. userInfo = @{
  1258. NSLocalizedFailureReasonErrorKey : reason,
  1259. };
  1260. }
  1261. return [self errorWithCode:FIRAuthInternalErrorCodeAppVerificationUserInteractionFailure
  1262. userInfo:userInfo];
  1263. }
  1264. + (NSError *)webSignInUserInteractionFailureWithReason:(nullable NSString *)reason {
  1265. NSDictionary *userInfo;
  1266. if (reason.length) {
  1267. userInfo = @{
  1268. NSLocalizedFailureReasonErrorKey : reason,
  1269. };
  1270. }
  1271. return [self errorWithCode:FIRAuthInternalErrorCodeWebSignInUserInteractionFailure
  1272. userInfo:userInfo];
  1273. }
  1274. + (nullable NSError *)URLResponseErrorWithCode:(NSString *)code
  1275. message:(nullable NSString *)message {
  1276. if ([code isEqualToString:kURLResponseErrorCodeInvalidClientID]) {
  1277. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidClientID message:message];
  1278. }
  1279. if ([code isEqualToString:kURLResponseErrorCodeNetworkRequestFailed]) {
  1280. return [self errorWithCode:FIRAuthInternalErrorCodeWebNetworkRequestFailed message:message];
  1281. }
  1282. if ([code isEqualToString:kURLResponseErrorCodeInternalError]) {
  1283. return [self errorWithCode:FIRAuthInternalErrorCodeWebInternalError message:message];
  1284. }
  1285. return nil;
  1286. }
  1287. + (NSError *)nullUserErrorWithMessage:(nullable NSString *)message {
  1288. return [self errorWithCode:FIRAuthInternalErrorCodeNullUser message:message];
  1289. }
  1290. + (NSError *)invalidProviderIDErrorWithMessage:(nullable NSString *)message {
  1291. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidProviderID message:message];
  1292. }
  1293. + (NSError *)invalidDynamicLinkDomainErrorWithMessage:(nullable NSString *)message {
  1294. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidDynamicLinkDomain message:message];
  1295. }
  1296. + (NSError *)missingOrInvalidNonceErrorWithMessage:(nullable NSString *)message {
  1297. return [self errorWithCode:FIRAuthInternalErrorCodeMissingOrInvalidNonce message:message];
  1298. }
  1299. + (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status {
  1300. NSString *failureReason = [NSString stringWithFormat:@"%@ (%li)", keychainFunction, (long)status];
  1301. return [self errorWithCode:FIRAuthInternalErrorCodeKeychainError
  1302. userInfo:@{
  1303. NSLocalizedFailureReasonErrorKey : failureReason,
  1304. }];
  1305. }
  1306. + (NSError *)tenantIDMismatchError {
  1307. return [self errorWithCode:FIRAuthInternalErrorCodeTenantIDMismatch];
  1308. }
  1309. + (NSError *)unsupportedTenantOperationError {
  1310. return [self errorWithCode:FIRAuthInternalErrorCodeUnsupportedTenantOperation];
  1311. }
  1312. + (NSError *)blockingCloudFunctionServerResponseWithMessage:(nullable NSString *)message {
  1313. if (message == nil) {
  1314. return [self errorWithCode:FIRAuthInternalErrorBlockingCloudFunctionError message:message];
  1315. }
  1316. NSString *jsonString =
  1317. [message stringByReplacingOccurrencesOfString:@"HTTP Cloud Function returned an error:"
  1318. withString:@""];
  1319. jsonString = [jsonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  1320. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  1321. NSError *jsonError;
  1322. NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData
  1323. options:0
  1324. error:&jsonError];
  1325. if (jsonError) {
  1326. return [self JSONSerializationErrorWithUnderlyingError:jsonError];
  1327. }
  1328. NSDictionary *errorDict = jsonDict[@"error"];
  1329. NSString *errorMessage = errorDict[@"message"];
  1330. return [self errorWithCode:FIRAuthInternalErrorBlockingCloudFunctionError message:errorMessage];
  1331. }
  1332. + (NSError *)recaptchaSDKNotLinkedError {
  1333. return [self errorWithCode:FIRAuthInternalErrorCodeRecaptchaSDKNotLinked
  1334. message:kFIRAuthErrorMessageRecaptchaSDKNotLinked];
  1335. }
  1336. @end
  1337. NS_ASSUME_NONNULL_END