FIRAuthErrorUtils.m 50 KB

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