FIRAuthErrorUtils.m 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  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 "FIRAuthErrorUtils.h"
  17. #import "FIRAuthCredential.h"
  18. #import "FIRAuthInternalErrors.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 FIRAuthErrorNameKey = @"error_name";
  27. NSString *const FIRAuthUpdatedCredentialKey = @"FIRAuthUpdatedCredentialKey";
  28. /** @var kServerErrorDetailMarker
  29. @brief This marker indicates that the server error message contains a detail error message which
  30. should be used instead of the hardcoded client error message.
  31. */
  32. static NSString *const kServerErrorDetailMarker = @" : ";
  33. #pragma mark - URL response error codes
  34. /** @var kURLResponseErrorCodeInvalidClientID
  35. @brief Error code that indicates that the client ID provided was invalid.
  36. */
  37. static NSString *const kURLResponseErrorCodeInvalidClientID = @"auth/invalid-oauth-client-id";
  38. #pragma mark - Standard Error Messages
  39. /** @var kFIRAuthErrorMessageInvalidCustomToken
  40. @brief Message for @c FIRAuthErrorCodeInvalidCustomToken error code.
  41. */
  42. static NSString *const kFIRAuthErrorMessageInvalidCustomToken = @"The custom token format is "
  43. "incorrect. Please check the documentation.";
  44. /** @var kFIRAuthErrorMessageCustomTokenMismatch
  45. @brief Message for @c FIRAuthErrorCodeCustomTokenMismatch error code.
  46. */
  47. static NSString *const kFIRAuthErrorMessageCustomTokenMismatch = @"The custom token corresponds to "
  48. "a different audience.";
  49. /** @var kFIRAuthErrorMessageInvalidEmail
  50. @brief Message for @c FIRAuthErrorCodeInvalidEmail error code.
  51. */
  52. static NSString *const kFIRAuthErrorMessageInvalidEmail = @"The email address is badly formatted.";
  53. /** @var kFIRAuthErrorMessageInvalidCredential
  54. @brief Message for @c FIRAuthErrorCodeInvalidCredential error code.
  55. */
  56. static NSString *const kFIRAuthErrorMessageInvalidCredential = @"The supplied auth credential is "
  57. "malformed or has expired.";
  58. /** @var kFIRAuthErrorMessageUserDisabled
  59. @brief Message for @c FIRAuthErrorCodeUserDisabled error code.
  60. */
  61. static NSString *const kFIRAuthErrorMessageUserDisabled = @"The user account has been disabled by "
  62. "an administrator.";
  63. /** @var kFIRAuthErrorMessageEmailAlreadyInUse
  64. @brief Message for @c FIRAuthErrorCodeEmailAlreadyInUse error code.
  65. */
  66. static NSString *const kFIRAuthErrorMessageEmailAlreadyInUse = @"The email address is already in "
  67. "use by another account.";
  68. /** @var kFIRAuthErrorMessageWrongPassword
  69. @brief Message for @c FIRAuthErrorCodeWrongPassword error code.
  70. */
  71. static NSString *const kFIRAuthErrorMessageWrongPassword = @"The password is invalid or the user "
  72. "does not have a password.";
  73. /** @var kFIRAuthErrorMessageTooManyRequests
  74. @brief Message for @c FIRAuthErrorCodeTooManyRequests error code.
  75. */
  76. static NSString *const kFIRAuthErrorMessageTooManyRequests = @"We have blocked all requests from "
  77. "this device due to unusual activity. Try again later.";
  78. /** @var kFIRAuthErrorMessageAccountExistsWithDifferentCredential
  79. @brief Message for @c FIRAuthErrorCodeAccountLinkNeeded error code.
  80. */
  81. static NSString *const kFIRAuthErrorMessageAccountExistsWithDifferentCredential = @"An account "
  82. "already exists with the same email address but different sign-in credentials. Sign in using a "
  83. "provider associated with this email address.";
  84. /** @var kFIRAuthErrorMessageRequiresRecentLogin
  85. @brief Message for @c FIRAuthErrorCodeRequiresRecentLogin error code.
  86. */
  87. static NSString *const kFIRAuthErrorMessageRequiresRecentLogin= @"This operation is sensitive and "
  88. "requires recent authentication. Log in again before retrying this request.";
  89. /** @var kFIRAuthErrorMessageProviderAlreadyLinked
  90. @brief Message for @c FIRAuthErrorCodeProviderAlreadyExists error code.
  91. */
  92. static NSString *const kFIRAuthErrorMessageProviderAlreadyLinked =
  93. @"[ERROR_PROVIDER_ALREADY_LINKED] - User can only be linked to one identity for the given "
  94. "provider.";
  95. /** @var kFIRAuthErrorMessageNoSuchProvider
  96. @brief Message for @c FIRAuthErrorCodeNoSuchProvider error code.
  97. */
  98. static NSString *const kFIRAuthErrorMessageNoSuchProvider = @"User was not linked to an account "
  99. "with the given provider.";
  100. /** @var kFIRAuthErrorMessageInvalidUserToken
  101. @brief Message for @c FIRAuthErrorCodeInvalidUserToken error code.
  102. */
  103. static NSString *const kFIRAuthErrorMessageInvalidUserToken = @"The user's credential is no longer "
  104. "valid. The user must sign in again.";
  105. /** @var kFIRAuthErrorMessageNetworkError
  106. @brief Message for @c FIRAuthErrorCodeNetworkError error code.
  107. */
  108. static NSString *const kFIRAuthErrorMessageNetworkError = @"Network error (such as timeout, "
  109. "interrupted connection or unreachable host) has occurred.";
  110. /** @var kFIRAuthErrorMessageKeychainError
  111. @brief Message for @c FIRAuthErrorCodeKeychainError error code.
  112. */
  113. static NSString *const kFIRAuthErrorMessageKeychainError = @"An error occurred when accessing the "
  114. "keychain. The @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo dictionary "
  115. "will contain more information about the error encountered";
  116. /** @var kFIRAuthErrorMessageUserTokenExpired
  117. @brief Message for @c FIRAuthErrorCodeTokenExpired error code.
  118. */
  119. static NSString *const kFIRAuthErrorMessageUserTokenExpired = @"The user's credential is no longer "
  120. "valid. The user must sign in again.";
  121. /** @var kFIRAuthErrorMessageUserNotFound
  122. @brief Message for @c FIRAuthErrorCodeUserNotFound error code.
  123. */
  124. static NSString *const kFIRAuthErrorMessageUserNotFound = @"There is no user record corresponding "
  125. "to this identifier. The user may have been deleted.";
  126. /** @var kFIRAuthErrorMessageInvalidAPIKey
  127. @brief Message for @c FIRAuthErrorCodeInvalidAPIKey error code.
  128. @remarks This error is not thrown by the server.
  129. */
  130. static NSString *const kFIRAuthErrorMessageInvalidAPIKey = @"An invalid API Key was supplied in "
  131. "the request.";
  132. /** @var kFIRAuthErrorMessageUserMismatch.
  133. @brief Message for @c FIRAuthErrorCodeInvalidAPIKey error code.
  134. */
  135. static NSString *const FIRAuthErrorMessageUserMismatch = @"The supplied credentials do not "
  136. "correspond to the previously signed in user.";
  137. /** @var kFIRAuthErrorMessageCredentialAlreadyInUse
  138. @brief Message for @c FIRAuthErrorCodeCredentialAlreadyInUse error code.
  139. */
  140. static NSString *const kFIRAuthErrorMessageCredentialAlreadyInUse = @"This credential is already "
  141. "associated with a different user account.";
  142. /** @var kFIRAuthErrorMessageOperationNotAllowed
  143. @brief Message for @c FIRAuthErrorCodeOperationNotAllowed error code.
  144. */
  145. static NSString *const kFIRAuthErrorMessageOperationNotAllowed = @"The given sign-in provider is "
  146. "disabled for this Firebase project. Enable it in the Firebase console, under the sign-in "
  147. "method tab of the Auth section.";
  148. /** @var kFIRAuthErrorMessageWeakPassword
  149. @brief Message for @c FIRAuthErrorCodeWeakPassword error code.
  150. */
  151. static NSString *const kFIRAuthErrorMessageWeakPassword = @"The password must be 6 characters long "
  152. "or more.";
  153. /** @var kFIRAuthErrorMessageAppNotAuthorized
  154. @brief Message for @c FIRAuthErrorCodeAppNotAuthorized error code.
  155. */
  156. static NSString *const kFIRAuthErrorMessageAppNotAuthorized = @"This app is not authorized to use "
  157. "Firebase Authentication with the provided API key. Review your key configuration in the "
  158. "Google API console and ensure that it accepts requests from your app's bundle ID.";
  159. /** @var kFIRAuthErrorMessageExpiredActionCode
  160. @brief Message for @c FIRAuthErrorCodeExpiredActionCode error code.
  161. */
  162. static NSString *const kFIRAuthErrorMessageExpiredActionCode = @"The action code has expired.";
  163. /** @var kFIRAuthErrorMessageInvalidActionCode
  164. @brief Message for @c FIRAuthErrorCodeInvalidActionCode error code.
  165. */
  166. static NSString *const kFIRAuthErrorMessageInvalidActionCode = @"The action code is invalid. This "
  167. "can happen if the code is malformed, expired, or has already been used.";
  168. /** @var kFIRAuthErrorMessageInvalidMessagePayload
  169. @brief Message for @c FIRAuthErrorCodeInvalidMessagePayload error code.
  170. */
  171. static NSString *const kFIRAuthErrorMessageInvalidMessagePayload = @"The action code is invalid. "
  172. "This can happen if the code is malformed, expired, or has already been used.";
  173. /** @var kFIRAuthErrorMessageInvalidSender
  174. @brief Message for @c FIRAuthErrorCodeInvalidSender error code.
  175. */
  176. static NSString *const kFIRAuthErrorMessageInvalidSender = @"The email template corresponding to "
  177. "this action contains invalid characters in its message. Please fix by going to the Auth email "
  178. "templates section in the Firebase Console.";
  179. /** @var kFIRAuthErrorMessageInvalidRecipientEmail
  180. @brief Message for @c FIRAuthErrorCodeInvalidRecipient error code.
  181. */
  182. static NSString *const kFIRAuthErrorMessageInvalidRecipientEmail = @"The action code is invalid. "
  183. "This can happen if the code is malformed, expired, or has already been used.";
  184. /** @var kFIRAuthErrorMessageMissingIosBundleID
  185. @brief Message for @c FIRAuthErrorCodeMissingIosbundleID error code.
  186. */
  187. static NSString *const kFIRAuthErrorMessageMissingIosBundleID =
  188. @"An iOS Bundle ID must be provided if an App Store ID is provided.";
  189. /** @var kFIRAuthErrorMessageMissingAndroidPackageName
  190. @brief Message for @c FIRAuthErrorCodeMissingAndroidPackageName error code.
  191. */
  192. static NSString *const kFIRAuthErrorMessageMissingAndroidPackageName =
  193. @"An Android Package Name must be provided if the Android App is required to be installed.";
  194. /** @var kFIRAuthErrorMessageUnauthorizedDomain
  195. @brief Message for @c FIRAuthErrorCodeUnauthorizedDomain error code.
  196. */
  197. static NSString *const kFIRAuthErrorMessageUnauthorizedDomain = @"The domain of the continue URL "
  198. "is not whitelisted. Please whitelist the domain in the Firebase console.";
  199. /** @var kFIRAuthErrorMessageInvalidContinueURI
  200. @brief Message for @c FIRAuthErrorCodeInvalidContinueURI error code.
  201. */
  202. static NSString *const kFIRAuthErrorMessageInvalidContinueURI =
  203. @"The continue URL provided in the request is invalid.";
  204. /** @var kFIRAuthErrorMessageMissingEmail
  205. @brief Message for @c FIRAuthErrorCodeMissingEmail error code.
  206. */
  207. static NSString *const kFIRAuthErrorMessageMissingEmail = @"An email address must be provided.";
  208. /** @var kFIRAuthErrorMessageMissingContinueURI
  209. @brief Message for @c FIRAuthErrorCodeMissingContinueURI error code.
  210. */
  211. static NSString *const kFIRAuthErrorMessageMissingContinueURI =
  212. @"A continue URL must be provided in the request.";
  213. /** @var kFIRAuthErrorMessageMissingPhoneNumber
  214. @brief Message for @c FIRAuthErrorCodeMissingPhoneNumber error code.
  215. */
  216. static NSString *const kFIRAuthErrorMessageMissingPhoneNumber =
  217. @"To send verification codes, provide a phone number for the recipient.";
  218. /** @var kFIRAuthErrorMessageInvalidPhoneNumber
  219. @brief Message for @c FIRAuthErrorCodeInvalidPhoneNumber error code.
  220. */
  221. static NSString *const kFIRAuthErrorMessageInvalidPhoneNumber =
  222. @"The format of the phone number provided is incorrect. Please enter the phone number in a "
  223. "format that can be parsed into E.164 format. E.164 phone numbers are written in the format "
  224. "[+][country code][subscriber number including area code].";
  225. /** @var kFIRAuthErrorMessageMissingVerificationCode
  226. @brief Message for @c FIRAuthErrorCodeMissingVerificationCode error code.
  227. */
  228. static NSString *const kFIRAuthErrorMessageMissingVerificationCode =
  229. @"The phone auth credential was created with an empty SMS verification Code.";
  230. /** @var kFIRAuthErrorMessageInvalidVerificationCode
  231. @brief Message for @c FIRAuthErrorCodeInvalidVerificationCode error code.
  232. */
  233. static NSString *const kFIRAuthErrorMessageInvalidVerificationCode =
  234. @"The SMS verification code used to create the phone auth credential is invalid. Please resend "
  235. "the verification code SMS and be sure to use the verification code provided by the user.";
  236. /** @var kFIRAuthErrorMessageMissingVerificationID
  237. @brief Message for @c FIRAuthErrorCodeInvalidVerificationID error code.
  238. */
  239. static NSString *const kFIRAuthErrorMessageMissingVerificationID =
  240. @"The phone auth credential was created with an empty verification ID.";
  241. /** @var kFIRAuthErrorMessageInvalidVerificationID
  242. @brief Message for @c FIRAuthErrorCodeInvalidVerificationID error code.
  243. */
  244. static NSString *const kFIRAuthErrorMessageInvalidVerificationID =
  245. @"The verification ID used to create the phone auth credential is invalid.";
  246. /** @var kFIRAuthErrorMessageSessionExpired
  247. @brief Message for @c FIRAuthErrorCodeSessionExpired error code.
  248. */
  249. static NSString *const kFIRAuthErrorMessageSessionExpired = @"The SMS code has expired. Please "
  250. @"re-send the verification code to try again.";
  251. /** @var kFIRAuthErrorMessageMissingAppCredential
  252. @brief Message for @c FIRAuthErrorCodeMissingAppCredential error code.
  253. */
  254. static NSString *const kFIRAuthErrorMessageMissingAppCredential = @"The phone verification request "
  255. "is missing an APNs Device token. Firebase Auth automatically detects APNs Device Tokens, "
  256. "however, if method swizzling is disabled, the APNs token must be set via the APNSToken "
  257. "property on FIRAuth or by calling setAPNSToken:type on FIRAuth.";
  258. /** @var kFIRAuthErrorMessageInvalidAppCredential
  259. @brief Message for @c FIRAuthErrorCodeInvalidAppCredential error code.
  260. */
  261. static NSString *const kFIRAuthErrorMessageInvalidAppCredential = @"The APNs device token provided "
  262. "is either incorrect or does not match the private certificate uploaded to the Firebase "
  263. "Console.";
  264. /** @var kFIRAuthErrorMessageQuotaExceeded
  265. @brief Message for @c FIRAuthErrorCodeQuotaExceeded error code.
  266. */
  267. static NSString *const kFIRAuthErrorMessageQuotaExceeded = @"The phone verification quota for this "
  268. "project has been exceeded.";
  269. /** @var kFIRAuthErrorMessageMissingAppToken
  270. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  271. */
  272. static NSString *const kFIRAuthErrorMessageMissingAppToken = @"There seems to be a problem with "
  273. "your project's Firebase phone number authentication set-up, please make sure to follow the "
  274. "instructions found at https://firebase.google.com/docs/auth/ios/phone-auth";
  275. /** @var kFIRAuthErrorMessageMissingAppToken
  276. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  277. */
  278. static NSString *const kFIRAuthErrorMessageNotificationNotForwarded = @"If app delegate swizzling "
  279. "is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to "
  280. "FIRAuth's canHandleNotificaton: method.";
  281. /** @var kFIRAuthErrorMessageAppNotVerified
  282. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  283. */
  284. static NSString *const kFIRAuthErrorMessageAppNotVerified = @"Firebase could not retrieve the "
  285. "silent push notification and therefore could not verify your app. Ensure that you configured "
  286. "your app correctly to recieve push notifications.";
  287. /** @var kFIRAuthErrorMessageCaptchaCheckFailed
  288. @brief Message for @c FIRAuthErrorCodeCaptchaCheckFailed error code.
  289. */
  290. static NSString *const kFIRAuthErrorMessageCaptchaCheckFailed = @"The reCAPTCHA response token "
  291. "provided is either invalid, expired or already";
  292. /** @var kFIRAuthErrorMessageWebContextAlreadyPresented
  293. @brief Message for @c FIRAuthErrorCodeWebContextAlreadyPresented error code.
  294. */
  295. static NSString *const kFIRAuthErrorMessageWebContextAlreadyPresented = @"User interaction is "
  296. "still ongoing, another view cannot be presented.";
  297. /** @var kFIRAuthErrorMessageWebContextCancelled
  298. @brief Message for @c FIRAuthErrorCodeWebContextCancelled error code.
  299. */
  300. static NSString *const kFIRAuthErrorMessageWebContextCancelled = @"The interaction was cancelled "
  301. "by the user.";
  302. /** @var kFIRAuthErrorMessageInvalidClientID
  303. @brief Message for @c FIRAuthErrorCodeInvalidClientID error code.
  304. */
  305. static NSString *const kFIRAuthErrorMessageInvalidClientID = @"The OAuth client ID provided is "
  306. "either invalid or does not match the specified API key.";
  307. /** @var kFIRAuthErrorMessageAppVerificationUserInteractionFailure
  308. @brief Message for @c FIRAuthErrorCodeInvalidClientID error code.
  309. */
  310. static NSString *const kFIRAuthErrorMessageAppVerificationUserInteractionFailure = @"The app "
  311. "verification process has failed, print and inspect the error details for more information";
  312. /** @var kFIRAuthErrorMessageInternalError
  313. @brief Message for @c FIRAuthErrorCodeInternalError error code.
  314. */
  315. static NSString *const kFIRAuthErrorMessageInternalError = @"An internal error has occurred, "
  316. "print and inspect the error details for more information.";
  317. /** @var FIRAuthErrorDescription
  318. @brief The error descrioption, based on the error code.
  319. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  320. */
  321. static NSString *FIRAuthErrorDescription(FIRAuthErrorCode code) {
  322. switch (code) {
  323. case FIRAuthErrorCodeInvalidCustomToken:
  324. return kFIRAuthErrorMessageInvalidCustomToken;
  325. case FIRAuthErrorCodeCustomTokenMismatch:
  326. return kFIRAuthErrorMessageCustomTokenMismatch;
  327. case FIRAuthErrorCodeInvalidEmail:
  328. return kFIRAuthErrorMessageInvalidEmail;
  329. case FIRAuthErrorCodeInvalidCredential:
  330. return kFIRAuthErrorMessageInvalidCredential;
  331. case FIRAuthErrorCodeUserDisabled:
  332. return kFIRAuthErrorMessageUserDisabled;
  333. case FIRAuthErrorCodeEmailAlreadyInUse:
  334. return kFIRAuthErrorMessageEmailAlreadyInUse;
  335. case FIRAuthErrorCodeWrongPassword:
  336. return kFIRAuthErrorMessageWrongPassword;
  337. case FIRAuthErrorCodeTooManyRequests:
  338. return kFIRAuthErrorMessageTooManyRequests;
  339. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  340. return kFIRAuthErrorMessageAccountExistsWithDifferentCredential;
  341. case FIRAuthErrorCodeRequiresRecentLogin:
  342. return kFIRAuthErrorMessageRequiresRecentLogin;
  343. case FIRAuthErrorCodeProviderAlreadyLinked:
  344. return kFIRAuthErrorMessageProviderAlreadyLinked;
  345. case FIRAuthErrorCodeNoSuchProvider:
  346. return kFIRAuthErrorMessageNoSuchProvider;
  347. case FIRAuthErrorCodeInvalidUserToken:
  348. return kFIRAuthErrorMessageInvalidUserToken;
  349. case FIRAuthErrorCodeNetworkError:
  350. return kFIRAuthErrorMessageNetworkError;
  351. case FIRAuthErrorCodeKeychainError:
  352. return kFIRAuthErrorMessageKeychainError;
  353. case FIRAuthErrorCodeUserTokenExpired:
  354. return kFIRAuthErrorMessageUserTokenExpired;
  355. case FIRAuthErrorCodeUserNotFound:
  356. return kFIRAuthErrorMessageUserNotFound;
  357. case FIRAuthErrorCodeInvalidAPIKey:
  358. return kFIRAuthErrorMessageInvalidAPIKey;
  359. case FIRAuthErrorCodeCredentialAlreadyInUse:
  360. return kFIRAuthErrorMessageCredentialAlreadyInUse;
  361. case FIRAuthErrorCodeInternalError:
  362. return kFIRAuthErrorMessageInternalError;
  363. case FIRAuthErrorCodeUserMismatch:
  364. return FIRAuthErrorMessageUserMismatch;
  365. case FIRAuthErrorCodeOperationNotAllowed:
  366. return kFIRAuthErrorMessageOperationNotAllowed;
  367. case FIRAuthErrorCodeWeakPassword:
  368. return kFIRAuthErrorMessageWeakPassword;
  369. case FIRAuthErrorCodeAppNotAuthorized:
  370. return kFIRAuthErrorMessageAppNotAuthorized;
  371. case FIRAuthErrorCodeExpiredActionCode:
  372. return kFIRAuthErrorMessageExpiredActionCode;
  373. case FIRAuthErrorCodeInvalidActionCode:
  374. return kFIRAuthErrorMessageInvalidActionCode;
  375. case FIRAuthErrorCodeInvalidSender:
  376. return kFIRAuthErrorMessageInvalidSender;
  377. case FIRAuthErrorCodeInvalidMessagePayload:
  378. return kFIRAuthErrorMessageInvalidMessagePayload;
  379. case FIRAuthErrorCodeInvalidRecipientEmail:
  380. return kFIRAuthErrorMessageInvalidRecipientEmail;
  381. case FIRAuthErrorCodeMissingIosBundleID:
  382. return kFIRAuthErrorMessageMissingIosBundleID;
  383. case FIRAuthErrorCodeMissingAndroidPackageName:
  384. return kFIRAuthErrorMessageMissingAndroidPackageName;
  385. case FIRAuthErrorCodeUnauthorizedDomain:
  386. return kFIRAuthErrorMessageUnauthorizedDomain;
  387. case FIRAuthErrorCodeInvalidContinueURI:
  388. return kFIRAuthErrorMessageInvalidContinueURI;
  389. case FIRAuthErrorCodeMissingContinueURI:
  390. return kFIRAuthErrorMessageMissingContinueURI;
  391. case FIRAuthErrorCodeMissingEmail:
  392. return kFIRAuthErrorMessageMissingEmail;
  393. case FIRAuthErrorCodeMissingPhoneNumber:
  394. return kFIRAuthErrorMessageMissingPhoneNumber;
  395. case FIRAuthErrorCodeInvalidPhoneNumber:
  396. return kFIRAuthErrorMessageInvalidPhoneNumber;
  397. case FIRAuthErrorCodeMissingVerificationCode:
  398. return kFIRAuthErrorMessageMissingVerificationCode;
  399. case FIRAuthErrorCodeInvalidVerificationCode:
  400. return kFIRAuthErrorMessageInvalidVerificationCode;
  401. case FIRAuthErrorCodeMissingVerificationID:
  402. return kFIRAuthErrorMessageMissingVerificationID;
  403. case FIRAuthErrorCodeInvalidVerificationID:
  404. return kFIRAuthErrorMessageInvalidVerificationID;
  405. case FIRAuthErrorCodeSessionExpired:
  406. return kFIRAuthErrorMessageSessionExpired;
  407. case FIRAuthErrorCodeMissingAppCredential:
  408. return kFIRAuthErrorMessageMissingAppCredential;
  409. case FIRAuthErrorCodeInvalidAppCredential:
  410. return kFIRAuthErrorMessageInvalidAppCredential;
  411. case FIRAuthErrorCodeQuotaExceeded:
  412. return kFIRAuthErrorMessageQuotaExceeded;
  413. case FIRAuthErrorCodeMissingAppToken:
  414. return kFIRAuthErrorMessageMissingAppToken;
  415. case FIRAuthErrorCodeNotificationNotForwarded:
  416. return kFIRAuthErrorMessageNotificationNotForwarded;
  417. case FIRAuthErrorCodeAppNotVerified:
  418. return kFIRAuthErrorMessageAppNotVerified;
  419. case FIRAuthErrorCodeCaptchaCheckFailed:
  420. return kFIRAuthErrorMessageCaptchaCheckFailed;
  421. case FIRAuthErrorCodeWebContextAlreadyPresented:
  422. return kFIRAuthErrorMessageWebContextAlreadyPresented;
  423. case FIRAuthErrorCodeWebContextCancelled:
  424. return kFIRAuthErrorMessageWebContextCancelled;
  425. case FIRAuthErrorCodeInvalidClientID:
  426. return kFIRAuthErrorMessageInvalidClientID;
  427. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  428. return kFIRAuthErrorMessageAppVerificationUserInteractionFailure;
  429. }
  430. }
  431. /** @var FIRAuthErrorCodeString
  432. @brief The the error short string, based on the error code.
  433. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  434. */
  435. static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
  436. switch (code) {
  437. case FIRAuthErrorCodeInvalidCustomToken:
  438. return @"ERROR_INVALID_CUSTOM_TOKEN";
  439. case FIRAuthErrorCodeCustomTokenMismatch:
  440. return @"ERROR_CUSTOM_TOKEN_MISMATCH";
  441. case FIRAuthErrorCodeInvalidEmail:
  442. return @"ERROR_INVALID_EMAIL";
  443. case FIRAuthErrorCodeInvalidCredential:
  444. return @"ERROR_INVALID_CREDENTIAL";
  445. case FIRAuthErrorCodeUserDisabled:
  446. return @"ERROR_USER_DISABLED";
  447. case FIRAuthErrorCodeEmailAlreadyInUse:
  448. return @"ERROR_EMAIL_ALREADY_IN_USE";
  449. case FIRAuthErrorCodeWrongPassword:
  450. return @"ERROR_WRONG_PASSWORD";
  451. case FIRAuthErrorCodeTooManyRequests:
  452. return @"ERROR_TOO_MANY_REQUESTS";
  453. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  454. return @"ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL";
  455. case FIRAuthErrorCodeRequiresRecentLogin:
  456. return @"ERROR_REQUIRES_RECENT_LOGIN";
  457. case FIRAuthErrorCodeProviderAlreadyLinked:
  458. return @"ERROR_PROVIDER_ALREADY_LINKED";
  459. case FIRAuthErrorCodeNoSuchProvider:
  460. return @"ERROR_NO_SUCH_PROVIDER";
  461. case FIRAuthErrorCodeInvalidUserToken:
  462. return @"ERROR_INVALID_USER_TOKEN";
  463. case FIRAuthErrorCodeNetworkError:
  464. return @"ERROR_NETWORK_REQUEST_FAILED";
  465. case FIRAuthErrorCodeKeychainError:
  466. return @"ERROR_KEYCHAIN_ERROR";
  467. case FIRAuthErrorCodeUserTokenExpired:
  468. return @"ERROR_USER_TOKEN_EXPIRED";
  469. case FIRAuthErrorCodeUserNotFound:
  470. return @"ERROR_USER_NOT_FOUND";
  471. case FIRAuthErrorCodeInvalidAPIKey:
  472. return @"ERROR_INVALID_API_KEY";
  473. case FIRAuthErrorCodeCredentialAlreadyInUse:
  474. return @"ERROR_CREDENTIAL_ALREADY_IN_USE";
  475. case FIRAuthErrorCodeInternalError:
  476. return @"ERROR_INTERNAL_ERROR";
  477. case FIRAuthErrorCodeUserMismatch:
  478. return @"ERROR_USER_MISMATCH";
  479. case FIRAuthErrorCodeOperationNotAllowed:
  480. return @"ERROR_OPERATION_NOT_ALLOWED";
  481. case FIRAuthErrorCodeWeakPassword:
  482. return @"ERROR_WEAK_PASSWORD";
  483. case FIRAuthErrorCodeAppNotAuthorized:
  484. return @"ERROR_APP_NOT_AUTHORIZED";
  485. case FIRAuthErrorCodeExpiredActionCode:
  486. return @"ERROR_EXPIRED_ACTION_CODE";
  487. case FIRAuthErrorCodeInvalidActionCode:
  488. return @"ERROR_INVALID_ACTION_CODE";
  489. case FIRAuthErrorCodeInvalidMessagePayload:
  490. return @"ERROR_INVALID_MESSAGE_PAYLOAD";
  491. case FIRAuthErrorCodeInvalidSender:
  492. return @"ERROR_INVALID_SENDER";
  493. case FIRAuthErrorCodeInvalidRecipientEmail:
  494. return @"ERROR_INVALID_RECIPIENT_EMAIL";
  495. case FIRAuthErrorCodeMissingIosBundleID:
  496. return @"ERROR_MISSING_IOS_BUNDLE_ID";
  497. case FIRAuthErrorCodeMissingAndroidPackageName:
  498. return @"ERROR_MISSING_ANDROID_PKG_NAME";
  499. case FIRAuthErrorCodeUnauthorizedDomain:
  500. return @"ERROR_UNAUTHORIZED_DOMAIN";
  501. case FIRAuthErrorCodeInvalidContinueURI:
  502. return @"ERROR_INVALID_CONTINUE_URI";
  503. case FIRAuthErrorCodeMissingContinueURI:
  504. return @"ERROR_MISSING_CONTINUE_URI";
  505. case FIRAuthErrorCodeMissingEmail:
  506. return @"ERROR_MISSING_EMAIL";
  507. case FIRAuthErrorCodeMissingPhoneNumber:
  508. return @"ERROR_MISSING_PHONE_NUMBER";
  509. case FIRAuthErrorCodeInvalidPhoneNumber:
  510. return @"ERROR_INVALID_PHONE_NUMBER";
  511. case FIRAuthErrorCodeMissingVerificationCode:
  512. return @"ERROR_MISSING_VERIFICATION_CODE";
  513. case FIRAuthErrorCodeInvalidVerificationCode:
  514. return @"ERROR_INVALID_VERIFICATION_CODE";
  515. case FIRAuthErrorCodeMissingVerificationID:
  516. return @"ERROR_MISSING_VERIFICATION_ID";
  517. case FIRAuthErrorCodeInvalidVerificationID:
  518. return @"ERROR_INVALID_VERIFICATION_ID";
  519. case FIRAuthErrorCodeSessionExpired:
  520. return @"ERROR_SESSION_EXPIRED";
  521. case FIRAuthErrorCodeMissingAppCredential:
  522. return @"MISSING_APP_CREDENTIAL";
  523. case FIRAuthErrorCodeInvalidAppCredential:
  524. return @"INVALID_APP_CREDENTIAL";
  525. case FIRAuthErrorCodeQuotaExceeded:
  526. return @"ERROR_QUOTA_EXCEEDED";
  527. case FIRAuthErrorCodeMissingAppToken:
  528. return @"ERROR_MISSING_APP_TOKEN";
  529. case FIRAuthErrorCodeNotificationNotForwarded:
  530. return @"ERROR_NOTIFICATION_NOT_FORWARDED";
  531. case FIRAuthErrorCodeAppNotVerified:
  532. return @"ERROR_APP_NOT_VERIFIED";
  533. case FIRAuthErrorCodeCaptchaCheckFailed:
  534. return @"ERROR_CAPTCHA_CHECK_FAILED";
  535. case FIRAuthErrorCodeWebContextAlreadyPresented:
  536. return @"ERROR_WEB_CONTEXT_ALREADY_PRESENTED";
  537. case FIRAuthErrorCodeWebContextCancelled:
  538. return @"ERROR_WEB_CONTEXT_CANCELLED";
  539. case FIRAuthErrorCodeInvalidClientID:
  540. return @"ERROR_INVALID_CLIENT_ID";
  541. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  542. return @"ERROR_APP_VERIFICATION_FAILED";
  543. }
  544. }
  545. @implementation FIRAuthErrorUtils
  546. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code {
  547. return [self errorWithCode:code message:nil];
  548. }
  549. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  550. message:(nullable NSString *)message {
  551. NSDictionary *userInfo = nil;
  552. if (message.length) {
  553. userInfo = @{
  554. NSLocalizedDescriptionKey : message
  555. };
  556. }
  557. return [self errorWithCode:code userInfo:userInfo];
  558. }
  559. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  560. underlyingError:(nullable NSError *)underlyingError {
  561. NSDictionary *errorUserInfo = nil;
  562. if (underlyingError) {
  563. errorUserInfo = @{
  564. NSUnderlyingErrorKey : underlyingError
  565. };
  566. }
  567. return [self errorWithCode:code userInfo:errorUserInfo];
  568. }
  569. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code userInfo:(NSDictionary *)userInfo {
  570. BOOL isPublic = (code & FIRAuthPublicErrorCodeFlag) == FIRAuthPublicErrorCodeFlag;
  571. if (isPublic) {
  572. // This is a public error. Return it as a public error and add a description.
  573. NSInteger errorCode = code & ~FIRAuthPublicErrorCodeFlag;
  574. NSMutableDictionary *errorUserInfo = [NSMutableDictionary dictionaryWithDictionary:userInfo];
  575. if (!errorUserInfo[NSLocalizedDescriptionKey]) {
  576. errorUserInfo[NSLocalizedDescriptionKey] = FIRAuthErrorDescription(errorCode);
  577. }
  578. errorUserInfo[FIRAuthErrorNameKey] = FIRAuthErrorCodeString(errorCode);
  579. return [NSError errorWithDomain:FIRAuthErrorDomain code:errorCode userInfo:errorUserInfo];
  580. } else {
  581. // This is an internal error. Wrap it in an internal error.
  582. NSError *error =
  583. [NSError errorWithDomain:FIRAuthInternalErrorDomain code:code userInfo:userInfo];
  584. return [self errorWithCode:FIRAuthInternalErrorCodeInternalError underlyingError:error];
  585. }
  586. }
  587. + (NSError *)RPCRequestEncodingErrorWithUnderlyingError:(NSError *)underlyingError {
  588. return [self errorWithCode:FIRAuthInternalErrorCodeRPCRequestEncodingError
  589. underlyingError:underlyingError];
  590. }
  591. + (NSError *)JSONSerializationErrorForUnencodableType {
  592. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError];
  593. }
  594. + (NSError *)JSONSerializationErrorWithUnderlyingError:(NSError *)underlyingError {
  595. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError
  596. underlyingError:underlyingError];
  597. }
  598. + (NSError *)networkErrorWithUnderlyingError:(NSError *)underlyingError {
  599. return [self errorWithCode:FIRAuthInternalErrorCodeNetworkError
  600. underlyingError:underlyingError];
  601. }
  602. + (NSError *)unexpectedErrorResponseWithData:(NSData *)data
  603. underlyingError:(NSError *)underlyingError {
  604. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse userInfo:@{
  605. FIRAuthErrorUserInfoDataKey : data,
  606. NSUnderlyingErrorKey : underlyingError
  607. }];
  608. }
  609. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse {
  610. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse userInfo:@{
  611. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse
  612. }];
  613. }
  614. + (NSError *)unexpectedResponseWithData:(NSData *)data
  615. underlyingError:(NSError *)underlyingError {
  616. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:@{
  617. FIRAuthErrorUserInfoDataKey : data,
  618. NSUnderlyingErrorKey : underlyingError
  619. }];
  620. }
  621. + (NSError *)unexpectedResponseWithDeserializedResponse:(id)deserializedResponse {
  622. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:@{
  623. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse
  624. }];
  625. }
  626. + (NSError *)unexpectedResponseWithDeserializedResponse:(nullable id)deserializedResponse
  627. underlyingError:(NSError *)underlyingError {
  628. NSMutableDictionary *userInfo =
  629. [NSMutableDictionary dictionaryWithDictionary:@{ NSUnderlyingErrorKey : underlyingError }];
  630. if (deserializedResponse) {
  631. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  632. }
  633. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:userInfo];
  634. }
  635. + (NSError *)RPCResponseDecodingErrorWithDeserializedResponse:(id)deserializedResponse
  636. underlyingError:(NSError *)underlyingError {
  637. return [self errorWithCode:FIRAuthInternalErrorCodeRPCResponseDecodingError userInfo:@{
  638. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse,
  639. NSUnderlyingErrorKey : underlyingError
  640. }];
  641. }
  642. + (NSError *)emailAlreadyInUseErrorWithEmail:(nullable NSString *)email {
  643. NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
  644. if (email.length) {
  645. userInfo[FIRAuthErrorUserInfoEmailKey] = email;
  646. }
  647. return [self errorWithCode:FIRAuthInternalErrorCodeEmailAlreadyInUse userInfo:userInfo];
  648. }
  649. + (NSError *)userDisabledErrorWithMessage:(nullable NSString *)message {
  650. return [self errorWithCode:FIRAuthInternalErrorCodeUserDisabled message:message];
  651. }
  652. + (NSError *)wrongPasswordErrorWithMessage:(nullable NSString *)message {
  653. return [self errorWithCode:FIRAuthInternalErrorCodeWrongPassword message:message];
  654. }
  655. + (NSError *)tooManyRequestsErrorWithMessage:(nullable NSString *)message {
  656. return [self errorWithCode:FIRAuthInternalErrorCodeTooManyRequests message:message];
  657. }
  658. + (NSError *)invalidCustomTokenErrorWithMessage:(nullable NSString *)message {
  659. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCustomToken message:message];
  660. }
  661. + (NSError *)customTokenMistmatchErrorWithMessage:(nullable NSString *)message {
  662. return [self errorWithCode:FIRAuthInternalErrorCodeCustomTokenMismatch message:message];
  663. }
  664. + (NSError *)invalidCredentialErrorWithMessage:(nullable NSString *)message {
  665. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCredential message:message];
  666. }
  667. + (NSError *)requiresRecentLoginErrorWithMessage:(nullable NSString *)message {
  668. return [self errorWithCode:FIRAuthInternalErrorCodeRequiresRecentLogin message:message];
  669. }
  670. + (NSError *)invalidUserTokenErrorWithMessage:(nullable NSString *)message {
  671. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidUserToken message:message];
  672. }
  673. + (NSError *)invalidEmailErrorWithMessage:(nullable NSString *)message {
  674. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidEmail message:message];
  675. }
  676. + (NSError *)accountExistsWithDifferentCredentialErrorWithEmail:(nullable NSString *)email {
  677. return [self errorWithCode:FIRAuthInternalErrorCodeAccountExistsWithDifferentCredential
  678. userInfo:@{ FIRAuthErrorUserInfoEmailKey : email }];
  679. }
  680. + (NSError *)providerAlreadyLinkedError {
  681. return [self errorWithCode:FIRAuthInternalErrorCodeProviderAlreadyLinked];
  682. }
  683. + (NSError *)noSuchProviderError {
  684. return [self errorWithCode:FIRAuthInternalErrorCodeNoSuchProvider];
  685. }
  686. + (NSError *)userTokenExpiredErrorWithMessage:(nullable NSString *)message {
  687. return [self errorWithCode:FIRAuthInternalErrorCodeUserTokenExpired message:message];
  688. }
  689. + (NSError *)userNotFoundErrorWithMessage:(nullable NSString *)message {
  690. return [self errorWithCode:FIRAuthInternalErrorCodeUserNotFound message:message];
  691. }
  692. + (NSError *)invalidAPIKeyError {
  693. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAPIKey];
  694. }
  695. + (NSError *)userMismatchError {
  696. return [self errorWithCode:FIRAuthInternalErrorCodeUserMismatch];
  697. }
  698. + (NSError *)credentialAlreadyInUseErrorWithMessage:(nullable NSString *)message
  699. credential:(nullable FIRPhoneAuthCredential *)credential {
  700. if (credential) {
  701. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse
  702. userInfo:@{ FIRAuthUpdatedCredentialKey : credential }];
  703. }
  704. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse message:message];
  705. }
  706. + (NSError *)operationNotAllowedErrorWithMessage:(nullable NSString *)message {
  707. return [self errorWithCode:FIRAuthInternalErrorCodeOperationNotAllowed message:message];
  708. }
  709. + (NSError *)weakPasswordErrorWithServerResponseReason:(NSString *)reason {
  710. return [self errorWithCode:FIRAuthInternalErrorCodeWeakPassword userInfo:@{
  711. NSLocalizedFailureReasonErrorKey : reason
  712. }];
  713. }
  714. + (NSError *)appNotAuthorizedError {
  715. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotAuthorized];
  716. }
  717. + (NSError *)expiredActionCodeErrorWithMessage:(nullable NSString *)message {
  718. return [self errorWithCode:FIRAuthInternalErrorCodeExpiredActionCode message:message];
  719. }
  720. + (NSError *)invalidActionCodeErrorWithMessage:(nullable NSString *)message {
  721. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidActionCode message:message];
  722. }
  723. + (NSError *)invalidMessagePayloadErrorWithMessage:(nullable NSString *)message {
  724. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidMessagePayload message:message];
  725. }
  726. + (NSError *)invalidSenderErrorWithMessage:(nullable NSString *)message {
  727. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidSender message:message];
  728. }
  729. + (NSError *)invalidRecipientEmailErrorWithMessage:(nullable NSString *)message {
  730. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidRecipientEmail message:message];
  731. }
  732. + (NSError *)missingIosBundleIDErrorWithMessage:(nullable NSString *)message {
  733. return [self errorWithCode:FIRAuthinternalErrorCodeMissingIosBundleID message:message];
  734. }
  735. + (NSError *)missingAndroidPackageNameErrorWithMessage:(nullable NSString *)message {
  736. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAndroidPackageName message:message];
  737. }
  738. + (NSError *)unauthorizedDomainErrorWithMessage:(nullable NSString *)message {
  739. return [self errorWithCode:FIRAuthInternalErrorCodeUnauthorizedDomain message:message];
  740. }
  741. + (NSError *)invalidContinueURIErrorWithMessage:(nullable NSString *)message {
  742. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidContinueURI message:message];
  743. }
  744. + (NSError *)missingContinueURIErrorWithMessage:(nullable NSString *)message {
  745. return[self errorWithCode:FIRAuthInternalErrorCodeMissingContinueURI message:message];
  746. }
  747. + (NSError *)missingEmailErrorWithMessage:(nullable NSString *)message {
  748. return [self errorWithCode:FIRAuthInternalErrorCodeMissingEmail message:message];
  749. }
  750. + (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message {
  751. return [self errorWithCode:FIRAuthInternalErrorCodeMissingPhoneNumber message:message];
  752. }
  753. + (NSError *)invalidPhoneNumberErrorWithMessage:(nullable NSString *)message {
  754. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidPhoneNumber message:message];
  755. }
  756. + (NSError *)missingVerificationCodeErrorWithMessage:(nullable NSString *)message {
  757. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationCode message:message];
  758. }
  759. + (NSError *)invalidVerificationCodeErrorWithMessage:(nullable NSString *)message {
  760. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationCode message:message];
  761. }
  762. + (NSError *)missingVerificationIDErrorWithMessage:(nullable NSString *)message {
  763. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationID message:message];
  764. }
  765. + (NSError *)invalidVerificationIDErrorWithMessage:(nullable NSString *)message {
  766. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationID message:message];
  767. }
  768. + (NSError *)sessionExpiredErrorWithMessage:(nullable NSString *)message {
  769. return [self errorWithCode:FIRAuthInternalErrorCodeSessionExpired message:message];
  770. }
  771. + (NSError *)missingAppCredentialWithMessage:(nullable NSString *)message {
  772. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppCredential message:message];
  773. }
  774. + (NSError *)invalidAppCredentialWithMessage:(nullable NSString *)message {
  775. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAppCredential message:message];
  776. }
  777. + (NSError *)quotaExceededErrorWithMessage:(nullable NSString *)message {
  778. return [self errorWithCode:FIRAuthInternalErrorCodeQuotaExceeded message:message];
  779. }
  780. + (NSError *)missingAppTokenErrorWithUnderlyingError:(nullable NSError *)underlyingError {
  781. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppToken
  782. underlyingError:underlyingError];
  783. }
  784. + (NSError *)notificationNotForwardedError {
  785. return [self errorWithCode:FIRAuthInternalErrorCodeNotificationNotForwarded];
  786. }
  787. + (NSError *)appNotVerifiedErrorWithMessage:(nullable NSString *)message {
  788. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotVerified message:message];
  789. }
  790. + (NSError *)captchaCheckFailedErrorWithMessage:(nullable NSString *)message {
  791. return [self errorWithCode:FIRAuthInternalErrorCodeCaptchaCheckFailed message:message];
  792. }
  793. + (NSError *)webContextAlreadyPresentedErrorWithMessage:(nullable NSString *)message {
  794. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextAlreadyPresented message:message];
  795. }
  796. + (NSError *)webContextCancelledErrorWithMessage:(nullable NSString *)message {
  797. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextCancelled message:message];
  798. }
  799. + (NSError *)appVerificationUserInteractionFailureWithReason:(nullable NSString *)reason {
  800. return [self errorWithCode:FIRAuthInternalErrorCodeAppVerificationUserInteractionFailure
  801. userInfo:@{
  802. NSLocalizedFailureReasonErrorKey : reason
  803. }];
  804. }
  805. + (NSError *)URLResponseErrorWithCode:(NSString *)code message:(nullable NSString *)message {
  806. if ([code isEqualToString:kURLResponseErrorCodeInvalidClientID]) {
  807. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidClientID message:message];
  808. }
  809. return nil;
  810. }
  811. + (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status {
  812. NSString *failureReason = [NSString stringWithFormat:@"%@ (%li)", keychainFunction, (long)status];
  813. return [self errorWithCode:FIRAuthInternalErrorCodeKeychainError userInfo:@{
  814. NSLocalizedFailureReasonErrorKey : failureReason,
  815. }];
  816. }
  817. @end
  818. NS_ASSUME_NONNULL_END