You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1008 lines
44 KiB

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