FIRAuthErrorUtils.m 46 KB

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