FIRAuthErrorUtils.m 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  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. /** @var FIRAuthErrorDescription
  526. @brief The error descrioption, based on the error code.
  527. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  528. */
  529. static NSString *FIRAuthErrorDescription(FIRAuthErrorCode code) {
  530. switch (code) {
  531. case FIRAuthErrorCodeInvalidCustomToken:
  532. return kFIRAuthErrorMessageInvalidCustomToken;
  533. case FIRAuthErrorCodeCustomTokenMismatch:
  534. return kFIRAuthErrorMessageCustomTokenMismatch;
  535. case FIRAuthErrorCodeInvalidEmail:
  536. return kFIRAuthErrorMessageInvalidEmail;
  537. case FIRAuthErrorCodeInvalidCredential:
  538. return kFIRAuthErrorMessageInvalidCredential;
  539. case FIRAuthErrorCodeUserDisabled:
  540. return kFIRAuthErrorMessageUserDisabled;
  541. case FIRAuthErrorCodeEmailAlreadyInUse:
  542. return kFIRAuthErrorMessageEmailAlreadyInUse;
  543. case FIRAuthErrorCodeWrongPassword:
  544. return kFIRAuthErrorMessageWrongPassword;
  545. case FIRAuthErrorCodeTooManyRequests:
  546. return kFIRAuthErrorMessageTooManyRequests;
  547. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  548. return kFIRAuthErrorMessageAccountExistsWithDifferentCredential;
  549. case FIRAuthErrorCodeRequiresRecentLogin:
  550. return kFIRAuthErrorMessageRequiresRecentLogin;
  551. case FIRAuthErrorCodeProviderAlreadyLinked:
  552. return kFIRAuthErrorMessageProviderAlreadyLinked;
  553. case FIRAuthErrorCodeNoSuchProvider:
  554. return kFIRAuthErrorMessageNoSuchProvider;
  555. case FIRAuthErrorCodeInvalidUserToken:
  556. return kFIRAuthErrorMessageInvalidUserToken;
  557. case FIRAuthErrorCodeNetworkError:
  558. return kFIRAuthErrorMessageNetworkError;
  559. case FIRAuthErrorCodeKeychainError:
  560. return kFIRAuthErrorMessageKeychainError;
  561. case FIRAuthErrorCodeUserTokenExpired:
  562. return kFIRAuthErrorMessageUserTokenExpired;
  563. case FIRAuthErrorCodeUserNotFound:
  564. return kFIRAuthErrorMessageUserNotFound;
  565. case FIRAuthErrorCodeInvalidAPIKey:
  566. return kFIRAuthErrorMessageInvalidAPIKey;
  567. case FIRAuthErrorCodeCredentialAlreadyInUse:
  568. return kFIRAuthErrorMessageCredentialAlreadyInUse;
  569. case FIRAuthErrorCodeInternalError:
  570. return kFIRAuthErrorMessageInternalError;
  571. case FIRAuthErrorCodeUserMismatch:
  572. return FIRAuthErrorMessageUserMismatch;
  573. case FIRAuthErrorCodeOperationNotAllowed:
  574. return kFIRAuthErrorMessageOperationNotAllowed;
  575. case FIRAuthErrorCodeWeakPassword:
  576. return kFIRAuthErrorMessageWeakPassword;
  577. case FIRAuthErrorCodeAppNotAuthorized:
  578. return kFIRAuthErrorMessageAppNotAuthorized;
  579. case FIRAuthErrorCodeExpiredActionCode:
  580. return kFIRAuthErrorMessageExpiredActionCode;
  581. case FIRAuthErrorCodeInvalidActionCode:
  582. return kFIRAuthErrorMessageInvalidActionCode;
  583. case FIRAuthErrorCodeInvalidSender:
  584. return kFIRAuthErrorMessageInvalidSender;
  585. case FIRAuthErrorCodeInvalidMessagePayload:
  586. return kFIRAuthErrorMessageInvalidMessagePayload;
  587. case FIRAuthErrorCodeInvalidRecipientEmail:
  588. return kFIRAuthErrorMessageInvalidRecipientEmail;
  589. case FIRAuthErrorCodeMissingIosBundleID:
  590. return kFIRAuthErrorMessageMissingIosBundleID;
  591. case FIRAuthErrorCodeMissingAndroidPackageName:
  592. return kFIRAuthErrorMessageMissingAndroidPackageName;
  593. case FIRAuthErrorCodeUnauthorizedDomain:
  594. return kFIRAuthErrorMessageUnauthorizedDomain;
  595. case FIRAuthErrorCodeInvalidContinueURI:
  596. return kFIRAuthErrorMessageInvalidContinueURI;
  597. case FIRAuthErrorCodeMissingContinueURI:
  598. return kFIRAuthErrorMessageMissingContinueURI;
  599. case FIRAuthErrorCodeMissingEmail:
  600. return kFIRAuthErrorMessageMissingEmail;
  601. case FIRAuthErrorCodeMissingPhoneNumber:
  602. return kFIRAuthErrorMessageMissingPhoneNumber;
  603. case FIRAuthErrorCodeInvalidPhoneNumber:
  604. return kFIRAuthErrorMessageInvalidPhoneNumber;
  605. case FIRAuthErrorCodeMissingVerificationCode:
  606. return kFIRAuthErrorMessageMissingVerificationCode;
  607. case FIRAuthErrorCodeInvalidVerificationCode:
  608. return kFIRAuthErrorMessageInvalidVerificationCode;
  609. case FIRAuthErrorCodeMissingVerificationID:
  610. return kFIRAuthErrorMessageMissingVerificationID;
  611. case FIRAuthErrorCodeInvalidVerificationID:
  612. return kFIRAuthErrorMessageInvalidVerificationID;
  613. case FIRAuthErrorCodeSessionExpired:
  614. return kFIRAuthErrorMessageSessionExpired;
  615. case FIRAuthErrorCodeMissingAppCredential:
  616. return kFIRAuthErrorMessageMissingAppCredential;
  617. case FIRAuthErrorCodeInvalidAppCredential:
  618. return kFIRAuthErrorMessageInvalidAppCredential;
  619. case FIRAuthErrorCodeQuotaExceeded:
  620. return kFIRAuthErrorMessageQuotaExceeded;
  621. case FIRAuthErrorCodeMissingAppToken:
  622. return kFIRAuthErrorMessageMissingAppToken;
  623. case FIRAuthErrorCodeNotificationNotForwarded:
  624. return kFIRAuthErrorMessageNotificationNotForwarded;
  625. case FIRAuthErrorCodeAppNotVerified:
  626. return kFIRAuthErrorMessageAppNotVerified;
  627. case FIRAuthErrorCodeCaptchaCheckFailed:
  628. return kFIRAuthErrorMessageCaptchaCheckFailed;
  629. case FIRAuthErrorCodeWebContextAlreadyPresented:
  630. return kFIRAuthErrorMessageWebContextAlreadyPresented;
  631. case FIRAuthErrorCodeWebContextCancelled:
  632. return kFIRAuthErrorMessageWebContextCancelled;
  633. case FIRAuthErrorCodeInvalidClientID:
  634. return kFIRAuthErrorMessageInvalidClientID;
  635. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  636. return kFIRAuthErrorMessageAppVerificationUserInteractionFailure;
  637. case FIRAuthErrorCodeWebNetworkRequestFailed:
  638. return kFIRAuthErrorMessageWebRequestFailed;
  639. case FIRAuthErrorCodeNullUser:
  640. return kFIRAuthErrorMessageNullUser;
  641. case FIRAuthErrorCodeInvalidProviderID:
  642. return kFIRAuthErrorMessageInvalidProviderID;
  643. case FIRAuthErrorCodeInvalidDynamicLinkDomain:
  644. return kFIRAuthErrorMessageInvalidDynamicLinkDomain;
  645. case FIRAuthErrorCodeWebInternalError:
  646. return kFIRAuthErrorMessageWebInternalError;
  647. case FIRAuthErrorCodeWebSignInUserInteractionFailure:
  648. return kFIRAuthErrorMessageAppVerificationUserInteractionFailure;
  649. case FIRAuthErrorCodeMalformedJWT:
  650. return kFIRAuthErrorMessageMalformedJWT;
  651. case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
  652. return kFIRAuthErrorMessageLocalPlayerNotAuthenticated;
  653. case FIRAuthErrorCodeGameKitNotLinked:
  654. return kFIRAuthErrorMessageGameKitNotLinked;
  655. case FIRAuthErrorCodeSecondFactorRequired:
  656. return kFIRAuthErrorMessageSecondFactorRequired;
  657. case FIRAuthErrorCodeMissingMultiFactorSession:
  658. return FIRAuthErrorMessageMissingMultiFactorSession;
  659. case FIRAuthErrorCodeMissingMultiFactorInfo:
  660. return FIRAuthErrorMessageMissingMultiFactorInfo;
  661. case FIRAuthErrorCodeInvalidMultiFactorSession:
  662. return FIRAuthErrorMessageInvalidMultiFactorSession;
  663. case FIRAuthErrorCodeMultiFactorInfoNotFound:
  664. return FIRAuthErrorMessageMultiFactorInfoNotFound;
  665. case FIRAuthErrorCodeAdminRestrictedOperation:
  666. return FIRAuthErrorMessageAdminRestrictedOperation;
  667. case FIRAuthErrorCodeUnverifiedEmail:
  668. return FIRAuthErrorMessageUnverifiedEmail;
  669. case FIRAuthErrorCodeSecondFactorAlreadyEnrolled:
  670. return FIRAuthErrorMessageSecondFactorAlreadyEnrolled;
  671. case FIRAuthErrorCodeMaximumSecondFactorCountExceeded:
  672. return FIRAuthErrorMessageMaximumSecondFactorCountExceeded;
  673. case FIRAuthErrorCodeUnsupportedFirstFactor:
  674. return FIRAuthErrorMessageUnsupportedFirstFactor;
  675. case FIRAuthErrorCodeEmailChangeNeedsVerification:
  676. return FIRAuthErrorMessageEmailChangeNeedsVerification;
  677. case FIRAuthErrorCodeDynamicLinkNotActivated:
  678. return kFIRAuthErrorMessageDynamicLinkNotActivated;
  679. case FIRAuthErrorCodeRejectedCredential:
  680. return kFIRAuthErrorMessageRejectedCredential;
  681. case FIRAuthErrorCodeMissingClientIdentifier:
  682. return kFIRAuthErrorMessageMissingClientIdentifier;
  683. case FIRAuthErrorCodeMissingOrInvalidNonce:
  684. return kFIRAuthErrorMessageMissingOrInvalidNonce;
  685. case FIRAuthErrorCodeTenantIDMismatch:
  686. return kFIRAuthErrorMessageTenantIDMismatch;
  687. case FIRAuthErrorCodeUnsupportedTenantOperation:
  688. return kFIRAuthErrorMessageUnsupportedTenantOperation;
  689. case FIRAuthErrorCodeBlockingCloudFunctionError:
  690. return kFIRAuthErrorMessageBlockingCloudFunctionReturnedError;
  691. case FIRAuthErrorCodeRecaptchaNotEnabled:
  692. return kFIRAuthErrorMessageRecaptchaNotEnabled;
  693. case FIRAuthErrorCodeMissingRecaptchaToken:
  694. return kFIRAuthErrorMessageMissingRecaptchaToken;
  695. case FIRAuthErrorCodeInvalidRecaptchaToken:
  696. return kFIRAuthErrorMessageInvalidRecaptchaToken;
  697. case FIRAuthErrorCodeInvalidRecaptchaAction:
  698. return kFIRAuthErrorMessageInvalidRecaptchaAction;
  699. case FIRAuthErrorCodeMissingClientType:
  700. return kFIRAuthErrorMessageMissingClientType;
  701. case FIRAuthErrorCodeMissingRecaptchaVersion:
  702. return kFIRAuthErrorMessageMissingRecaptchaVersion;
  703. case FIRAuthErrorCodeInvalidRecaptchaVersion:
  704. return kFIRAuthErrorMessageInvalidRecaptchaVersion;
  705. case FIRAuthErrorCodeInvalidReqType:
  706. return kFIRAuthErrorMessageInvalidReqType;
  707. case FIRAuthErrorCodeRecaptchaSDKNotLinked:
  708. return kFIRAuthErrorMessageRecaptchaSDKNotLinked;
  709. }
  710. }
  711. /** @var FIRAuthErrorCodeString
  712. @brief The error short string, based on the error code.
  713. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  714. */
  715. static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
  716. switch (code) {
  717. case FIRAuthErrorCodeInvalidCustomToken:
  718. return @"ERROR_INVALID_CUSTOM_TOKEN";
  719. case FIRAuthErrorCodeCustomTokenMismatch:
  720. return @"ERROR_CUSTOM_TOKEN_MISMATCH";
  721. case FIRAuthErrorCodeInvalidEmail:
  722. return @"ERROR_INVALID_EMAIL";
  723. case FIRAuthErrorCodeInvalidCredential:
  724. return @"ERROR_INVALID_CREDENTIAL";
  725. case FIRAuthErrorCodeUserDisabled:
  726. return @"ERROR_USER_DISABLED";
  727. case FIRAuthErrorCodeEmailAlreadyInUse:
  728. return @"ERROR_EMAIL_ALREADY_IN_USE";
  729. case FIRAuthErrorCodeWrongPassword:
  730. return @"ERROR_WRONG_PASSWORD";
  731. case FIRAuthErrorCodeTooManyRequests:
  732. return @"ERROR_TOO_MANY_REQUESTS";
  733. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  734. return @"ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL";
  735. case FIRAuthErrorCodeRequiresRecentLogin:
  736. return @"ERROR_REQUIRES_RECENT_LOGIN";
  737. case FIRAuthErrorCodeProviderAlreadyLinked:
  738. return @"ERROR_PROVIDER_ALREADY_LINKED";
  739. case FIRAuthErrorCodeNoSuchProvider:
  740. return @"ERROR_NO_SUCH_PROVIDER";
  741. case FIRAuthErrorCodeInvalidUserToken:
  742. return @"ERROR_INVALID_USER_TOKEN";
  743. case FIRAuthErrorCodeNetworkError:
  744. return @"ERROR_NETWORK_REQUEST_FAILED";
  745. case FIRAuthErrorCodeKeychainError:
  746. return @"ERROR_KEYCHAIN_ERROR";
  747. case FIRAuthErrorCodeMissingClientType:
  748. return @"ERROR_MISSING_CLIENT_TYPE";
  749. case FIRAuthErrorCodeUserTokenExpired:
  750. return @"ERROR_USER_TOKEN_EXPIRED";
  751. case FIRAuthErrorCodeUserNotFound:
  752. return @"ERROR_USER_NOT_FOUND";
  753. case FIRAuthErrorCodeInvalidAPIKey:
  754. return @"ERROR_INVALID_API_KEY";
  755. case FIRAuthErrorCodeCredentialAlreadyInUse:
  756. return @"ERROR_CREDENTIAL_ALREADY_IN_USE";
  757. case FIRAuthErrorCodeInternalError:
  758. return @"ERROR_INTERNAL_ERROR";
  759. case FIRAuthErrorCodeUserMismatch:
  760. return @"ERROR_USER_MISMATCH";
  761. case FIRAuthErrorCodeOperationNotAllowed:
  762. return @"ERROR_OPERATION_NOT_ALLOWED";
  763. case FIRAuthErrorCodeWeakPassword:
  764. return @"ERROR_WEAK_PASSWORD";
  765. case FIRAuthErrorCodeAppNotAuthorized:
  766. return @"ERROR_APP_NOT_AUTHORIZED";
  767. case FIRAuthErrorCodeExpiredActionCode:
  768. return @"ERROR_EXPIRED_ACTION_CODE";
  769. case FIRAuthErrorCodeInvalidActionCode:
  770. return @"ERROR_INVALID_ACTION_CODE";
  771. case FIRAuthErrorCodeInvalidMessagePayload:
  772. return @"ERROR_INVALID_MESSAGE_PAYLOAD";
  773. case FIRAuthErrorCodeInvalidSender:
  774. return @"ERROR_INVALID_SENDER";
  775. case FIRAuthErrorCodeInvalidRecipientEmail:
  776. return @"ERROR_INVALID_RECIPIENT_EMAIL";
  777. case FIRAuthErrorCodeMissingIosBundleID:
  778. return @"ERROR_MISSING_IOS_BUNDLE_ID";
  779. case FIRAuthErrorCodeMissingAndroidPackageName:
  780. return @"ERROR_MISSING_ANDROID_PKG_NAME";
  781. case FIRAuthErrorCodeUnauthorizedDomain:
  782. return @"ERROR_UNAUTHORIZED_DOMAIN";
  783. case FIRAuthErrorCodeInvalidContinueURI:
  784. return @"ERROR_INVALID_CONTINUE_URI";
  785. case FIRAuthErrorCodeMissingContinueURI:
  786. return @"ERROR_MISSING_CONTINUE_URI";
  787. case FIRAuthErrorCodeMissingEmail:
  788. return @"ERROR_MISSING_EMAIL";
  789. case FIRAuthErrorCodeMissingPhoneNumber:
  790. return @"ERROR_MISSING_PHONE_NUMBER";
  791. case FIRAuthErrorCodeInvalidPhoneNumber:
  792. return @"ERROR_INVALID_PHONE_NUMBER";
  793. case FIRAuthErrorCodeMissingVerificationCode:
  794. return @"ERROR_MISSING_VERIFICATION_CODE";
  795. case FIRAuthErrorCodeInvalidVerificationCode:
  796. return @"ERROR_INVALID_VERIFICATION_CODE";
  797. case FIRAuthErrorCodeMissingVerificationID:
  798. return @"ERROR_MISSING_VERIFICATION_ID";
  799. case FIRAuthErrorCodeInvalidVerificationID:
  800. return @"ERROR_INVALID_VERIFICATION_ID";
  801. case FIRAuthErrorCodeSessionExpired:
  802. return @"ERROR_SESSION_EXPIRED";
  803. case FIRAuthErrorCodeMissingAppCredential:
  804. return @"MISSING_APP_CREDENTIAL";
  805. case FIRAuthErrorCodeInvalidAppCredential:
  806. return @"INVALID_APP_CREDENTIAL";
  807. case FIRAuthErrorCodeQuotaExceeded:
  808. return @"ERROR_QUOTA_EXCEEDED";
  809. case FIRAuthErrorCodeMissingAppToken:
  810. return @"ERROR_MISSING_APP_TOKEN";
  811. case FIRAuthErrorCodeNotificationNotForwarded:
  812. return @"ERROR_NOTIFICATION_NOT_FORWARDED";
  813. case FIRAuthErrorCodeAppNotVerified:
  814. return @"ERROR_APP_NOT_VERIFIED";
  815. case FIRAuthErrorCodeCaptchaCheckFailed:
  816. return @"ERROR_CAPTCHA_CHECK_FAILED";
  817. case FIRAuthErrorCodeWebContextAlreadyPresented:
  818. return @"ERROR_WEB_CONTEXT_ALREADY_PRESENTED";
  819. case FIRAuthErrorCodeWebContextCancelled:
  820. return @"ERROR_WEB_CONTEXT_CANCELLED";
  821. case FIRAuthErrorCodeInvalidClientID:
  822. return @"ERROR_INVALID_CLIENT_ID";
  823. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  824. return @"ERROR_APP_VERIFICATION_FAILED";
  825. case FIRAuthErrorCodeWebNetworkRequestFailed:
  826. return @"ERROR_WEB_NETWORK_REQUEST_FAILED";
  827. case FIRAuthErrorCodeNullUser:
  828. return @"ERROR_NULL_USER";
  829. case FIRAuthErrorCodeInvalidProviderID:
  830. return @"ERROR_INVALID_PROVIDER_ID";
  831. case FIRAuthErrorCodeInvalidDynamicLinkDomain:
  832. return @"ERROR_INVALID_DYNAMIC_LINK_DOMAIN";
  833. case FIRAuthErrorCodeWebInternalError:
  834. return @"ERROR_WEB_INTERNAL_ERROR";
  835. case FIRAuthErrorCodeWebSignInUserInteractionFailure:
  836. return @"ERROR_WEB_USER_INTERACTION_FAILURE";
  837. case FIRAuthErrorCodeMalformedJWT:
  838. return @"ERROR_MALFORMED_JWT";
  839. case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
  840. return @"ERROR_LOCAL_PLAYER_NOT_AUTHENTICATED";
  841. case FIRAuthErrorCodeGameKitNotLinked:
  842. return @"ERROR_GAME_KIT_NOT_LINKED";
  843. case FIRAuthErrorCodeSecondFactorRequired:
  844. return @"ERROR_SECOND_FACTOR_REQUIRED";
  845. case FIRAuthErrorCodeMissingMultiFactorSession:
  846. return @"ERROR_MISSING_MULTI_FACTOR_SESSION";
  847. case FIRAuthErrorCodeMissingMultiFactorInfo:
  848. return @"ERROR_MISSING_MULTI_FACTOR_INFO";
  849. case FIRAuthErrorCodeInvalidMultiFactorSession:
  850. return @"ERROR_INVALID_MULTI_FACTOR_SESSION";
  851. case FIRAuthErrorCodeMultiFactorInfoNotFound:
  852. return @"ERROR_MULTI_FACTOR_INFO_NOT_FOUND";
  853. case FIRAuthErrorCodeAdminRestrictedOperation:
  854. return @"ERROR_ADMIN_RESTRICTED_OPERATION";
  855. case FIRAuthErrorCodeUnverifiedEmail:
  856. return @"ERROR_UNVERIFIED_EMAIL";
  857. case FIRAuthErrorCodeSecondFactorAlreadyEnrolled:
  858. return @"ERROR_SECOND_FACTOR_ALREADY_ENROLLED";
  859. case FIRAuthErrorCodeMaximumSecondFactorCountExceeded:
  860. return @"ERROR_MAXIMUM_SECOND_FACTOR_COUNT_EXCEEDED";
  861. case FIRAuthErrorCodeUnsupportedFirstFactor:
  862. return @"ERROR_UNSUPPORTED_FIRST_FACTOR";
  863. case FIRAuthErrorCodeEmailChangeNeedsVerification:
  864. return @"ERROR_EMAIL_CHANGE_NEEDS_VERIFICATION";
  865. case FIRAuthErrorCodeDynamicLinkNotActivated:
  866. return @"ERROR_DYNAMIC_LINK_NOT_ACTIVATED";
  867. case FIRAuthErrorCodeRejectedCredential:
  868. return @"ERROR_REJECTED_CREDENTIAL";
  869. case FIRAuthErrorCodeMissingClientIdentifier:
  870. return @"ERROR_MISSING_CLIENT_IDENTIFIER";
  871. case FIRAuthErrorCodeMissingOrInvalidNonce:
  872. return @"ERROR_MISSING_OR_INVALID_NONCE";
  873. case FIRAuthErrorCodeTenantIDMismatch:
  874. return @"ERROR_TENANT_ID_MISMATCH";
  875. case FIRAuthErrorCodeUnsupportedTenantOperation:
  876. return @"ERROR_UNSUPPORTED_TENANT_OPERATION";
  877. case FIRAuthErrorCodeBlockingCloudFunctionError:
  878. return @"ERROR_BLOCKING_CLOUD_FUNCTION_RETURNED_ERROR";
  879. case FIRAuthErrorCodeRecaptchaNotEnabled:
  880. return @"ERROR_RECAPTCHA_NOT_ENABLED";
  881. case FIRAuthErrorCodeMissingRecaptchaToken:
  882. return @"ERROR_MISSING_RECAPTCHA_TOKEN";
  883. case FIRAuthErrorCodeInvalidRecaptchaToken:
  884. return @"ERROR_INVALID_RECAPTCHA_TOKEN";
  885. case FIRAuthErrorCodeInvalidRecaptchaAction:
  886. return @"ERROR_INVALID_RECAPTCHA_ACTION";
  887. case FIRAuthErrorCodeMissingRecaptchaVersion:
  888. return @"ERROR_MISSING_RECAPTCHA_VERSION";
  889. case FIRAuthErrorCodeInvalidRecaptchaVersion:
  890. return @"ERROR_INVALID_RECAPTCHA_VERSION";
  891. case FIRAuthErrorCodeInvalidReqType:
  892. return @"ERROR_INVALID_REQ_TYPE";
  893. case FIRAuthErrorCodeRecaptchaSDKNotLinked:
  894. return @"ERROR_RECAPTCHA_SDK_NOT_LINKED";
  895. }
  896. }
  897. @implementation FIRAuthErrorUtils
  898. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code {
  899. return [self errorWithCode:code message:nil];
  900. }
  901. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code message:(nullable NSString *)message {
  902. NSDictionary *userInfo = nil;
  903. if (message.length) {
  904. userInfo = @{NSLocalizedDescriptionKey : message};
  905. }
  906. return [self errorWithCode:code userInfo:userInfo];
  907. }
  908. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  909. underlyingError:(nullable NSError *)underlyingError {
  910. NSDictionary *errorUserInfo;
  911. if (underlyingError) {
  912. errorUserInfo = @{NSUnderlyingErrorKey : underlyingError};
  913. }
  914. return [self errorWithCode:code userInfo:errorUserInfo];
  915. }
  916. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  917. userInfo:(nullable NSDictionary *)userInfo {
  918. BOOL isPublic = (code & FIRAuthPublicErrorCodeFlag) == FIRAuthPublicErrorCodeFlag;
  919. if (isPublic) {
  920. // This is a public error. Return it as a public error and add a description.
  921. NSInteger errorCode = code & ~FIRAuthPublicErrorCodeFlag;
  922. NSMutableDictionary *errorUserInfo = [NSMutableDictionary dictionary];
  923. if (userInfo) {
  924. [errorUserInfo addEntriesFromDictionary:userInfo];
  925. }
  926. if (!errorUserInfo[NSLocalizedDescriptionKey]) {
  927. errorUserInfo[NSLocalizedDescriptionKey] = FIRAuthErrorDescription(errorCode);
  928. }
  929. errorUserInfo[FIRAuthErrorUserInfoNameKey] = FIRAuthErrorCodeString(errorCode);
  930. return [NSError errorWithDomain:FIRAuthErrorDomain code:errorCode userInfo:errorUserInfo];
  931. } else {
  932. // This is an internal error. Wrap it in an internal error.
  933. NSError *error = [NSError errorWithDomain:FIRAuthInternalErrorDomain
  934. code:code
  935. userInfo:userInfo];
  936. return [self errorWithCode:FIRAuthInternalErrorCodeInternalError underlyingError:error];
  937. }
  938. }
  939. + (NSError *)RPCRequestEncodingErrorWithUnderlyingError:(NSError *)underlyingError {
  940. return [self errorWithCode:FIRAuthInternalErrorCodeRPCRequestEncodingError
  941. underlyingError:underlyingError];
  942. }
  943. + (NSError *)JSONSerializationErrorForUnencodableType {
  944. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError];
  945. }
  946. + (NSError *)JSONSerializationErrorWithUnderlyingError:(NSError *)underlyingError {
  947. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError
  948. underlyingError:underlyingError];
  949. }
  950. + (NSError *)networkErrorWithUnderlyingError:(NSError *)underlyingError {
  951. return [self errorWithCode:FIRAuthInternalErrorCodeNetworkError underlyingError:underlyingError];
  952. }
  953. + (NSError *)unexpectedErrorResponseWithData:(NSData *)data
  954. underlyingError:(NSError *)underlyingError {
  955. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  956. if (data) {
  957. userInfo[FIRAuthErrorUserInfoDataKey] = data;
  958. }
  959. if (underlyingError) {
  960. userInfo[NSUnderlyingErrorKey] = underlyingError;
  961. }
  962. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse
  963. userInfo:[userInfo copy]];
  964. }
  965. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse {
  966. NSDictionary *userInfo;
  967. if (deserializedResponse) {
  968. userInfo = @{
  969. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse,
  970. };
  971. }
  972. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse userInfo:userInfo];
  973. }
  974. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse
  975. underlyingError:(NSError *)underlyingError {
  976. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  977. if (deserializedResponse) {
  978. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  979. }
  980. if (underlyingError) {
  981. userInfo[NSUnderlyingErrorKey] = underlyingError;
  982. }
  983. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse
  984. userInfo:[userInfo copy]];
  985. }
  986. + (NSError *)malformedJWTErrorWithToken:(NSString *)token
  987. underlyingError:(NSError *_Nullable)underlyingError {
  988. NSMutableDictionary *userInfo =
  989. [NSMutableDictionary dictionaryWithObject:kFIRAuthErrorMessageMalformedJWT
  990. forKey:NSLocalizedDescriptionKey];
  991. [userInfo setObject:token forKey:FIRAuthErrorUserInfoDataKey];
  992. if (underlyingError != nil) {
  993. [userInfo setObject:underlyingError forKey:NSUnderlyingErrorKey];
  994. }
  995. return [self errorWithCode:FIRAuthInternalErrorCodeMalformedJWT userInfo:[userInfo copy]];
  996. }
  997. + (NSError *)unexpectedResponseWithData:(NSData *)data underlyingError:(NSError *)underlyingError {
  998. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  999. if (data) {
  1000. userInfo[FIRAuthErrorUserInfoDataKey] = data;
  1001. }
  1002. if (underlyingError) {
  1003. userInfo[NSUnderlyingErrorKey] = underlyingError;
  1004. }
  1005. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:[userInfo copy]];
  1006. }
  1007. + (NSError *)unexpectedResponseWithDeserializedResponse:(id)deserializedResponse {
  1008. NSDictionary *userInfo;
  1009. if (deserializedResponse) {
  1010. userInfo = @{
  1011. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse,
  1012. };
  1013. }
  1014. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:userInfo];
  1015. }
  1016. + (NSError *)unexpectedResponseWithDeserializedResponse:(nullable id)deserializedResponse
  1017. underlyingError:(NSError *)underlyingError {
  1018. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1019. if (deserializedResponse) {
  1020. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  1021. }
  1022. if (underlyingError) {
  1023. userInfo[NSUnderlyingErrorKey] = underlyingError;
  1024. }
  1025. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:[userInfo copy]];
  1026. }
  1027. + (NSError *)RPCResponseDecodingErrorWithDeserializedResponse:(id)deserializedResponse
  1028. underlyingError:(NSError *)underlyingError {
  1029. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1030. if (deserializedResponse) {
  1031. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  1032. }
  1033. if (underlyingError) {
  1034. userInfo[NSUnderlyingErrorKey] = underlyingError;
  1035. }
  1036. return [self errorWithCode:FIRAuthInternalErrorCodeRPCResponseDecodingError
  1037. userInfo:[userInfo copy]];
  1038. }
  1039. + (NSError *)emailAlreadyInUseErrorWithEmail:(nullable NSString *)email {
  1040. NSDictionary *userInfo;
  1041. if (email.length) {
  1042. userInfo = @{
  1043. FIRAuthErrorUserInfoEmailKey : email,
  1044. };
  1045. }
  1046. return [self errorWithCode:FIRAuthInternalErrorCodeEmailAlreadyInUse userInfo:userInfo];
  1047. }
  1048. + (NSError *)userDisabledErrorWithMessage:(nullable NSString *)message {
  1049. return [self errorWithCode:FIRAuthInternalErrorCodeUserDisabled message:message];
  1050. }
  1051. + (NSError *)wrongPasswordErrorWithMessage:(nullable NSString *)message {
  1052. return [self errorWithCode:FIRAuthInternalErrorCodeWrongPassword message:message];
  1053. }
  1054. + (NSError *)tooManyRequestsErrorWithMessage:(nullable NSString *)message {
  1055. return [self errorWithCode:FIRAuthInternalErrorCodeTooManyRequests message:message];
  1056. }
  1057. + (NSError *)invalidCustomTokenErrorWithMessage:(nullable NSString *)message {
  1058. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCustomToken message:message];
  1059. }
  1060. + (NSError *)customTokenMistmatchErrorWithMessage:(nullable NSString *)message {
  1061. return [self errorWithCode:FIRAuthInternalErrorCodeCustomTokenMismatch message:message];
  1062. }
  1063. + (NSError *)invalidCredentialErrorWithMessage:(nullable NSString *)message {
  1064. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCredential message:message];
  1065. }
  1066. + (NSError *)requiresRecentLoginErrorWithMessage:(nullable NSString *)message {
  1067. return [self errorWithCode:FIRAuthInternalErrorCodeRequiresRecentLogin message:message];
  1068. }
  1069. + (NSError *)invalidUserTokenErrorWithMessage:(nullable NSString *)message {
  1070. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidUserToken message:message];
  1071. }
  1072. + (NSError *)invalidEmailErrorWithMessage:(nullable NSString *)message {
  1073. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidEmail message:message];
  1074. }
  1075. + (NSError *)accountExistsWithDifferentCredentialErrorWithEmail:(nullable NSString *)email
  1076. updatedCredential:
  1077. (nullable FIRAuthCredential *)updatedCredential {
  1078. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1079. if (email) {
  1080. userInfo[FIRAuthErrorUserInfoEmailKey] = email;
  1081. }
  1082. if (updatedCredential) {
  1083. userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey] = updatedCredential;
  1084. }
  1085. return [self errorWithCode:FIRAuthInternalErrorCodeAccountExistsWithDifferentCredential
  1086. userInfo:userInfo];
  1087. }
  1088. + (NSError *)providerAlreadyLinkedError {
  1089. return [self errorWithCode:FIRAuthInternalErrorCodeProviderAlreadyLinked];
  1090. }
  1091. + (NSError *)noSuchProviderError {
  1092. return [self errorWithCode:FIRAuthInternalErrorCodeNoSuchProvider];
  1093. }
  1094. + (NSError *)userTokenExpiredErrorWithMessage:(nullable NSString *)message {
  1095. return [self errorWithCode:FIRAuthInternalErrorCodeUserTokenExpired message:message];
  1096. }
  1097. + (NSError *)userNotFoundErrorWithMessage:(nullable NSString *)message {
  1098. return [self errorWithCode:FIRAuthInternalErrorCodeUserNotFound message:message];
  1099. }
  1100. + (NSError *)invalidAPIKeyError {
  1101. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAPIKey];
  1102. }
  1103. + (NSError *)userMismatchError {
  1104. return [self errorWithCode:FIRAuthInternalErrorCodeUserMismatch];
  1105. }
  1106. + (NSError *)credentialAlreadyInUseErrorWithMessage:(nullable NSString *)message
  1107. credential:(nullable FIRAuthCredential *)credential
  1108. email:(nullable NSString *)email {
  1109. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1110. if (credential) {
  1111. userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey] = credential;
  1112. }
  1113. if (email.length) {
  1114. userInfo[FIRAuthErrorUserInfoEmailKey] = email;
  1115. }
  1116. if (userInfo.count) {
  1117. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse userInfo:userInfo];
  1118. }
  1119. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse message:message];
  1120. }
  1121. + (NSError *)operationNotAllowedErrorWithMessage:(nullable NSString *)message {
  1122. return [self errorWithCode:FIRAuthInternalErrorCodeOperationNotAllowed message:message];
  1123. }
  1124. + (NSError *)weakPasswordErrorWithServerResponseReason:(nullable NSString *)reason {
  1125. NSDictionary *userInfo;
  1126. if (reason.length) {
  1127. userInfo = @{
  1128. NSLocalizedFailureReasonErrorKey : reason,
  1129. };
  1130. }
  1131. return [self errorWithCode:FIRAuthInternalErrorCodeWeakPassword userInfo:userInfo];
  1132. }
  1133. + (NSError *)appNotAuthorizedError {
  1134. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotAuthorized];
  1135. }
  1136. + (NSError *)expiredActionCodeErrorWithMessage:(nullable NSString *)message {
  1137. return [self errorWithCode:FIRAuthInternalErrorCodeExpiredActionCode message:message];
  1138. }
  1139. + (NSError *)invalidActionCodeErrorWithMessage:(nullable NSString *)message {
  1140. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidActionCode message:message];
  1141. }
  1142. + (NSError *)invalidMessagePayloadErrorWithMessage:(nullable NSString *)message {
  1143. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidMessagePayload message:message];
  1144. }
  1145. + (NSError *)invalidSenderErrorWithMessage:(nullable NSString *)message {
  1146. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidSender message:message];
  1147. }
  1148. + (NSError *)invalidRecipientEmailErrorWithMessage:(nullable NSString *)message {
  1149. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidRecipientEmail message:message];
  1150. }
  1151. + (NSError *)missingIosBundleIDErrorWithMessage:(nullable NSString *)message {
  1152. return [self errorWithCode:FIRAuthinternalErrorCodeMissingIosBundleID message:message];
  1153. }
  1154. + (NSError *)missingAndroidPackageNameErrorWithMessage:(nullable NSString *)message {
  1155. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAndroidPackageName message:message];
  1156. }
  1157. + (NSError *)unauthorizedDomainErrorWithMessage:(nullable NSString *)message {
  1158. return [self errorWithCode:FIRAuthInternalErrorCodeUnauthorizedDomain message:message];
  1159. }
  1160. + (NSError *)invalidContinueURIErrorWithMessage:(nullable NSString *)message {
  1161. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidContinueURI message:message];
  1162. }
  1163. + (NSError *)missingContinueURIErrorWithMessage:(nullable NSString *)message {
  1164. return [self errorWithCode:FIRAuthInternalErrorCodeMissingContinueURI message:message];
  1165. }
  1166. + (NSError *)missingEmailErrorWithMessage:(nullable NSString *)message {
  1167. return [self errorWithCode:FIRAuthInternalErrorCodeMissingEmail message:message];
  1168. }
  1169. + (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message {
  1170. return [self errorWithCode:FIRAuthInternalErrorCodeMissingPhoneNumber message:message];
  1171. }
  1172. + (NSError *)invalidPhoneNumberErrorWithMessage:(nullable NSString *)message {
  1173. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidPhoneNumber message:message];
  1174. }
  1175. + (NSError *)missingVerificationCodeErrorWithMessage:(nullable NSString *)message {
  1176. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationCode message:message];
  1177. }
  1178. + (NSError *)invalidVerificationCodeErrorWithMessage:(nullable NSString *)message {
  1179. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationCode message:message];
  1180. }
  1181. + (NSError *)missingVerificationIDErrorWithMessage:(nullable NSString *)message {
  1182. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationID message:message];
  1183. }
  1184. + (NSError *)invalidVerificationIDErrorWithMessage:(nullable NSString *)message {
  1185. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationID message:message];
  1186. }
  1187. + (NSError *)sessionExpiredErrorWithMessage:(nullable NSString *)message {
  1188. return [self errorWithCode:FIRAuthInternalErrorCodeSessionExpired message:message];
  1189. }
  1190. + (NSError *)missingAppCredentialWithMessage:(nullable NSString *)message {
  1191. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppCredential message:message];
  1192. }
  1193. + (NSError *)invalidAppCredentialWithMessage:(nullable NSString *)message {
  1194. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAppCredential message:message];
  1195. }
  1196. + (NSError *)quotaExceededErrorWithMessage:(nullable NSString *)message {
  1197. return [self errorWithCode:FIRAuthInternalErrorCodeQuotaExceeded message:message];
  1198. }
  1199. + (NSError *)missingAppTokenErrorWithUnderlyingError:(nullable NSError *)underlyingError {
  1200. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppToken
  1201. underlyingError:underlyingError];
  1202. }
  1203. + (NSError *)localPlayerNotAuthenticatedError {
  1204. return [self errorWithCode:FIRAuthInternalErrorCodeLocalPlayerNotAuthenticated];
  1205. }
  1206. + (NSError *)gameKitNotLinkedError {
  1207. return [self errorWithCode:FIRAuthInternalErrorCodeGameKitNotLinked];
  1208. }
  1209. #if TARGET_OS_IOS
  1210. + (NSError *)secondFactorRequiredErrorWithPendingCredential:(NSString *)MFAPendingCredential
  1211. hints:(NSArray<FIRMultiFactorInfo *> *)hints
  1212. auth:(FIRAuth *)auth {
  1213. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  1214. if (MFAPendingCredential && hints) {
  1215. FIRMultiFactorResolver *resolver =
  1216. [[FIRMultiFactorResolver alloc] initWithMFAPendingCredential:MFAPendingCredential
  1217. hints:hints
  1218. auth:auth];
  1219. userInfo[FIRAuthErrorUserInfoMultiFactorResolverKey] = resolver;
  1220. }
  1221. return [self errorWithCode:FIRAuthInternalErrorCodeSecondFactorRequired userInfo:userInfo];
  1222. }
  1223. #endif
  1224. + (NSError *)notificationNotForwardedError {
  1225. return [self errorWithCode:FIRAuthInternalErrorCodeNotificationNotForwarded];
  1226. }
  1227. + (NSError *)appNotVerifiedErrorWithMessage:(nullable NSString *)message {
  1228. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotVerified message:message];
  1229. }
  1230. + (NSError *)missingClientIdentifierErrorWithMessage:(nullable NSString *)message {
  1231. return [self errorWithCode:FIRAuthInternalErrorCodeMissingClientIdentifier message:message];
  1232. }
  1233. + (NSError *)missingClientTypeErrorWithMessage:(nullable NSString *)message {
  1234. return [self errorWithCode:FIRAuthInternalErrorCodeMissingClientType message:message];
  1235. }
  1236. + (NSError *)captchaCheckFailedErrorWithMessage:(nullable NSString *)message {
  1237. return [self errorWithCode:FIRAuthInternalErrorCodeCaptchaCheckFailed message:message];
  1238. }
  1239. + (NSError *)webContextAlreadyPresentedErrorWithMessage:(nullable NSString *)message {
  1240. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextAlreadyPresented message:message];
  1241. }
  1242. + (NSError *)webContextCancelledErrorWithMessage:(nullable NSString *)message {
  1243. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextCancelled message:message];
  1244. }
  1245. + (NSError *)appVerificationUserInteractionFailureWithReason:(NSString *)reason {
  1246. NSDictionary *userInfo;
  1247. if (reason.length) {
  1248. userInfo = @{
  1249. NSLocalizedFailureReasonErrorKey : reason,
  1250. };
  1251. }
  1252. return [self errorWithCode:FIRAuthInternalErrorCodeAppVerificationUserInteractionFailure
  1253. userInfo:userInfo];
  1254. }
  1255. + (NSError *)webSignInUserInteractionFailureWithReason:(nullable NSString *)reason {
  1256. NSDictionary *userInfo;
  1257. if (reason.length) {
  1258. userInfo = @{
  1259. NSLocalizedFailureReasonErrorKey : reason,
  1260. };
  1261. }
  1262. return [self errorWithCode:FIRAuthInternalErrorCodeWebSignInUserInteractionFailure
  1263. userInfo:userInfo];
  1264. }
  1265. + (nullable NSError *)URLResponseErrorWithCode:(NSString *)code
  1266. message:(nullable NSString *)message {
  1267. if ([code isEqualToString:kURLResponseErrorCodeInvalidClientID]) {
  1268. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidClientID message:message];
  1269. }
  1270. if ([code isEqualToString:kURLResponseErrorCodeNetworkRequestFailed]) {
  1271. return [self errorWithCode:FIRAuthInternalErrorCodeWebNetworkRequestFailed message:message];
  1272. }
  1273. if ([code isEqualToString:kURLResponseErrorCodeInternalError]) {
  1274. return [self errorWithCode:FIRAuthInternalErrorCodeWebInternalError message:message];
  1275. }
  1276. return nil;
  1277. }
  1278. + (NSError *)nullUserErrorWithMessage:(nullable NSString *)message {
  1279. return [self errorWithCode:FIRAuthInternalErrorCodeNullUser message:message];
  1280. }
  1281. + (NSError *)invalidProviderIDErrorWithMessage:(nullable NSString *)message {
  1282. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidProviderID message:message];
  1283. }
  1284. + (NSError *)invalidDynamicLinkDomainErrorWithMessage:(nullable NSString *)message {
  1285. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidDynamicLinkDomain message:message];
  1286. }
  1287. + (NSError *)missingOrInvalidNonceErrorWithMessage:(nullable NSString *)message {
  1288. return [self errorWithCode:FIRAuthInternalErrorCodeMissingOrInvalidNonce message:message];
  1289. }
  1290. + (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status {
  1291. NSString *failureReason = [NSString stringWithFormat:@"%@ (%li)", keychainFunction, (long)status];
  1292. return [self errorWithCode:FIRAuthInternalErrorCodeKeychainError
  1293. userInfo:@{
  1294. NSLocalizedFailureReasonErrorKey : failureReason,
  1295. }];
  1296. }
  1297. + (NSError *)tenantIDMismatchError {
  1298. return [self errorWithCode:FIRAuthInternalErrorCodeTenantIDMismatch];
  1299. }
  1300. + (NSError *)unsupportedTenantOperationError {
  1301. return [self errorWithCode:FIRAuthInternalErrorCodeUnsupportedTenantOperation];
  1302. }
  1303. + (NSError *)blockingCloudFunctionServerResponseWithMessage:(nullable NSString *)message {
  1304. if (message == nil) {
  1305. return [self errorWithCode:FIRAuthInternalErrorBlockingCloudFunctionError message:message];
  1306. }
  1307. NSString *jsonString =
  1308. [message stringByReplacingOccurrencesOfString:@"HTTP Cloud Function returned an error:"
  1309. withString:@""];
  1310. jsonString = [jsonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  1311. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  1312. NSError *jsonError;
  1313. NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData
  1314. options:0
  1315. error:&jsonError];
  1316. if (jsonError) {
  1317. return [self JSONSerializationErrorWithUnderlyingError:jsonError];
  1318. }
  1319. NSDictionary *errorDict = jsonDict[@"error"];
  1320. NSString *errorMessage = errorDict[@"message"];
  1321. return [self errorWithCode:FIRAuthInternalErrorBlockingCloudFunctionError message:errorMessage];
  1322. }
  1323. + (NSError *)recaptchaSDKNotLinkedError {
  1324. return [self errorWithCode:FIRAuthInternalErrorCodeRecaptchaSDKNotLinked
  1325. message:kFIRAuthErrorMessageRecaptchaSDKNotLinked];
  1326. }
  1327. @end
  1328. NS_ASSUME_NONNULL_END