FIRAuthErrorUtils.m 34 KB

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