No Description

FIRAuthErrorUtils.m 51KB

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