FIRAuthErrorUtils.m 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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 - 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 kFIRAuthErrorMessageMissingIosBundleID
  180. @brief Message for @c FIRAuthErrorCodeMissingIosbundleID error code.
  181. */
  182. static NSString *const kFIRAuthErrorMessageMissingIosBundleID =
  183. @"An iOS Bundle ID must be provided if an App Store ID is provided.";
  184. /** @var kFIRAuthErrorMessageMissingAndroidPackageName
  185. @brief Message for @c FIRAuthErrorCodeMissingAndroidPackageName error code.
  186. */
  187. static NSString *const kFIRAuthErrorMessageMissingAndroidPackageName =
  188. @"An Android Package Name must be provided if the Android App is required to be installed.";
  189. /** @var kFIRAuthErrorMessageUnauthorizedDomain
  190. @brief Message for @c FIRAuthErrorCodeUnauthorizedDomain error code.
  191. */
  192. static NSString *const kFIRAuthErrorMessageUnauthorizedDomain = @"The domain of the continue URL "
  193. "is not whitelisted. Please whitelist the domain in the Firebase console.";
  194. /** @var kFIRAuthErrorMessageInvalidContinueURI
  195. @brief Message for @c FIRAuthErrorCodeInvalidContinueURI error code.
  196. */
  197. static NSString *const kFIRAuthErrorMessageInvalidContinueURI =
  198. @"The continue URL provided in the request is invalid.";
  199. /** @var kFIRAuthErrorMessageMissingEmail
  200. @brief Message for @c FIRAuthErrorCodeMissingEmail error code.
  201. */
  202. static NSString *const kFIRAuthErrorMessageMissingEmail = @"An email address must be provided.";
  203. /** @var kFIRAuthErrorMessageMissingContinueURI
  204. @brief Message for @c FIRAuthErrorCodeMissingContinueURI error code.
  205. */
  206. static NSString *const kFIRAuthErrorMessageMissingContinueURI =
  207. @"A continue URL must be provided in the request.";
  208. /** @var kFIRAuthErrorMessageMissingPhoneNumber
  209. @brief Message for @c FIRAuthErrorCodeMissingPhoneNumber error code.
  210. */
  211. static NSString *const kFIRAuthErrorMessageMissingPhoneNumber =
  212. @"To send verification codes, provide a phone number for the recipient.";
  213. /** @var kFIRAuthErrorMessageInvalidPhoneNumber
  214. @brief Message for @c FIRAuthErrorCodeInvalidPhoneNumber error code.
  215. */
  216. static NSString *const kFIRAuthErrorMessageInvalidPhoneNumber =
  217. @"The format of the phone number provided is incorrect. Please enter the phone number in a "
  218. "format that can be parsed into E.164 format. E.164 phone numbers are written in the format "
  219. "[+][country code][subscriber number including area code].";
  220. /** @var kFIRAuthErrorMessageMissingVerificationCode
  221. @brief Message for @c FIRAuthErrorCodeMissingVerificationCode error code.
  222. */
  223. static NSString *const kFIRAuthErrorMessageMissingVerificationCode =
  224. @"The phone auth credential was created with an empty SMS verification Code.";
  225. /** @var kFIRAuthErrorMessageInvalidVerificationCode
  226. @brief Message for @c FIRAuthErrorCodeInvalidVerificationCode error code.
  227. */
  228. static NSString *const kFIRAuthErrorMessageInvalidVerificationCode =
  229. @"The SMS verification code used to create the phone auth credential is invalid. Please resend "
  230. "the verification code SMS and be sure to use the verification code provided by the user.";
  231. /** @var kFIRAuthErrorMessageMissingVerificationID
  232. @brief Message for @c FIRAuthErrorCodeInvalidVerificationID error code.
  233. */
  234. static NSString *const kFIRAuthErrorMessageMissingVerificationID =
  235. @"The phone auth credential was created with an empty verification ID.";
  236. /** @var kFIRAuthErrorMessageInvalidVerificationID
  237. @brief Message for @c FIRAuthErrorCodeInvalidVerificationID error code.
  238. */
  239. static NSString *const kFIRAuthErrorMessageInvalidVerificationID =
  240. @"The verification ID used to create the phone auth credential is invalid.";
  241. /** @var kFIRAuthErrorMessageSessionExpired
  242. @brief Message for @c FIRAuthErrorCodeSessionExpired error code.
  243. */
  244. static NSString *const kFIRAuthErrorMessageSessionExpired = @"The SMS code has expired. Please "
  245. @"re-send the verification code to try again.";
  246. /** @var kFIRAuthErrorMessageMissingAppCredential
  247. @brief Message for @c FIRAuthErrorCodeMissingAppCredential error code.
  248. */
  249. static NSString *const kFIRAuthErrorMessageMissingAppCredential = @"The phone verification request "
  250. "is missing an APNs Device token. Firebase Auth automatically detects APNs Device Tokens, "
  251. "however, if method swizzling is disabled, the APNs token must be set via the APNSToken "
  252. "property on FIRAuth or by calling setAPNSToken:type on FIRAuth.";
  253. /** @var kFIRAuthErrorMessageInvalidAppCredential
  254. @brief Message for @c FIRAuthErrorCodeInvalidAppCredential error code.
  255. */
  256. static NSString *const kFIRAuthErrorMessageInvalidAppCredential = @"The APNs device token provided "
  257. "is either incorrect or does not match the private certificate uploaded to the Firebase "
  258. "Console.";
  259. /** @var kFIRAuthErrorMessageQuotaExceeded
  260. @brief Message for @c FIRAuthErrorCodeQuotaExceeded error code.
  261. */
  262. static NSString *const kFIRAuthErrorMessageQuotaExceeded = @"The phone verification quota for this "
  263. "project has been exceeded.";
  264. /** @var kFIRAuthErrorMessageMissingAppToken
  265. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  266. */
  267. static NSString *const kFIRAuthErrorMessageMissingAppToken = @"There seems to be a problem with "
  268. "your project's Firebase phone number authentication set-up, please make sure to follow the "
  269. "instructions found at https://firebase.google.com/docs/auth/ios/phone-auth";
  270. /** @var kFIRAuthErrorMessageMissingAppToken
  271. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  272. */
  273. static NSString *const kFIRAuthErrorMessageNotificationNotForwarded = @"If app delegate swizzling "
  274. "is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to "
  275. "FIRAuth's canHandleNotificaton: method.";
  276. /** @var kFIRAuthErrorMessageAppNotVerified
  277. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  278. */
  279. static NSString *const kFIRAuthErrorMessageAppNotVerified = @"Firebase could not retrieve the "
  280. "silent push notification and therefore could not verify your app. Ensure that you configured "
  281. "your app correctly to recieve push notifications.";
  282. /** @var kFIRAuthErrorMessageInternalError
  283. @brief Message for @c FIRAuthErrorCodeInternalError error code.
  284. */
  285. static NSString *const kFIRAuthErrorMessageInternalError = @"An internal error has occurred, "
  286. "print and inspect the error details for more information.";
  287. /** @var FIRAuthErrorDescription
  288. @brief The error descrioption, based on the error code.
  289. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  290. */
  291. static NSString *FIRAuthErrorDescription(FIRAuthErrorCode code) {
  292. switch (code) {
  293. case FIRAuthErrorCodeInvalidCustomToken:
  294. return kFIRAuthErrorMessageInvalidCustomToken;
  295. case FIRAuthErrorCodeCustomTokenMismatch:
  296. return kFIRAuthErrorMessageCustomTokenMismatch;
  297. case FIRAuthErrorCodeInvalidEmail:
  298. return kFIRAuthErrorMessageInvalidEmail;
  299. case FIRAuthErrorCodeInvalidCredential:
  300. return kFIRAuthErrorMessageInvalidCredential;
  301. case FIRAuthErrorCodeUserDisabled:
  302. return kFIRAuthErrorMessageUserDisabled;
  303. case FIRAuthErrorCodeEmailAlreadyInUse:
  304. return kFIRAuthErrorMessageEmailAlreadyInUse;
  305. case FIRAuthErrorCodeWrongPassword:
  306. return kFIRAuthErrorMessageWrongPassword;
  307. case FIRAuthErrorCodeTooManyRequests:
  308. return kFIRAuthErrorMessageTooManyRequests;
  309. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  310. return kFIRAuthErrorMessageAccountExistsWithDifferentCredential;
  311. case FIRAuthErrorCodeRequiresRecentLogin:
  312. return kFIRAuthErrorMessageRequiresRecentLogin;
  313. case FIRAuthErrorCodeProviderAlreadyLinked:
  314. return kFIRAuthErrorMessageProviderAlreadyLinked;
  315. case FIRAuthErrorCodeNoSuchProvider:
  316. return kFIRAuthErrorMessageNoSuchProvider;
  317. case FIRAuthErrorCodeInvalidUserToken:
  318. return kFIRAuthErrorMessageInvalidUserToken;
  319. case FIRAuthErrorCodeNetworkError:
  320. return kFIRAuthErrorMessageNetworkError;
  321. case FIRAuthErrorCodeKeychainError:
  322. return kFIRAuthErrorMessageKeychainError;
  323. case FIRAuthErrorCodeUserTokenExpired:
  324. return kFIRAuthErrorMessageUserTokenExpired;
  325. case FIRAuthErrorCodeUserNotFound:
  326. return kFIRAuthErrorMessageUserNotFound;
  327. case FIRAuthErrorCodeInvalidAPIKey:
  328. return kFIRAuthErrorMessageInvalidAPIKey;
  329. case FIRAuthErrorCodeCredentialAlreadyInUse:
  330. return kFIRAuthErrorMessageCredentialAlreadyInUse;
  331. case FIRAuthErrorCodeInternalError:
  332. return kFIRAuthErrorMessageInternalError;
  333. case FIRAuthErrorCodeUserMismatch:
  334. return FIRAuthErrorMessageUserMismatch;
  335. case FIRAuthErrorCodeOperationNotAllowed:
  336. return kFIRAuthErrorMessageOperationNotAllowed;
  337. case FIRAuthErrorCodeWeakPassword:
  338. return kFIRAuthErrorMessageWeakPassword;
  339. case FIRAuthErrorCodeAppNotAuthorized:
  340. return kFIRAuthErrorMessageAppNotAuthorized;
  341. case FIRAuthErrorCodeExpiredActionCode:
  342. return kFIRAuthErrorMessageExpiredActionCode;
  343. case FIRAuthErrorCodeInvalidActionCode:
  344. return kFIRAuthErrorMessageInvalidActionCode;
  345. case FIRAuthErrorCodeInvalidSender:
  346. return kFIRAuthErrorMessageInvalidSender;
  347. case FIRAuthErrorCodeInvalidMessagePayload:
  348. return kFIRAuthErrorMessageInvalidMessagePayload;
  349. case FIRAuthErrorCodeInvalidRecipientEmail:
  350. return kFIRAuthErrorMessageInvalidRecipientEmail;
  351. case FIRAuthErrorCodeMissingIosBundleID:
  352. return kFIRAuthErrorMessageMissingIosBundleID;
  353. case FIRAuthErrorCodeMissingAndroidPackageName:
  354. return kFIRAuthErrorMessageMissingAndroidPackageName;
  355. case FIRAuthErrorCodeUnauthorizedDomain:
  356. return kFIRAuthErrorMessageUnauthorizedDomain;
  357. case FIRAuthErrorCodeInvalidContinueURI:
  358. return kFIRAuthErrorMessageInvalidContinueURI;
  359. case FIRAuthErrorCodeMissingContinueURI:
  360. return kFIRAuthErrorMessageMissingContinueURI;
  361. case FIRAuthErrorCodeMissingEmail:
  362. return kFIRAuthErrorMessageMissingEmail;
  363. case FIRAuthErrorCodeMissingPhoneNumber:
  364. return kFIRAuthErrorMessageMissingPhoneNumber;
  365. case FIRAuthErrorCodeInvalidPhoneNumber:
  366. return kFIRAuthErrorMessageInvalidPhoneNumber;
  367. case FIRAuthErrorCodeMissingVerificationCode:
  368. return kFIRAuthErrorMessageMissingVerificationCode;
  369. case FIRAuthErrorCodeInvalidVerificationCode:
  370. return kFIRAuthErrorMessageInvalidVerificationCode;
  371. case FIRAuthErrorCodeMissingVerificationID:
  372. return kFIRAuthErrorMessageMissingVerificationID;
  373. case FIRAuthErrorCodeInvalidVerificationID:
  374. return kFIRAuthErrorMessageInvalidVerificationID;
  375. case FIRAuthErrorCodeSessionExpired:
  376. return kFIRAuthErrorMessageSessionExpired;
  377. case FIRAuthErrorCodeMissingAppCredential:
  378. return kFIRAuthErrorMessageMissingAppCredential;
  379. case FIRAuthErrorCodeInvalidAppCredential:
  380. return kFIRAuthErrorMessageInvalidAppCredential;
  381. case FIRAuthErrorCodeQuotaExceeded:
  382. return kFIRAuthErrorMessageQuotaExceeded;
  383. case FIRAuthErrorCodeMissingAppToken:
  384. return kFIRAuthErrorMessageMissingAppToken;
  385. case FIRAuthErrorCodeNotificationNotForwarded:
  386. return kFIRAuthErrorMessageNotificationNotForwarded;
  387. case FIRAuthErrorCodeAppNotVerified:
  388. return kFIRAuthErrorMessageAppNotVerified;
  389. }
  390. }
  391. /** @var FIRAuthErrorCodeString
  392. @brief The the error short string, based on the error code.
  393. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  394. */
  395. static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
  396. switch (code) {
  397. case FIRAuthErrorCodeInvalidCustomToken:
  398. return @"ERROR_INVALID_CUSTOM_TOKEN";
  399. case FIRAuthErrorCodeCustomTokenMismatch:
  400. return @"ERROR_CUSTOM_TOKEN_MISMATCH";
  401. case FIRAuthErrorCodeInvalidEmail:
  402. return @"ERROR_INVALID_EMAIL";
  403. case FIRAuthErrorCodeInvalidCredential:
  404. return @"ERROR_INVALID_CREDENTIAL";
  405. case FIRAuthErrorCodeUserDisabled:
  406. return @"ERROR_USER_DISABLED";
  407. case FIRAuthErrorCodeEmailAlreadyInUse:
  408. return @"ERROR_EMAIL_ALREADY_IN_USE";
  409. case FIRAuthErrorCodeWrongPassword:
  410. return @"ERROR_WRONG_PASSWORD";
  411. case FIRAuthErrorCodeTooManyRequests:
  412. return @"ERROR_TOO_MANY_REQUESTS";
  413. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  414. return @"ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL";
  415. case FIRAuthErrorCodeRequiresRecentLogin:
  416. return @"ERROR_REQUIRES_RECENT_LOGIN";
  417. case FIRAuthErrorCodeProviderAlreadyLinked:
  418. return @"ERROR_PROVIDER_ALREADY_LINKED";
  419. case FIRAuthErrorCodeNoSuchProvider:
  420. return @"ERROR_NO_SUCH_PROVIDER";
  421. case FIRAuthErrorCodeInvalidUserToken:
  422. return @"ERROR_INVALID_USER_TOKEN";
  423. case FIRAuthErrorCodeNetworkError:
  424. return @"ERROR_NETWORK_REQUEST_FAILED";
  425. case FIRAuthErrorCodeKeychainError:
  426. return @"ERROR_KEYCHAIN_ERROR";
  427. case FIRAuthErrorCodeUserTokenExpired:
  428. return @"ERROR_USER_TOKEN_EXPIRED";
  429. case FIRAuthErrorCodeUserNotFound:
  430. return @"ERROR_USER_NOT_FOUND";
  431. case FIRAuthErrorCodeInvalidAPIKey:
  432. return @"ERROR_INVALID_API_KEY";
  433. case FIRAuthErrorCodeCredentialAlreadyInUse:
  434. return @"ERROR_CREDENTIAL_ALREADY_IN_USE";
  435. case FIRAuthErrorCodeInternalError:
  436. return @"ERROR_INTERNAL_ERROR";
  437. case FIRAuthErrorCodeUserMismatch:
  438. return @"ERROR_USER_MISMATCH";
  439. case FIRAuthErrorCodeOperationNotAllowed:
  440. return @"ERROR_OPERATION_NOT_ALLOWED";
  441. case FIRAuthErrorCodeWeakPassword:
  442. return @"ERROR_WEAK_PASSWORD";
  443. case FIRAuthErrorCodeAppNotAuthorized:
  444. return @"ERROR_APP_NOT_AUTHORIZED";
  445. case FIRAuthErrorCodeExpiredActionCode:
  446. return @"ERROR_EXPIRED_ACTION_CODE";
  447. case FIRAuthErrorCodeInvalidActionCode:
  448. return @"ERROR_INVALID_ACTION_CODE";
  449. case FIRAuthErrorCodeInvalidMessagePayload:
  450. return @"ERROR_INVALID_MESSAGE_PAYLOAD";
  451. case FIRAuthErrorCodeInvalidSender:
  452. return @"ERROR_INVALID_SENDER";
  453. case FIRAuthErrorCodeInvalidRecipientEmail:
  454. return @"ERROR_INVALID_RECIPIENT_EMAIL";
  455. case FIRAuthErrorCodeMissingIosBundleID:
  456. return @"ERROR_MISSING_IOS_BUNDLE_ID";
  457. case FIRAuthErrorCodeMissingAndroidPackageName:
  458. return @"ERROR_MISSING_ANDROID_PKG_NAME";
  459. case FIRAuthErrorCodeUnauthorizedDomain:
  460. return @"ERROR_UNAUTHORIZED_DOMAIN";
  461. case FIRAuthErrorCodeInvalidContinueURI:
  462. return @"ERROR_INVALID_CONTINUE_URI";
  463. case FIRAuthErrorCodeMissingContinueURI:
  464. return @"ERROR_MISSING_CONTINUE_URI";
  465. case FIRAuthErrorCodeMissingEmail:
  466. return @"MISSING_EMAIL";
  467. case FIRAuthErrorCodeMissingPhoneNumber:
  468. return @"ERROR_MISSING_PHONE_NUMBER";
  469. case FIRAuthErrorCodeInvalidPhoneNumber:
  470. return @"ERROR_INVALID_PHONE_NUMBER";
  471. case FIRAuthErrorCodeMissingVerificationCode:
  472. return @"ERROR_MISSING_VERIFICATION_CODE";
  473. case FIRAuthErrorCodeInvalidVerificationCode:
  474. return @"ERROR_INVALID_VERIFICATION_CODE";
  475. case FIRAuthErrorCodeMissingVerificationID:
  476. return @"ERROR_MISSING_VERIFICATION_ID";
  477. case FIRAuthErrorCodeInvalidVerificationID:
  478. return @"ERROR_INVALID_VERIFICATION_ID";
  479. case FIRAuthErrorCodeSessionExpired:
  480. return @"ERROR_SESSION_EXPIRED";
  481. case FIRAuthErrorCodeMissingAppCredential:
  482. return @"MISSING_APP_CREDENTIAL";
  483. case FIRAuthErrorCodeInvalidAppCredential:
  484. return @"INVALID_APP_CREDENTIAL";
  485. case FIRAuthErrorCodeQuotaExceeded:
  486. return @"ERROR_QUOTA_EXCEEDED";
  487. case FIRAuthErrorCodeMissingAppToken:
  488. return @"ERROR_MISSING_APP_TOKEN";
  489. case FIRAuthErrorCodeNotificationNotForwarded:
  490. return @"ERROR_NOTIFICATION_NOT_FORWARDED";
  491. case FIRAuthErrorCodeAppNotVerified:
  492. return @"ERROR_APP_NOT_VERIFIED";
  493. }
  494. }
  495. @implementation FIRAuthErrorUtils
  496. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code {
  497. return [self errorWithCode:code message:nil];
  498. }
  499. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  500. message:(nullable NSString *)message {
  501. NSDictionary *userInfo = nil;
  502. if (message.length) {
  503. userInfo = @{
  504. NSLocalizedDescriptionKey : message
  505. };
  506. }
  507. return [self errorWithCode:code userInfo:userInfo];
  508. }
  509. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  510. underlyingError:(nullable NSError *)underlyingError {
  511. NSDictionary *errorUserInfo = nil;
  512. if (underlyingError) {
  513. errorUserInfo = @{
  514. NSUnderlyingErrorKey : underlyingError
  515. };
  516. }
  517. return [self errorWithCode:code userInfo:errorUserInfo];
  518. }
  519. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code userInfo:(NSDictionary *)userInfo {
  520. BOOL isPublic = (code & FIRAuthPublicErrorCodeFlag) == FIRAuthPublicErrorCodeFlag;
  521. if (isPublic) {
  522. // This is a public error. Return it as a public error and add a description.
  523. NSInteger errorCode = code & ~FIRAuthPublicErrorCodeFlag;
  524. NSMutableDictionary *errorUserInfo = [NSMutableDictionary dictionaryWithDictionary:userInfo];
  525. if (!errorUserInfo[NSLocalizedDescriptionKey]) {
  526. errorUserInfo[NSLocalizedDescriptionKey] = FIRAuthErrorDescription(errorCode);
  527. }
  528. errorUserInfo[FIRAuthErrorNameKey] = FIRAuthErrorCodeString(errorCode);
  529. return [NSError errorWithDomain:FIRAuthErrorDomain code:errorCode userInfo:errorUserInfo];
  530. } else {
  531. // This is an internal error. Wrap it in an internal error.
  532. NSError *error =
  533. [NSError errorWithDomain:FIRAuthInternalErrorDomain code:code userInfo:userInfo];
  534. return [self errorWithCode:FIRAuthInternalErrorCodeInternalError underlyingError:error];
  535. }
  536. }
  537. + (NSError *)RPCRequestEncodingErrorWithUnderlyingError:(NSError *)underlyingError {
  538. return [self errorWithCode:FIRAuthInternalErrorCodeRPCRequestEncodingError
  539. underlyingError:underlyingError];
  540. }
  541. + (NSError *)JSONSerializationErrorForUnencodableType {
  542. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError];
  543. }
  544. + (NSError *)JSONSerializationErrorWithUnderlyingError:(NSError *)underlyingError {
  545. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError
  546. underlyingError:underlyingError];
  547. }
  548. + (NSError *)networkErrorWithUnderlyingError:(NSError *)underlyingError {
  549. return [self errorWithCode:FIRAuthInternalErrorCodeNetworkError
  550. underlyingError:underlyingError];
  551. }
  552. + (NSError *)unexpectedErrorResponseWithData:(NSData *)data
  553. underlyingError:(NSError *)underlyingError {
  554. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse userInfo:@{
  555. FIRAuthErrorUserInfoDataKey : data,
  556. NSUnderlyingErrorKey : underlyingError
  557. }];
  558. }
  559. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse {
  560. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse userInfo:@{
  561. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse
  562. }];
  563. }
  564. + (NSError *)unexpectedResponseWithData:(NSData *)data
  565. underlyingError:(NSError *)underlyingError {
  566. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:@{
  567. FIRAuthErrorUserInfoDataKey : data,
  568. NSUnderlyingErrorKey : underlyingError
  569. }];
  570. }
  571. + (NSError *)unexpectedResponseWithDeserializedResponse:(id)deserializedResponse {
  572. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:@{
  573. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse
  574. }];
  575. }
  576. + (NSError *)unexpectedResponseWithDeserializedResponse:(nullable id)deserializedResponse
  577. underlyingError:(NSError *)underlyingError {
  578. NSMutableDictionary *userInfo =
  579. [NSMutableDictionary dictionaryWithDictionary:@{ NSUnderlyingErrorKey : underlyingError }];
  580. if (deserializedResponse) {
  581. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  582. }
  583. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:userInfo];
  584. }
  585. + (NSError *)RPCResponseDecodingErrorWithDeserializedResponse:(id)deserializedResponse
  586. underlyingError:(NSError *)underlyingError {
  587. return [self errorWithCode:FIRAuthInternalErrorCodeRPCResponseDecodingError userInfo:@{
  588. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse,
  589. NSUnderlyingErrorKey : underlyingError
  590. }];
  591. }
  592. + (NSError *)emailAlreadyInUseErrorWithEmail:(nullable NSString *)email {
  593. NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
  594. if (email.length) {
  595. userInfo[FIRAuthErrorUserInfoEmailKey] = email;
  596. }
  597. return [self errorWithCode:FIRAuthInternalErrorCodeEmailAlreadyInUse userInfo:userInfo];
  598. }
  599. + (NSError *)userDisabledErrorWithMessage:(nullable NSString *)message {
  600. return [self errorWithCode:FIRAuthInternalErrorCodeUserDisabled message:message];
  601. }
  602. + (NSError *)wrongPasswordErrorWithMessage:(nullable NSString *)message {
  603. return [self errorWithCode:FIRAuthInternalErrorCodeWrongPassword message:message];
  604. }
  605. + (NSError *)tooManyRequestsErrorWithMessage:(nullable NSString *)message {
  606. return [self errorWithCode:FIRAuthInternalErrorCodeTooManyRequests message:message];
  607. }
  608. + (NSError *)invalidCustomTokenErrorWithMessage:(nullable NSString *)message {
  609. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCustomToken message:message];
  610. }
  611. + (NSError *)customTokenMistmatchErrorWithMessage:(nullable NSString *)message {
  612. return [self errorWithCode:FIRAuthInternalErrorCodeCustomTokenMismatch message:message];
  613. }
  614. + (NSError *)invalidCredentialErrorWithMessage:(nullable NSString *)message {
  615. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCredential message:message];
  616. }
  617. + (NSError *)requiresRecentLoginErrorWithMessage:(nullable NSString *)message {
  618. return [self errorWithCode:FIRAuthInternalErrorCodeRequiresRecentLogin message:message];
  619. }
  620. + (NSError *)invalidUserTokenErrorWithMessage:(nullable NSString *)message {
  621. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidUserToken message:message];
  622. }
  623. + (NSError *)invalidEmailErrorWithMessage:(nullable NSString *)message {
  624. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidEmail message:message];
  625. }
  626. + (NSError *)accountExistsWithDifferentCredentialErrorWithEmail:(nullable NSString *)email {
  627. return [self errorWithCode:FIRAuthInternalErrorCodeAccountExistsWithDifferentCredential
  628. userInfo:@{ FIRAuthErrorUserInfoEmailKey : email }];
  629. }
  630. + (NSError *)providerAlreadyLinkedError {
  631. return [self errorWithCode:FIRAuthInternalErrorCodeProviderAlreadyLinked];
  632. }
  633. + (NSError *)noSuchProviderError {
  634. return [self errorWithCode:FIRAuthInternalErrorCodeNoSuchProvider];
  635. }
  636. + (NSError *)userTokenExpiredErrorWithMessage:(nullable NSString *)message {
  637. return [self errorWithCode:FIRAuthInternalErrorCodeUserTokenExpired message:message];
  638. }
  639. + (NSError *)userNotFoundErrorWithMessage:(nullable NSString *)message {
  640. return [self errorWithCode:FIRAuthInternalErrorCodeUserNotFound message:message];
  641. }
  642. + (NSError *)invalidAPIKeyError {
  643. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAPIKey];
  644. }
  645. + (NSError *)userMismatchError {
  646. return [self errorWithCode:FIRAuthInternalErrorCodeUserMismatch];
  647. }
  648. + (NSError *)credentialAlreadyInUseErrorWithMessage:(nullable NSString *)message
  649. credential:(nullable FIRPhoneAuthCredential *)credential {
  650. if (credential) {
  651. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse
  652. userInfo:@{ FIRAuthUpdatedCredentialKey : credential }];
  653. }
  654. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse message:message];
  655. }
  656. + (NSError *)operationNotAllowedErrorWithMessage:(nullable NSString *)message {
  657. return [self errorWithCode:FIRAuthInternalErrorCodeOperationNotAllowed message:message];
  658. }
  659. + (NSError *)weakPasswordErrorWithServerResponseReason:(NSString *)reason {
  660. return [self errorWithCode:FIRAuthInternalErrorCodeWeakPassword userInfo:@{
  661. NSLocalizedFailureReasonErrorKey : reason
  662. }];
  663. }
  664. + (NSError *)appNotAuthorizedError {
  665. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotAuthorized];
  666. }
  667. + (NSError *)expiredActionCodeErrorWithMessage:(nullable NSString *)message {
  668. return [self errorWithCode:FIRAuthInternalErrorCodeExpiredActionCode message:message];
  669. }
  670. + (NSError *)invalidActionCodeErrorWithMessage:(nullable NSString *)message {
  671. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidActionCode message:message];
  672. }
  673. + (NSError *)invalidMessagePayloadErrorWithMessage:(nullable NSString *)message {
  674. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidMessagePayload message:message];
  675. }
  676. + (NSError *)invalidSenderErrorWithMessage:(nullable NSString *)message {
  677. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidSender message:message];
  678. }
  679. + (NSError *)invalidRecipientEmailErrorWithMessage:(nullable NSString *)message {
  680. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidRecipientEmail message:message];
  681. }
  682. + (NSError *)missingIosBundleIDErrorWithMessage:(nullable NSString *)message {
  683. return [self errorWithCode:FIRAuthinternalErrorCodeMissingIosBundleID message:message];
  684. }
  685. + (NSError *)missingAndroidPackageNameErrorWithMessage:(nullable NSString *)message {
  686. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAndroidPackageName message:message];
  687. }
  688. + (NSError *)unauthorizedDomainErrorWithMessage:(nullable NSString *)message {
  689. return [self errorWithCode:FIRAuthInternalErrorCodeUnauthorizedDomain message:message];
  690. }
  691. + (NSError *)invalidContinueURIErrorWithMessage:(nullable NSString *)message {
  692. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidContinueURI message:message];
  693. }
  694. + (NSError *)missingContinueURIErrorWithMessage:(nullable NSString *)message {
  695. return[self errorWithCode:FIRAuthInternalErrorCodeMissingContinueURI message:message];
  696. }
  697. + (NSError *)missingEmail {
  698. return [self errorWithCode:FIRAuthInternalErrorCodeMissingEmail];
  699. }
  700. + (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message {
  701. return [self errorWithCode:FIRAuthInternalErrorCodeMissingPhoneNumber message:message];
  702. }
  703. + (NSError *)invalidPhoneNumberErrorWithMessage:(nullable NSString *)message {
  704. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidPhoneNumber message:message];
  705. }
  706. + (NSError *)missingVerificationCodeErrorWithMessage:(nullable NSString *)message {
  707. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationCode message:message];
  708. }
  709. + (NSError *)invalidVerificationCodeErrorWithMessage:(nullable NSString *)message {
  710. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationCode message:message];
  711. }
  712. + (NSError *)missingVerificationIDErrorWithMessage:(nullable NSString *)message {
  713. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationID message:message];
  714. }
  715. + (NSError *)invalidVerificationIDErrorWithMessage:(nullable NSString *)message {
  716. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationID message:message];
  717. }
  718. + (NSError *)sessionExpiredErrorWithMessage:(nullable NSString *)message {
  719. return [self errorWithCode:FIRAuthInternalErrorCodeSessionExpired message:message];
  720. }
  721. + (NSError *)missingAppCredentialWithMessage:(nullable NSString *)message {
  722. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppCredential message:message];
  723. }
  724. + (NSError *)invalidAppCredentialWithMessage:(nullable NSString *)message {
  725. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAppCredential message:message];
  726. }
  727. + (NSError *)quotaExceededErrorWithMessage:(nullable NSString *)message {
  728. return [self errorWithCode:FIRAuthInternalErrorCodeQuotaExceeded message:message];
  729. }
  730. + (NSError *)missingAppTokenError {
  731. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppToken];
  732. }
  733. + (NSError *)notificationNotForwardedError {
  734. return [self errorWithCode:FIRAuthInternalErrorCodeNotificationNotForwarded];
  735. }
  736. + (NSError *)appNotVerifiedErrorWithMessage:(nullable NSString *)message {
  737. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotVerified message:message];
  738. }
  739. + (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status {
  740. NSString *failureReason = [NSString stringWithFormat:@"%@ (%li)", keychainFunction, (long)status];
  741. return [self errorWithCode:FIRAuthInternalErrorCodeKeychainError userInfo:@{
  742. NSLocalizedFailureReasonErrorKey : failureReason,
  743. }];
  744. }
  745. @end
  746. NS_ASSUME_NONNULL_END