FIRAuthErrorUtils.m 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  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 occurred 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. "doesn’t 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 kFIRAuthErrorMessageLocalPlayerNotAuthenticated
  258. @brief Message for @c FIRAuthErrorCodeLocalPlayerNotAuthenticated error code.
  259. */
  260. static NSString *const kFIRAuthErrorMessageLocalPlayerNotAuthenticated =
  261. @"The local player is not authenticated. Please log the local player in to Game Center.";
  262. /** @var kFIRAuthErrorMessageGameKitNotLinked
  263. @brief Message for @c kFIRAuthErrorMessageGameKitNotLinked error code.
  264. */
  265. static NSString *const kFIRAuthErrorMessageGameKitNotLinked =
  266. @"The GameKit framework is not linked. Please turn on the Game Center capability.";
  267. /** @var kFIRAuthErrorMessageSessionExpired
  268. @brief Message for @c FIRAuthErrorCodeSessionExpired error code.
  269. */
  270. static NSString *const kFIRAuthErrorMessageSessionExpired = @"The SMS code has expired. Please "
  271. @"re-send the verification code to try again.";
  272. /** @var kFIRAuthErrorMessageMissingAppCredential
  273. @brief Message for @c FIRAuthErrorCodeMissingAppCredential error code.
  274. */
  275. static NSString *const kFIRAuthErrorMessageMissingAppCredential = @"The phone verification request "
  276. "is missing an APNs Device token. Firebase Auth automatically detects APNs Device Tokens, "
  277. "however, if method swizzling is disabled, the APNs token must be set via the APNSToken "
  278. "property on FIRAuth or by calling setAPNSToken:type on FIRAuth.";
  279. /** @var kFIRAuthErrorMessageInvalidAppCredential
  280. @brief Message for @c FIRAuthErrorCodeInvalidAppCredential error code.
  281. */
  282. static NSString *const kFIRAuthErrorMessageInvalidAppCredential = @"The APNs device token provided "
  283. "is either incorrect or does not match the private certificate uploaded to the Firebase "
  284. "Console.";
  285. /** @var kFIRAuthErrorMessageQuotaExceeded
  286. @brief Message for @c FIRAuthErrorCodeQuotaExceeded error code.
  287. */
  288. static NSString *const kFIRAuthErrorMessageQuotaExceeded = @"The phone verification quota for this "
  289. "project has been exceeded.";
  290. /** @var kFIRAuthErrorMessageMissingAppToken
  291. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  292. */
  293. static NSString *const kFIRAuthErrorMessageMissingAppToken = @"There seems to be a problem with "
  294. "your project's Firebase phone number authentication set-up, please make sure to follow the "
  295. "instructions found at https://firebase.google.com/docs/auth/ios/phone-auth";
  296. /** @var kFIRAuthErrorMessageMissingAppToken
  297. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  298. */
  299. static NSString *const kFIRAuthErrorMessageNotificationNotForwarded = @"If app delegate swizzling "
  300. "is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to "
  301. "FIRAuth's canHandleNotificaton: method.";
  302. /** @var kFIRAuthErrorMessageAppNotVerified
  303. @brief Message for @c FIRAuthErrorCodeMissingAppToken error code.
  304. */
  305. static NSString *const kFIRAuthErrorMessageAppNotVerified = @"Firebase could not retrieve the "
  306. "silent push notification and therefore could not verify your app. Ensure that you configured "
  307. "your app correctly to receive push notifications.";
  308. /** @var kFIRAuthErrorMessageCaptchaCheckFailed
  309. @brief Message for @c FIRAuthErrorCodeCaptchaCheckFailed error code.
  310. */
  311. static NSString *const kFIRAuthErrorMessageCaptchaCheckFailed = @"The reCAPTCHA response token "
  312. "provided is either invalid, expired or already";
  313. /** @var kFIRAuthErrorMessageWebContextAlreadyPresented
  314. @brief Message for @c FIRAuthErrorCodeWebContextAlreadyPresented error code.
  315. */
  316. static NSString *const kFIRAuthErrorMessageWebContextAlreadyPresented = @"User interaction is "
  317. "still ongoing, another view cannot be presented.";
  318. /** @var kFIRAuthErrorMessageWebContextCancelled
  319. @brief Message for @c FIRAuthErrorCodeWebContextCancelled error code.
  320. */
  321. static NSString *const kFIRAuthErrorMessageWebContextCancelled = @"The interaction was cancelled "
  322. "by the user.";
  323. /** @var kFIRAuthErrorMessageInvalidClientID
  324. @brief Message for @c FIRAuthErrorCodeInvalidClientID error code.
  325. */
  326. static NSString *const kFIRAuthErrorMessageInvalidClientID = @"The OAuth client ID provided is "
  327. "either invalid or does not match the specified API key.";
  328. /** @var kFIRAuthErrorMessageWebRequestFailed
  329. @brief Message for @c FIRAuthErrorCodeWebRequestFailed error code.
  330. */
  331. static NSString *const kFIRAuthErrorMessageWebRequestFailed = @"A network error (such as timeout, "
  332. "interrupted connection, or unreachable host) has occurred within the web context.";
  333. /** @var kFIRAuthErrorMessageWebInternalError
  334. @brief Message for @c FIRAuthErrorCodeWebInternalError error code.
  335. */
  336. static NSString *const kFIRAuthErrorMessageWebInternalError = @"An internal error has occurred "
  337. "within the SFSafariViewController or UIWebView.";
  338. /** @var kFIRAuthErrorMessageAppVerificationUserInteractionFailure
  339. @brief Message for @c FIRAuthErrorCodeInvalidClientID error code.
  340. */
  341. static NSString *const kFIRAuthErrorMessageAppVerificationUserInteractionFailure = @"The app "
  342. "verification process has failed, print and inspect the error details for more information";
  343. /** @var kFIRAuthErrorMessageNullUser
  344. @brief Message for @c FIRAuthErrorCodeNullUser error code.
  345. */
  346. static NSString *const kFIRAuthErrorMessageNullUser = @"A null user object was provided as the "
  347. "argument for an operation which requires a non-null user object.";
  348. /** @var kFIRAuthErrorMessageInvalidDynamicLinkDomain
  349. @brief Message for @c kFIRAuthErrorMessageInvalidDynamicLinkDomain error code.
  350. */
  351. static NSString *const kFIRAuthErrorMessageInvalidDynamicLinkDomain = @"The "
  352. "Firebase Dynamic Link domain used is either not configured or is unauthorized "
  353. "for the current project.";
  354. /** @var kFIRAuthErrorMessageInternalError
  355. @brief Message for @c FIRAuthErrorCodeInternalError error code.
  356. */
  357. static NSString *const kFIRAuthErrorMessageInternalError = @"An internal error has occurred, "
  358. "print and inspect the error details for more information.";
  359. /** @var kFIRAuthErrorMessageMalformedJWT
  360. @brief Error message constant describing @c FIRAuthErrorCodeMalformedJWT errors.
  361. */
  362. static NSString *const kFIRAuthErrorMessageMalformedJWT =
  363. @"Failed to parse JWT. Check the userInfo dictionary for the full token.";
  364. /** @var FIRAuthErrorDescription
  365. @brief The error descrioption, based on the error code.
  366. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  367. */
  368. static NSString *FIRAuthErrorDescription(FIRAuthErrorCode code) {
  369. switch (code) {
  370. case FIRAuthErrorCodeInvalidCustomToken:
  371. return kFIRAuthErrorMessageInvalidCustomToken;
  372. case FIRAuthErrorCodeCustomTokenMismatch:
  373. return kFIRAuthErrorMessageCustomTokenMismatch;
  374. case FIRAuthErrorCodeInvalidEmail:
  375. return kFIRAuthErrorMessageInvalidEmail;
  376. case FIRAuthErrorCodeInvalidCredential:
  377. return kFIRAuthErrorMessageInvalidCredential;
  378. case FIRAuthErrorCodeUserDisabled:
  379. return kFIRAuthErrorMessageUserDisabled;
  380. case FIRAuthErrorCodeEmailAlreadyInUse:
  381. return kFIRAuthErrorMessageEmailAlreadyInUse;
  382. case FIRAuthErrorCodeWrongPassword:
  383. return kFIRAuthErrorMessageWrongPassword;
  384. case FIRAuthErrorCodeTooManyRequests:
  385. return kFIRAuthErrorMessageTooManyRequests;
  386. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  387. return kFIRAuthErrorMessageAccountExistsWithDifferentCredential;
  388. case FIRAuthErrorCodeRequiresRecentLogin:
  389. return kFIRAuthErrorMessageRequiresRecentLogin;
  390. case FIRAuthErrorCodeProviderAlreadyLinked:
  391. return kFIRAuthErrorMessageProviderAlreadyLinked;
  392. case FIRAuthErrorCodeNoSuchProvider:
  393. return kFIRAuthErrorMessageNoSuchProvider;
  394. case FIRAuthErrorCodeInvalidUserToken:
  395. return kFIRAuthErrorMessageInvalidUserToken;
  396. case FIRAuthErrorCodeNetworkError:
  397. return kFIRAuthErrorMessageNetworkError;
  398. case FIRAuthErrorCodeKeychainError:
  399. return kFIRAuthErrorMessageKeychainError;
  400. case FIRAuthErrorCodeUserTokenExpired:
  401. return kFIRAuthErrorMessageUserTokenExpired;
  402. case FIRAuthErrorCodeUserNotFound:
  403. return kFIRAuthErrorMessageUserNotFound;
  404. case FIRAuthErrorCodeInvalidAPIKey:
  405. return kFIRAuthErrorMessageInvalidAPIKey;
  406. case FIRAuthErrorCodeCredentialAlreadyInUse:
  407. return kFIRAuthErrorMessageCredentialAlreadyInUse;
  408. case FIRAuthErrorCodeInternalError:
  409. return kFIRAuthErrorMessageInternalError;
  410. case FIRAuthErrorCodeUserMismatch:
  411. return FIRAuthErrorMessageUserMismatch;
  412. case FIRAuthErrorCodeOperationNotAllowed:
  413. return kFIRAuthErrorMessageOperationNotAllowed;
  414. case FIRAuthErrorCodeWeakPassword:
  415. return kFIRAuthErrorMessageWeakPassword;
  416. case FIRAuthErrorCodeAppNotAuthorized:
  417. return kFIRAuthErrorMessageAppNotAuthorized;
  418. case FIRAuthErrorCodeExpiredActionCode:
  419. return kFIRAuthErrorMessageExpiredActionCode;
  420. case FIRAuthErrorCodeInvalidActionCode:
  421. return kFIRAuthErrorMessageInvalidActionCode;
  422. case FIRAuthErrorCodeInvalidSender:
  423. return kFIRAuthErrorMessageInvalidSender;
  424. case FIRAuthErrorCodeInvalidMessagePayload:
  425. return kFIRAuthErrorMessageInvalidMessagePayload;
  426. case FIRAuthErrorCodeInvalidRecipientEmail:
  427. return kFIRAuthErrorMessageInvalidRecipientEmail;
  428. case FIRAuthErrorCodeMissingIosBundleID:
  429. return kFIRAuthErrorMessageMissingIosBundleID;
  430. case FIRAuthErrorCodeMissingAndroidPackageName:
  431. return kFIRAuthErrorMessageMissingAndroidPackageName;
  432. case FIRAuthErrorCodeUnauthorizedDomain:
  433. return kFIRAuthErrorMessageUnauthorizedDomain;
  434. case FIRAuthErrorCodeInvalidContinueURI:
  435. return kFIRAuthErrorMessageInvalidContinueURI;
  436. case FIRAuthErrorCodeMissingContinueURI:
  437. return kFIRAuthErrorMessageMissingContinueURI;
  438. case FIRAuthErrorCodeMissingEmail:
  439. return kFIRAuthErrorMessageMissingEmail;
  440. case FIRAuthErrorCodeMissingPhoneNumber:
  441. return kFIRAuthErrorMessageMissingPhoneNumber;
  442. case FIRAuthErrorCodeInvalidPhoneNumber:
  443. return kFIRAuthErrorMessageInvalidPhoneNumber;
  444. case FIRAuthErrorCodeMissingVerificationCode:
  445. return kFIRAuthErrorMessageMissingVerificationCode;
  446. case FIRAuthErrorCodeInvalidVerificationCode:
  447. return kFIRAuthErrorMessageInvalidVerificationCode;
  448. case FIRAuthErrorCodeMissingVerificationID:
  449. return kFIRAuthErrorMessageMissingVerificationID;
  450. case FIRAuthErrorCodeInvalidVerificationID:
  451. return kFIRAuthErrorMessageInvalidVerificationID;
  452. case FIRAuthErrorCodeSessionExpired:
  453. return kFIRAuthErrorMessageSessionExpired;
  454. case FIRAuthErrorCodeMissingAppCredential:
  455. return kFIRAuthErrorMessageMissingAppCredential;
  456. case FIRAuthErrorCodeInvalidAppCredential:
  457. return kFIRAuthErrorMessageInvalidAppCredential;
  458. case FIRAuthErrorCodeQuotaExceeded:
  459. return kFIRAuthErrorMessageQuotaExceeded;
  460. case FIRAuthErrorCodeMissingAppToken:
  461. return kFIRAuthErrorMessageMissingAppToken;
  462. case FIRAuthErrorCodeNotificationNotForwarded:
  463. return kFIRAuthErrorMessageNotificationNotForwarded;
  464. case FIRAuthErrorCodeAppNotVerified:
  465. return kFIRAuthErrorMessageAppNotVerified;
  466. case FIRAuthErrorCodeCaptchaCheckFailed:
  467. return kFIRAuthErrorMessageCaptchaCheckFailed;
  468. case FIRAuthErrorCodeWebContextAlreadyPresented:
  469. return kFIRAuthErrorMessageWebContextAlreadyPresented;
  470. case FIRAuthErrorCodeWebContextCancelled:
  471. return kFIRAuthErrorMessageWebContextCancelled;
  472. case FIRAuthErrorCodeInvalidClientID:
  473. return kFIRAuthErrorMessageInvalidClientID;
  474. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  475. return kFIRAuthErrorMessageAppVerificationUserInteractionFailure;
  476. case FIRAuthErrorCodeWebNetworkRequestFailed:
  477. return kFIRAuthErrorMessageWebRequestFailed;
  478. case FIRAuthErrorCodeNullUser:
  479. return kFIRAuthErrorMessageNullUser;
  480. case FIRAuthErrorCodeInvalidDynamicLinkDomain:
  481. return kFIRAuthErrorMessageInvalidDynamicLinkDomain;
  482. case FIRAuthErrorCodeWebInternalError:
  483. return kFIRAuthErrorMessageWebInternalError;
  484. case FIRAuthErrorCodeMalformedJWT:
  485. return kFIRAuthErrorMessageMalformedJWT;
  486. case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
  487. return kFIRAuthErrorMessageLocalPlayerNotAuthenticated;
  488. case FIRAuthErrorCodeGameKitNotLinked:
  489. return kFIRAuthErrorMessageGameKitNotLinked;
  490. }
  491. }
  492. /** @var FIRAuthErrorCodeString
  493. @brief The the error short string, based on the error code.
  494. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  495. */
  496. static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
  497. switch (code) {
  498. case FIRAuthErrorCodeInvalidCustomToken:
  499. return @"ERROR_INVALID_CUSTOM_TOKEN";
  500. case FIRAuthErrorCodeCustomTokenMismatch:
  501. return @"ERROR_CUSTOM_TOKEN_MISMATCH";
  502. case FIRAuthErrorCodeInvalidEmail:
  503. return @"ERROR_INVALID_EMAIL";
  504. case FIRAuthErrorCodeInvalidCredential:
  505. return @"ERROR_INVALID_CREDENTIAL";
  506. case FIRAuthErrorCodeUserDisabled:
  507. return @"ERROR_USER_DISABLED";
  508. case FIRAuthErrorCodeEmailAlreadyInUse:
  509. return @"ERROR_EMAIL_ALREADY_IN_USE";
  510. case FIRAuthErrorCodeWrongPassword:
  511. return @"ERROR_WRONG_PASSWORD";
  512. case FIRAuthErrorCodeTooManyRequests:
  513. return @"ERROR_TOO_MANY_REQUESTS";
  514. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  515. return @"ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL";
  516. case FIRAuthErrorCodeRequiresRecentLogin:
  517. return @"ERROR_REQUIRES_RECENT_LOGIN";
  518. case FIRAuthErrorCodeProviderAlreadyLinked:
  519. return @"ERROR_PROVIDER_ALREADY_LINKED";
  520. case FIRAuthErrorCodeNoSuchProvider:
  521. return @"ERROR_NO_SUCH_PROVIDER";
  522. case FIRAuthErrorCodeInvalidUserToken:
  523. return @"ERROR_INVALID_USER_TOKEN";
  524. case FIRAuthErrorCodeNetworkError:
  525. return @"ERROR_NETWORK_REQUEST_FAILED";
  526. case FIRAuthErrorCodeKeychainError:
  527. return @"ERROR_KEYCHAIN_ERROR";
  528. case FIRAuthErrorCodeUserTokenExpired:
  529. return @"ERROR_USER_TOKEN_EXPIRED";
  530. case FIRAuthErrorCodeUserNotFound:
  531. return @"ERROR_USER_NOT_FOUND";
  532. case FIRAuthErrorCodeInvalidAPIKey:
  533. return @"ERROR_INVALID_API_KEY";
  534. case FIRAuthErrorCodeCredentialAlreadyInUse:
  535. return @"ERROR_CREDENTIAL_ALREADY_IN_USE";
  536. case FIRAuthErrorCodeInternalError:
  537. return @"ERROR_INTERNAL_ERROR";
  538. case FIRAuthErrorCodeUserMismatch:
  539. return @"ERROR_USER_MISMATCH";
  540. case FIRAuthErrorCodeOperationNotAllowed:
  541. return @"ERROR_OPERATION_NOT_ALLOWED";
  542. case FIRAuthErrorCodeWeakPassword:
  543. return @"ERROR_WEAK_PASSWORD";
  544. case FIRAuthErrorCodeAppNotAuthorized:
  545. return @"ERROR_APP_NOT_AUTHORIZED";
  546. case FIRAuthErrorCodeExpiredActionCode:
  547. return @"ERROR_EXPIRED_ACTION_CODE";
  548. case FIRAuthErrorCodeInvalidActionCode:
  549. return @"ERROR_INVALID_ACTION_CODE";
  550. case FIRAuthErrorCodeInvalidMessagePayload:
  551. return @"ERROR_INVALID_MESSAGE_PAYLOAD";
  552. case FIRAuthErrorCodeInvalidSender:
  553. return @"ERROR_INVALID_SENDER";
  554. case FIRAuthErrorCodeInvalidRecipientEmail:
  555. return @"ERROR_INVALID_RECIPIENT_EMAIL";
  556. case FIRAuthErrorCodeMissingIosBundleID:
  557. return @"ERROR_MISSING_IOS_BUNDLE_ID";
  558. case FIRAuthErrorCodeMissingAndroidPackageName:
  559. return @"ERROR_MISSING_ANDROID_PKG_NAME";
  560. case FIRAuthErrorCodeUnauthorizedDomain:
  561. return @"ERROR_UNAUTHORIZED_DOMAIN";
  562. case FIRAuthErrorCodeInvalidContinueURI:
  563. return @"ERROR_INVALID_CONTINUE_URI";
  564. case FIRAuthErrorCodeMissingContinueURI:
  565. return @"ERROR_MISSING_CONTINUE_URI";
  566. case FIRAuthErrorCodeMissingEmail:
  567. return @"ERROR_MISSING_EMAIL";
  568. case FIRAuthErrorCodeMissingPhoneNumber:
  569. return @"ERROR_MISSING_PHONE_NUMBER";
  570. case FIRAuthErrorCodeInvalidPhoneNumber:
  571. return @"ERROR_INVALID_PHONE_NUMBER";
  572. case FIRAuthErrorCodeMissingVerificationCode:
  573. return @"ERROR_MISSING_VERIFICATION_CODE";
  574. case FIRAuthErrorCodeInvalidVerificationCode:
  575. return @"ERROR_INVALID_VERIFICATION_CODE";
  576. case FIRAuthErrorCodeMissingVerificationID:
  577. return @"ERROR_MISSING_VERIFICATION_ID";
  578. case FIRAuthErrorCodeInvalidVerificationID:
  579. return @"ERROR_INVALID_VERIFICATION_ID";
  580. case FIRAuthErrorCodeSessionExpired:
  581. return @"ERROR_SESSION_EXPIRED";
  582. case FIRAuthErrorCodeMissingAppCredential:
  583. return @"MISSING_APP_CREDENTIAL";
  584. case FIRAuthErrorCodeInvalidAppCredential:
  585. return @"INVALID_APP_CREDENTIAL";
  586. case FIRAuthErrorCodeQuotaExceeded:
  587. return @"ERROR_QUOTA_EXCEEDED";
  588. case FIRAuthErrorCodeMissingAppToken:
  589. return @"ERROR_MISSING_APP_TOKEN";
  590. case FIRAuthErrorCodeNotificationNotForwarded:
  591. return @"ERROR_NOTIFICATION_NOT_FORWARDED";
  592. case FIRAuthErrorCodeAppNotVerified:
  593. return @"ERROR_APP_NOT_VERIFIED";
  594. case FIRAuthErrorCodeCaptchaCheckFailed:
  595. return @"ERROR_CAPTCHA_CHECK_FAILED";
  596. case FIRAuthErrorCodeWebContextAlreadyPresented:
  597. return @"ERROR_WEB_CONTEXT_ALREADY_PRESENTED";
  598. case FIRAuthErrorCodeWebContextCancelled:
  599. return @"ERROR_WEB_CONTEXT_CANCELLED";
  600. case FIRAuthErrorCodeInvalidClientID:
  601. return @"ERROR_INVALID_CLIENT_ID";
  602. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  603. return @"ERROR_APP_VERIFICATION_FAILED";
  604. case FIRAuthErrorCodeWebNetworkRequestFailed:
  605. return @"ERROR_WEB_NETWORK_REQUEST_FAILED";
  606. case FIRAuthErrorCodeNullUser:
  607. return @"ERROR_NULL_USER";
  608. case FIRAuthErrorCodeInvalidDynamicLinkDomain:
  609. return @"ERROR_INVALID_DYNAMIC_LINK_DOMAIN";
  610. case FIRAuthErrorCodeWebInternalError:
  611. return @"ERROR_WEB_INTERNAL_ERROR";
  612. case FIRAuthErrorCodeMalformedJWT:
  613. return @"ERROR_MALFORMED_JWT";
  614. case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
  615. return @"ERROR_LOCAL_PLAYER_NOT_AUTHENTICATED";
  616. case FIRAuthErrorCodeGameKitNotLinked:
  617. return @"ERROR_GAME_KIT_NOT_LINKED";
  618. }
  619. }
  620. @implementation FIRAuthErrorUtils
  621. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code {
  622. return [self errorWithCode:code message:nil];
  623. }
  624. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  625. message:(nullable NSString *)message {
  626. NSDictionary *userInfo = nil;
  627. if (message.length) {
  628. userInfo = @{
  629. NSLocalizedDescriptionKey : message
  630. };
  631. }
  632. return [self errorWithCode:code userInfo:userInfo];
  633. }
  634. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  635. underlyingError:(nullable NSError *)underlyingError {
  636. NSDictionary *errorUserInfo = nil;
  637. if (underlyingError) {
  638. errorUserInfo = @{
  639. NSUnderlyingErrorKey : underlyingError
  640. };
  641. }
  642. return [self errorWithCode:code userInfo:errorUserInfo];
  643. }
  644. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  645. userInfo:(nullable NSDictionary *)userInfo {
  646. BOOL isPublic = (code & FIRAuthPublicErrorCodeFlag) == FIRAuthPublicErrorCodeFlag;
  647. if (isPublic) {
  648. // This is a public error. Return it as a public error and add a description.
  649. NSInteger errorCode = code & ~FIRAuthPublicErrorCodeFlag;
  650. NSMutableDictionary *errorUserInfo = [NSMutableDictionary dictionaryWithDictionary:userInfo];
  651. if (!errorUserInfo[NSLocalizedDescriptionKey]) {
  652. errorUserInfo[NSLocalizedDescriptionKey] = FIRAuthErrorDescription(errorCode);
  653. }
  654. errorUserInfo[FIRAuthErrorNameKey] = FIRAuthErrorCodeString(errorCode);
  655. return [NSError errorWithDomain:FIRAuthErrorDomain code:errorCode userInfo:errorUserInfo];
  656. } else {
  657. // This is an internal error. Wrap it in an internal error.
  658. NSError *error =
  659. [NSError errorWithDomain:FIRAuthInternalErrorDomain code:code userInfo:userInfo];
  660. return [self errorWithCode:FIRAuthInternalErrorCodeInternalError underlyingError:error];
  661. }
  662. }
  663. + (NSError *)RPCRequestEncodingErrorWithUnderlyingError:(NSError *)underlyingError {
  664. return [self errorWithCode:FIRAuthInternalErrorCodeRPCRequestEncodingError
  665. underlyingError:underlyingError];
  666. }
  667. + (NSError *)JSONSerializationErrorForUnencodableType {
  668. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError];
  669. }
  670. + (NSError *)JSONSerializationErrorWithUnderlyingError:(NSError *)underlyingError {
  671. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError
  672. underlyingError:underlyingError];
  673. }
  674. + (NSError *)networkErrorWithUnderlyingError:(NSError *)underlyingError {
  675. return [self errorWithCode:FIRAuthInternalErrorCodeNetworkError
  676. underlyingError:underlyingError];
  677. }
  678. + (NSError *)unexpectedErrorResponseWithData:(NSData *)data
  679. underlyingError:(NSError *)underlyingError {
  680. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse userInfo:@{
  681. FIRAuthErrorUserInfoDataKey : data,
  682. NSUnderlyingErrorKey : underlyingError
  683. }];
  684. }
  685. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse {
  686. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse userInfo:@{
  687. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse
  688. }];
  689. }
  690. + (NSError *)malformedJWTErrorWithToken:(NSString *)token
  691. underlyingError:(NSError *_Nullable)underlyingError {
  692. NSMutableDictionary *userInfo =
  693. [NSMutableDictionary dictionaryWithObject:kFIRAuthErrorMessageMalformedJWT
  694. forKey:NSLocalizedDescriptionKey];
  695. [userInfo setObject:token forKey:FIRAuthErrorUserInfoDataKey];
  696. if (underlyingError != nil) {
  697. [userInfo setObject:underlyingError forKey:NSUnderlyingErrorKey];
  698. }
  699. return [self errorWithCode:FIRAuthInternalErrorCodeMalformedJWT userInfo:[userInfo copy]];
  700. }
  701. + (NSError *)unexpectedResponseWithData:(NSData *)data
  702. underlyingError:(NSError *)underlyingError {
  703. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:@{
  704. FIRAuthErrorUserInfoDataKey : data,
  705. NSUnderlyingErrorKey : underlyingError
  706. }];
  707. }
  708. + (NSError *)unexpectedResponseWithDeserializedResponse:(id)deserializedResponse {
  709. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:@{
  710. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse
  711. }];
  712. }
  713. + (NSError *)unexpectedResponseWithDeserializedResponse:(nullable id)deserializedResponse
  714. underlyingError:(NSError *)underlyingError {
  715. NSMutableDictionary *userInfo =
  716. [NSMutableDictionary dictionaryWithDictionary:@{ NSUnderlyingErrorKey : underlyingError }];
  717. if (deserializedResponse) {
  718. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  719. }
  720. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:userInfo];
  721. }
  722. + (NSError *)RPCResponseDecodingErrorWithDeserializedResponse:(id)deserializedResponse
  723. underlyingError:(NSError *)underlyingError {
  724. return [self errorWithCode:FIRAuthInternalErrorCodeRPCResponseDecodingError userInfo:@{
  725. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse,
  726. NSUnderlyingErrorKey : underlyingError
  727. }];
  728. }
  729. + (NSError *)emailAlreadyInUseErrorWithEmail:(nullable NSString *)email {
  730. NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
  731. if (email.length) {
  732. userInfo[FIRAuthErrorUserInfoEmailKey] = email;
  733. }
  734. return [self errorWithCode:FIRAuthInternalErrorCodeEmailAlreadyInUse userInfo:userInfo];
  735. }
  736. + (NSError *)userDisabledErrorWithMessage:(nullable NSString *)message {
  737. return [self errorWithCode:FIRAuthInternalErrorCodeUserDisabled message:message];
  738. }
  739. + (NSError *)wrongPasswordErrorWithMessage:(nullable NSString *)message {
  740. return [self errorWithCode:FIRAuthInternalErrorCodeWrongPassword message:message];
  741. }
  742. + (NSError *)tooManyRequestsErrorWithMessage:(nullable NSString *)message {
  743. return [self errorWithCode:FIRAuthInternalErrorCodeTooManyRequests message:message];
  744. }
  745. + (NSError *)invalidCustomTokenErrorWithMessage:(nullable NSString *)message {
  746. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCustomToken message:message];
  747. }
  748. + (NSError *)customTokenMistmatchErrorWithMessage:(nullable NSString *)message {
  749. return [self errorWithCode:FIRAuthInternalErrorCodeCustomTokenMismatch message:message];
  750. }
  751. + (NSError *)invalidCredentialErrorWithMessage:(nullable NSString *)message {
  752. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCredential message:message];
  753. }
  754. + (NSError *)requiresRecentLoginErrorWithMessage:(nullable NSString *)message {
  755. return [self errorWithCode:FIRAuthInternalErrorCodeRequiresRecentLogin message:message];
  756. }
  757. + (NSError *)invalidUserTokenErrorWithMessage:(nullable NSString *)message {
  758. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidUserToken message:message];
  759. }
  760. + (NSError *)invalidEmailErrorWithMessage:(nullable NSString *)message {
  761. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidEmail message:message];
  762. }
  763. + (NSError *)accountExistsWithDifferentCredentialErrorWithEmail:(nullable NSString *)email {
  764. return [self errorWithCode:FIRAuthInternalErrorCodeAccountExistsWithDifferentCredential
  765. userInfo:@{ FIRAuthErrorUserInfoEmailKey : email }];
  766. }
  767. + (NSError *)providerAlreadyLinkedError {
  768. return [self errorWithCode:FIRAuthInternalErrorCodeProviderAlreadyLinked];
  769. }
  770. + (NSError *)noSuchProviderError {
  771. return [self errorWithCode:FIRAuthInternalErrorCodeNoSuchProvider];
  772. }
  773. + (NSError *)userTokenExpiredErrorWithMessage:(nullable NSString *)message {
  774. return [self errorWithCode:FIRAuthInternalErrorCodeUserTokenExpired message:message];
  775. }
  776. + (NSError *)userNotFoundErrorWithMessage:(nullable NSString *)message {
  777. return [self errorWithCode:FIRAuthInternalErrorCodeUserNotFound message:message];
  778. }
  779. + (NSError *)invalidAPIKeyError {
  780. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAPIKey];
  781. }
  782. + (NSError *)userMismatchError {
  783. return [self errorWithCode:FIRAuthInternalErrorCodeUserMismatch];
  784. }
  785. + (NSError *)credentialAlreadyInUseErrorWithMessage:(nullable NSString *)message
  786. credential:(nullable FIRPhoneAuthCredential *)credential {
  787. if (credential) {
  788. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse
  789. userInfo:@{ FIRAuthUpdatedCredentialKey : credential }];
  790. }
  791. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse message:message];
  792. }
  793. + (NSError *)operationNotAllowedErrorWithMessage:(nullable NSString *)message {
  794. return [self errorWithCode:FIRAuthInternalErrorCodeOperationNotAllowed message:message];
  795. }
  796. + (NSError *)weakPasswordErrorWithServerResponseReason:(nullable NSString *)reason {
  797. return [self errorWithCode:FIRAuthInternalErrorCodeWeakPassword userInfo:@{
  798. NSLocalizedFailureReasonErrorKey : reason
  799. }];
  800. }
  801. + (NSError *)appNotAuthorizedError {
  802. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotAuthorized];
  803. }
  804. + (NSError *)expiredActionCodeErrorWithMessage:(nullable NSString *)message {
  805. return [self errorWithCode:FIRAuthInternalErrorCodeExpiredActionCode message:message];
  806. }
  807. + (NSError *)invalidActionCodeErrorWithMessage:(nullable NSString *)message {
  808. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidActionCode message:message];
  809. }
  810. + (NSError *)invalidMessagePayloadErrorWithMessage:(nullable NSString *)message {
  811. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidMessagePayload message:message];
  812. }
  813. + (NSError *)invalidSenderErrorWithMessage:(nullable NSString *)message {
  814. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidSender message:message];
  815. }
  816. + (NSError *)invalidRecipientEmailErrorWithMessage:(nullable NSString *)message {
  817. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidRecipientEmail message:message];
  818. }
  819. + (NSError *)missingIosBundleIDErrorWithMessage:(nullable NSString *)message {
  820. return [self errorWithCode:FIRAuthinternalErrorCodeMissingIosBundleID message:message];
  821. }
  822. + (NSError *)missingAndroidPackageNameErrorWithMessage:(nullable NSString *)message {
  823. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAndroidPackageName message:message];
  824. }
  825. + (NSError *)unauthorizedDomainErrorWithMessage:(nullable NSString *)message {
  826. return [self errorWithCode:FIRAuthInternalErrorCodeUnauthorizedDomain message:message];
  827. }
  828. + (NSError *)invalidContinueURIErrorWithMessage:(nullable NSString *)message {
  829. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidContinueURI message:message];
  830. }
  831. + (NSError *)missingContinueURIErrorWithMessage:(nullable NSString *)message {
  832. return[self errorWithCode:FIRAuthInternalErrorCodeMissingContinueURI message:message];
  833. }
  834. + (NSError *)missingEmailErrorWithMessage:(nullable NSString *)message {
  835. return [self errorWithCode:FIRAuthInternalErrorCodeMissingEmail message:message];
  836. }
  837. + (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message {
  838. return [self errorWithCode:FIRAuthInternalErrorCodeMissingPhoneNumber message:message];
  839. }
  840. + (NSError *)invalidPhoneNumberErrorWithMessage:(nullable NSString *)message {
  841. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidPhoneNumber message:message];
  842. }
  843. + (NSError *)missingVerificationCodeErrorWithMessage:(nullable NSString *)message {
  844. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationCode message:message];
  845. }
  846. + (NSError *)invalidVerificationCodeErrorWithMessage:(nullable NSString *)message {
  847. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationCode message:message];
  848. }
  849. + (NSError *)missingVerificationIDErrorWithMessage:(nullable NSString *)message {
  850. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationID message:message];
  851. }
  852. + (NSError *)invalidVerificationIDErrorWithMessage:(nullable NSString *)message {
  853. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationID message:message];
  854. }
  855. + (NSError *)sessionExpiredErrorWithMessage:(nullable NSString *)message {
  856. return [self errorWithCode:FIRAuthInternalErrorCodeSessionExpired message:message];
  857. }
  858. + (NSError *)missingAppCredentialWithMessage:(nullable NSString *)message {
  859. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppCredential message:message];
  860. }
  861. + (NSError *)invalidAppCredentialWithMessage:(nullable NSString *)message {
  862. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAppCredential message:message];
  863. }
  864. + (NSError *)quotaExceededErrorWithMessage:(nullable NSString *)message {
  865. return [self errorWithCode:FIRAuthInternalErrorCodeQuotaExceeded message:message];
  866. }
  867. + (NSError *)missingAppTokenErrorWithUnderlyingError:(nullable NSError *)underlyingError {
  868. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppToken
  869. underlyingError:underlyingError];
  870. }
  871. + (NSError *)localPlayerNotAuthenticatedError {
  872. return [self errorWithCode:FIRAuthInternalErrorCodeLocalPlayerNotAuthenticated];
  873. }
  874. + (NSError *)gameKitNotLinkedError {
  875. return [self errorWithCode:FIRAuthInternalErrorCodeGameKitNotLinked];
  876. }
  877. + (NSError *)notificationNotForwardedError {
  878. return [self errorWithCode:FIRAuthInternalErrorCodeNotificationNotForwarded];
  879. }
  880. + (NSError *)appNotVerifiedErrorWithMessage:(nullable NSString *)message {
  881. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotVerified message:message];
  882. }
  883. + (NSError *)captchaCheckFailedErrorWithMessage:(nullable NSString *)message {
  884. return [self errorWithCode:FIRAuthInternalErrorCodeCaptchaCheckFailed message:message];
  885. }
  886. + (NSError *)webContextAlreadyPresentedErrorWithMessage:(nullable NSString *)message {
  887. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextAlreadyPresented message:message];
  888. }
  889. + (NSError *)webContextCancelledErrorWithMessage:(nullable NSString *)message {
  890. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextCancelled message:message];
  891. }
  892. + (NSError *)appVerificationUserInteractionFailureWithReason:(NSString *)reason {
  893. return [self errorWithCode:FIRAuthInternalErrorCodeAppVerificationUserInteractionFailure
  894. userInfo:@{
  895. NSLocalizedFailureReasonErrorKey : reason
  896. }];
  897. }
  898. + (nullable NSError *)URLResponseErrorWithCode:(NSString *)code message:(nullable NSString *)message {
  899. if ([code isEqualToString:kURLResponseErrorCodeInvalidClientID]) {
  900. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidClientID message:message];
  901. }
  902. if ([code isEqualToString:kURLResponseErrorCodeNetworkRequestFailed]) {
  903. return [self errorWithCode:FIRAuthInternalErrorCodeWebNetworkRequestFailed message:message];
  904. }
  905. if ([code isEqualToString:kURLResponseErrorCodeInternalError]) {
  906. return [self errorWithCode:FIRAuthInternalErrorCodeWebInternalError message:message];
  907. }
  908. return nil;
  909. }
  910. + (NSError *)nullUserErrorWithMessage:(nullable NSString *)message {
  911. return [self errorWithCode:FIRAuthInternalErrorCodeNullUser message:message];
  912. }
  913. + (NSError *)invalidDynamicLinkDomainErrorWithMessage:(nullable NSString *)message {
  914. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidDynamicLinkDomain message:message];
  915. }
  916. + (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status {
  917. NSString *failureReason = [NSString stringWithFormat:@"%@ (%li)", keychainFunction, (long)status];
  918. return [self errorWithCode:FIRAuthInternalErrorCodeKeychainError userInfo:@{
  919. NSLocalizedFailureReasonErrorKey : failureReason,
  920. }];
  921. }
  922. @end
  923. NS_ASSUME_NONNULL_END