No Description

FIRAuthErrorUtils.m 49KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  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 kFIRAuthErrorMessageInvalidDynamicLinkDomain
  352. @brief Message for @c kFIRAuthErrorMessageInvalidDynamicLinkDomain error code.
  353. */
  354. static NSString *const kFIRAuthErrorMessageInvalidDynamicLinkDomain = @"The "
  355. "Firebase Dynamic Link domain used is either not configured or is unauthorized "
  356. "for the current project.";
  357. /** @var kFIRAuthErrorMessageInternalError
  358. @brief Message for @c FIRAuthErrorCodeInternalError error code.
  359. */
  360. static NSString *const kFIRAuthErrorMessageInternalError = @"An internal error has occurred, "
  361. "print and inspect the error details for more information.";
  362. /** @var kFIRAuthErrorMessageMalformedJWT
  363. @brief Error message constant describing @c FIRAuthErrorCodeMalformedJWT errors.
  364. */
  365. static NSString *const kFIRAuthErrorMessageMalformedJWT =
  366. @"Failed to parse JWT. Check the userInfo dictionary for the full token.";
  367. /** @var FIRAuthErrorDescription
  368. @brief The error descrioption, based on the error code.
  369. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  370. */
  371. static NSString *FIRAuthErrorDescription(FIRAuthErrorCode code) {
  372. switch (code) {
  373. case FIRAuthErrorCodeInvalidCustomToken:
  374. return kFIRAuthErrorMessageInvalidCustomToken;
  375. case FIRAuthErrorCodeCustomTokenMismatch:
  376. return kFIRAuthErrorMessageCustomTokenMismatch;
  377. case FIRAuthErrorCodeInvalidEmail:
  378. return kFIRAuthErrorMessageInvalidEmail;
  379. case FIRAuthErrorCodeInvalidCredential:
  380. return kFIRAuthErrorMessageInvalidCredential;
  381. case FIRAuthErrorCodeUserDisabled:
  382. return kFIRAuthErrorMessageUserDisabled;
  383. case FIRAuthErrorCodeEmailAlreadyInUse:
  384. return kFIRAuthErrorMessageEmailAlreadyInUse;
  385. case FIRAuthErrorCodeWrongPassword:
  386. return kFIRAuthErrorMessageWrongPassword;
  387. case FIRAuthErrorCodeTooManyRequests:
  388. return kFIRAuthErrorMessageTooManyRequests;
  389. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  390. return kFIRAuthErrorMessageAccountExistsWithDifferentCredential;
  391. case FIRAuthErrorCodeRequiresRecentLogin:
  392. return kFIRAuthErrorMessageRequiresRecentLogin;
  393. case FIRAuthErrorCodeProviderAlreadyLinked:
  394. return kFIRAuthErrorMessageProviderAlreadyLinked;
  395. case FIRAuthErrorCodeNoSuchProvider:
  396. return kFIRAuthErrorMessageNoSuchProvider;
  397. case FIRAuthErrorCodeInvalidUserToken:
  398. return kFIRAuthErrorMessageInvalidUserToken;
  399. case FIRAuthErrorCodeNetworkError:
  400. return kFIRAuthErrorMessageNetworkError;
  401. case FIRAuthErrorCodeKeychainError:
  402. return kFIRAuthErrorMessageKeychainError;
  403. case FIRAuthErrorCodeUserTokenExpired:
  404. return kFIRAuthErrorMessageUserTokenExpired;
  405. case FIRAuthErrorCodeUserNotFound:
  406. return kFIRAuthErrorMessageUserNotFound;
  407. case FIRAuthErrorCodeInvalidAPIKey:
  408. return kFIRAuthErrorMessageInvalidAPIKey;
  409. case FIRAuthErrorCodeCredentialAlreadyInUse:
  410. return kFIRAuthErrorMessageCredentialAlreadyInUse;
  411. case FIRAuthErrorCodeInternalError:
  412. return kFIRAuthErrorMessageInternalError;
  413. case FIRAuthErrorCodeUserMismatch:
  414. return FIRAuthErrorMessageUserMismatch;
  415. case FIRAuthErrorCodeOperationNotAllowed:
  416. return kFIRAuthErrorMessageOperationNotAllowed;
  417. case FIRAuthErrorCodeWeakPassword:
  418. return kFIRAuthErrorMessageWeakPassword;
  419. case FIRAuthErrorCodeAppNotAuthorized:
  420. return kFIRAuthErrorMessageAppNotAuthorized;
  421. case FIRAuthErrorCodeExpiredActionCode:
  422. return kFIRAuthErrorMessageExpiredActionCode;
  423. case FIRAuthErrorCodeInvalidActionCode:
  424. return kFIRAuthErrorMessageInvalidActionCode;
  425. case FIRAuthErrorCodeInvalidSender:
  426. return kFIRAuthErrorMessageInvalidSender;
  427. case FIRAuthErrorCodeInvalidMessagePayload:
  428. return kFIRAuthErrorMessageInvalidMessagePayload;
  429. case FIRAuthErrorCodeInvalidRecipientEmail:
  430. return kFIRAuthErrorMessageInvalidRecipientEmail;
  431. case FIRAuthErrorCodeMissingIosBundleID:
  432. return kFIRAuthErrorMessageMissingIosBundleID;
  433. case FIRAuthErrorCodeMissingAndroidPackageName:
  434. return kFIRAuthErrorMessageMissingAndroidPackageName;
  435. case FIRAuthErrorCodeUnauthorizedDomain:
  436. return kFIRAuthErrorMessageUnauthorizedDomain;
  437. case FIRAuthErrorCodeInvalidContinueURI:
  438. return kFIRAuthErrorMessageInvalidContinueURI;
  439. case FIRAuthErrorCodeMissingContinueURI:
  440. return kFIRAuthErrorMessageMissingContinueURI;
  441. case FIRAuthErrorCodeMissingEmail:
  442. return kFIRAuthErrorMessageMissingEmail;
  443. case FIRAuthErrorCodeMissingPhoneNumber:
  444. return kFIRAuthErrorMessageMissingPhoneNumber;
  445. case FIRAuthErrorCodeInvalidPhoneNumber:
  446. return kFIRAuthErrorMessageInvalidPhoneNumber;
  447. case FIRAuthErrorCodeMissingVerificationCode:
  448. return kFIRAuthErrorMessageMissingVerificationCode;
  449. case FIRAuthErrorCodeInvalidVerificationCode:
  450. return kFIRAuthErrorMessageInvalidVerificationCode;
  451. case FIRAuthErrorCodeMissingVerificationID:
  452. return kFIRAuthErrorMessageMissingVerificationID;
  453. case FIRAuthErrorCodeInvalidVerificationID:
  454. return kFIRAuthErrorMessageInvalidVerificationID;
  455. case FIRAuthErrorCodeSessionExpired:
  456. return kFIRAuthErrorMessageSessionExpired;
  457. case FIRAuthErrorCodeMissingAppCredential:
  458. return kFIRAuthErrorMessageMissingAppCredential;
  459. case FIRAuthErrorCodeInvalidAppCredential:
  460. return kFIRAuthErrorMessageInvalidAppCredential;
  461. case FIRAuthErrorCodeQuotaExceeded:
  462. return kFIRAuthErrorMessageQuotaExceeded;
  463. case FIRAuthErrorCodeMissingAppToken:
  464. return kFIRAuthErrorMessageMissingAppToken;
  465. case FIRAuthErrorCodeNotificationNotForwarded:
  466. return kFIRAuthErrorMessageNotificationNotForwarded;
  467. case FIRAuthErrorCodeAppNotVerified:
  468. return kFIRAuthErrorMessageAppNotVerified;
  469. case FIRAuthErrorCodeCaptchaCheckFailed:
  470. return kFIRAuthErrorMessageCaptchaCheckFailed;
  471. case FIRAuthErrorCodeWebContextAlreadyPresented:
  472. return kFIRAuthErrorMessageWebContextAlreadyPresented;
  473. case FIRAuthErrorCodeWebContextCancelled:
  474. return kFIRAuthErrorMessageWebContextCancelled;
  475. case FIRAuthErrorCodeInvalidClientID:
  476. return kFIRAuthErrorMessageInvalidClientID;
  477. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  478. return kFIRAuthErrorMessageAppVerificationUserInteractionFailure;
  479. case FIRAuthErrorCodeWebNetworkRequestFailed:
  480. return kFIRAuthErrorMessageWebRequestFailed;
  481. case FIRAuthErrorCodeNullUser:
  482. return kFIRAuthErrorMessageNullUser;
  483. case FIRAuthErrorCodeInvalidDynamicLinkDomain:
  484. return kFIRAuthErrorMessageInvalidDynamicLinkDomain;
  485. case FIRAuthErrorCodeWebInternalError:
  486. return kFIRAuthErrorMessageWebInternalError;
  487. case FIRAuthErrorCodeWebSignInUserInteractionFailure:
  488. return kFIRAuthErrorMessageAppVerificationUserInteractionFailure;
  489. case FIRAuthErrorCodeMalformedJWT:
  490. return kFIRAuthErrorMessageMalformedJWT;
  491. case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
  492. return kFIRAuthErrorMessageLocalPlayerNotAuthenticated;
  493. case FIRAuthErrorCodeGameKitNotLinked:
  494. return kFIRAuthErrorMessageGameKitNotLinked;
  495. }
  496. }
  497. /** @var FIRAuthErrorCodeString
  498. @brief The the error short string, based on the error code.
  499. @remarks No default case so that we get a compiler warning if a new value was added to the enum.
  500. */
  501. static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
  502. switch (code) {
  503. case FIRAuthErrorCodeInvalidCustomToken:
  504. return @"ERROR_INVALID_CUSTOM_TOKEN";
  505. case FIRAuthErrorCodeCustomTokenMismatch:
  506. return @"ERROR_CUSTOM_TOKEN_MISMATCH";
  507. case FIRAuthErrorCodeInvalidEmail:
  508. return @"ERROR_INVALID_EMAIL";
  509. case FIRAuthErrorCodeInvalidCredential:
  510. return @"ERROR_INVALID_CREDENTIAL";
  511. case FIRAuthErrorCodeUserDisabled:
  512. return @"ERROR_USER_DISABLED";
  513. case FIRAuthErrorCodeEmailAlreadyInUse:
  514. return @"ERROR_EMAIL_ALREADY_IN_USE";
  515. case FIRAuthErrorCodeWrongPassword:
  516. return @"ERROR_WRONG_PASSWORD";
  517. case FIRAuthErrorCodeTooManyRequests:
  518. return @"ERROR_TOO_MANY_REQUESTS";
  519. case FIRAuthErrorCodeAccountExistsWithDifferentCredential:
  520. return @"ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL";
  521. case FIRAuthErrorCodeRequiresRecentLogin:
  522. return @"ERROR_REQUIRES_RECENT_LOGIN";
  523. case FIRAuthErrorCodeProviderAlreadyLinked:
  524. return @"ERROR_PROVIDER_ALREADY_LINKED";
  525. case FIRAuthErrorCodeNoSuchProvider:
  526. return @"ERROR_NO_SUCH_PROVIDER";
  527. case FIRAuthErrorCodeInvalidUserToken:
  528. return @"ERROR_INVALID_USER_TOKEN";
  529. case FIRAuthErrorCodeNetworkError:
  530. return @"ERROR_NETWORK_REQUEST_FAILED";
  531. case FIRAuthErrorCodeKeychainError:
  532. return @"ERROR_KEYCHAIN_ERROR";
  533. case FIRAuthErrorCodeUserTokenExpired:
  534. return @"ERROR_USER_TOKEN_EXPIRED";
  535. case FIRAuthErrorCodeUserNotFound:
  536. return @"ERROR_USER_NOT_FOUND";
  537. case FIRAuthErrorCodeInvalidAPIKey:
  538. return @"ERROR_INVALID_API_KEY";
  539. case FIRAuthErrorCodeCredentialAlreadyInUse:
  540. return @"ERROR_CREDENTIAL_ALREADY_IN_USE";
  541. case FIRAuthErrorCodeInternalError:
  542. return @"ERROR_INTERNAL_ERROR";
  543. case FIRAuthErrorCodeUserMismatch:
  544. return @"ERROR_USER_MISMATCH";
  545. case FIRAuthErrorCodeOperationNotAllowed:
  546. return @"ERROR_OPERATION_NOT_ALLOWED";
  547. case FIRAuthErrorCodeWeakPassword:
  548. return @"ERROR_WEAK_PASSWORD";
  549. case FIRAuthErrorCodeAppNotAuthorized:
  550. return @"ERROR_APP_NOT_AUTHORIZED";
  551. case FIRAuthErrorCodeExpiredActionCode:
  552. return @"ERROR_EXPIRED_ACTION_CODE";
  553. case FIRAuthErrorCodeInvalidActionCode:
  554. return @"ERROR_INVALID_ACTION_CODE";
  555. case FIRAuthErrorCodeInvalidMessagePayload:
  556. return @"ERROR_INVALID_MESSAGE_PAYLOAD";
  557. case FIRAuthErrorCodeInvalidSender:
  558. return @"ERROR_INVALID_SENDER";
  559. case FIRAuthErrorCodeInvalidRecipientEmail:
  560. return @"ERROR_INVALID_RECIPIENT_EMAIL";
  561. case FIRAuthErrorCodeMissingIosBundleID:
  562. return @"ERROR_MISSING_IOS_BUNDLE_ID";
  563. case FIRAuthErrorCodeMissingAndroidPackageName:
  564. return @"ERROR_MISSING_ANDROID_PKG_NAME";
  565. case FIRAuthErrorCodeUnauthorizedDomain:
  566. return @"ERROR_UNAUTHORIZED_DOMAIN";
  567. case FIRAuthErrorCodeInvalidContinueURI:
  568. return @"ERROR_INVALID_CONTINUE_URI";
  569. case FIRAuthErrorCodeMissingContinueURI:
  570. return @"ERROR_MISSING_CONTINUE_URI";
  571. case FIRAuthErrorCodeMissingEmail:
  572. return @"ERROR_MISSING_EMAIL";
  573. case FIRAuthErrorCodeMissingPhoneNumber:
  574. return @"ERROR_MISSING_PHONE_NUMBER";
  575. case FIRAuthErrorCodeInvalidPhoneNumber:
  576. return @"ERROR_INVALID_PHONE_NUMBER";
  577. case FIRAuthErrorCodeMissingVerificationCode:
  578. return @"ERROR_MISSING_VERIFICATION_CODE";
  579. case FIRAuthErrorCodeInvalidVerificationCode:
  580. return @"ERROR_INVALID_VERIFICATION_CODE";
  581. case FIRAuthErrorCodeMissingVerificationID:
  582. return @"ERROR_MISSING_VERIFICATION_ID";
  583. case FIRAuthErrorCodeInvalidVerificationID:
  584. return @"ERROR_INVALID_VERIFICATION_ID";
  585. case FIRAuthErrorCodeSessionExpired:
  586. return @"ERROR_SESSION_EXPIRED";
  587. case FIRAuthErrorCodeMissingAppCredential:
  588. return @"MISSING_APP_CREDENTIAL";
  589. case FIRAuthErrorCodeInvalidAppCredential:
  590. return @"INVALID_APP_CREDENTIAL";
  591. case FIRAuthErrorCodeQuotaExceeded:
  592. return @"ERROR_QUOTA_EXCEEDED";
  593. case FIRAuthErrorCodeMissingAppToken:
  594. return @"ERROR_MISSING_APP_TOKEN";
  595. case FIRAuthErrorCodeNotificationNotForwarded:
  596. return @"ERROR_NOTIFICATION_NOT_FORWARDED";
  597. case FIRAuthErrorCodeAppNotVerified:
  598. return @"ERROR_APP_NOT_VERIFIED";
  599. case FIRAuthErrorCodeCaptchaCheckFailed:
  600. return @"ERROR_CAPTCHA_CHECK_FAILED";
  601. case FIRAuthErrorCodeWebContextAlreadyPresented:
  602. return @"ERROR_WEB_CONTEXT_ALREADY_PRESENTED";
  603. case FIRAuthErrorCodeWebContextCancelled:
  604. return @"ERROR_WEB_CONTEXT_CANCELLED";
  605. case FIRAuthErrorCodeInvalidClientID:
  606. return @"ERROR_INVALID_CLIENT_ID";
  607. case FIRAuthErrorCodeAppVerificationUserInteractionFailure:
  608. return @"ERROR_APP_VERIFICATION_FAILED";
  609. case FIRAuthErrorCodeWebNetworkRequestFailed:
  610. return @"ERROR_WEB_NETWORK_REQUEST_FAILED";
  611. case FIRAuthErrorCodeNullUser:
  612. return @"ERROR_NULL_USER";
  613. case FIRAuthErrorCodeInvalidDynamicLinkDomain:
  614. return @"ERROR_INVALID_DYNAMIC_LINK_DOMAIN";
  615. case FIRAuthErrorCodeWebInternalError:
  616. return @"ERROR_WEB_INTERNAL_ERROR";
  617. case FIRAuthErrorCodeWebSignInUserInteractionFailure:
  618. return @"ERROR_WEB_USER_INTERACTION_FAILURE";
  619. case FIRAuthErrorCodeMalformedJWT:
  620. return @"ERROR_MALFORMED_JWT";
  621. case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
  622. return @"ERROR_LOCAL_PLAYER_NOT_AUTHENTICATED";
  623. case FIRAuthErrorCodeGameKitNotLinked:
  624. return @"ERROR_GAME_KIT_NOT_LINKED";
  625. }
  626. }
  627. @implementation FIRAuthErrorUtils
  628. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code {
  629. return [self errorWithCode:code message:nil];
  630. }
  631. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  632. message:(nullable NSString *)message {
  633. NSDictionary *userInfo = nil;
  634. if (message.length) {
  635. userInfo = @{
  636. NSLocalizedDescriptionKey : message
  637. };
  638. }
  639. return [self errorWithCode:code userInfo:userInfo];
  640. }
  641. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  642. underlyingError:(nullable NSError *)underlyingError {
  643. NSDictionary *errorUserInfo;
  644. if (underlyingError) {
  645. errorUserInfo = @{
  646. NSUnderlyingErrorKey : underlyingError
  647. };
  648. }
  649. return [self errorWithCode:code userInfo:errorUserInfo];
  650. }
  651. + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
  652. userInfo:(nullable NSDictionary *)userInfo {
  653. BOOL isPublic = (code & FIRAuthPublicErrorCodeFlag) == FIRAuthPublicErrorCodeFlag;
  654. if (isPublic) {
  655. // This is a public error. Return it as a public error and add a description.
  656. NSInteger errorCode = code & ~FIRAuthPublicErrorCodeFlag;
  657. NSMutableDictionary *errorUserInfo = [NSMutableDictionary dictionaryWithDictionary:userInfo];
  658. if (!errorUserInfo[NSLocalizedDescriptionKey]) {
  659. errorUserInfo[NSLocalizedDescriptionKey] = FIRAuthErrorDescription(errorCode);
  660. }
  661. #pragma clang diagnostic push
  662. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  663. // TODO(wangyue): Remove the deprecated code on next breaking change.
  664. errorUserInfo[FIRAuthErrorNameKey] = FIRAuthErrorCodeString(errorCode);
  665. #pragma clang diagnostic pop
  666. errorUserInfo[FIRAuthErrorUserInfoNameKey] = FIRAuthErrorCodeString(errorCode);
  667. return [NSError errorWithDomain:FIRAuthErrorDomain code:errorCode userInfo:errorUserInfo];
  668. } else {
  669. // This is an internal error. Wrap it in an internal error.
  670. NSError *error =
  671. [NSError errorWithDomain:FIRAuthInternalErrorDomain code:code userInfo:userInfo];
  672. return [self errorWithCode:FIRAuthInternalErrorCodeInternalError underlyingError:error];
  673. }
  674. }
  675. + (NSError *)RPCRequestEncodingErrorWithUnderlyingError:(NSError *)underlyingError {
  676. return [self errorWithCode:FIRAuthInternalErrorCodeRPCRequestEncodingError
  677. underlyingError:underlyingError];
  678. }
  679. + (NSError *)JSONSerializationErrorForUnencodableType {
  680. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError];
  681. }
  682. + (NSError *)JSONSerializationErrorWithUnderlyingError:(NSError *)underlyingError {
  683. return [self errorWithCode:FIRAuthInternalErrorCodeJSONSerializationError
  684. underlyingError:underlyingError];
  685. }
  686. + (NSError *)networkErrorWithUnderlyingError:(NSError *)underlyingError {
  687. return [self errorWithCode:FIRAuthInternalErrorCodeNetworkError
  688. underlyingError:underlyingError];
  689. }
  690. + (NSError *)unexpectedErrorResponseWithData:(NSData *)data
  691. underlyingError:(NSError *)underlyingError {
  692. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  693. if (data) {
  694. userInfo[FIRAuthErrorUserInfoDataKey] = data;
  695. }
  696. if (underlyingError) {
  697. userInfo[NSUnderlyingErrorKey] = underlyingError;
  698. }
  699. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse
  700. userInfo:[userInfo copy]];
  701. }
  702. + (NSError *)unexpectedErrorResponseWithDeserializedResponse:(id)deserializedResponse {
  703. NSDictionary *userInfo;
  704. if (deserializedResponse) {
  705. userInfo = @{
  706. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse,
  707. };
  708. }
  709. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedErrorResponse userInfo:userInfo];
  710. }
  711. + (NSError *)malformedJWTErrorWithToken:(NSString *)token
  712. underlyingError:(NSError *_Nullable)underlyingError {
  713. NSMutableDictionary *userInfo =
  714. [NSMutableDictionary dictionaryWithObject:kFIRAuthErrorMessageMalformedJWT
  715. forKey:NSLocalizedDescriptionKey];
  716. [userInfo setObject:token forKey:FIRAuthErrorUserInfoDataKey];
  717. if (underlyingError != nil) {
  718. [userInfo setObject:underlyingError forKey:NSUnderlyingErrorKey];
  719. }
  720. return [self errorWithCode:FIRAuthInternalErrorCodeMalformedJWT userInfo:[userInfo copy]];
  721. }
  722. + (NSError *)unexpectedResponseWithData:(NSData *)data
  723. underlyingError:(NSError *)underlyingError {
  724. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  725. if (data) {
  726. userInfo[FIRAuthErrorUserInfoDataKey] = data;
  727. }
  728. if (underlyingError) {
  729. userInfo[NSUnderlyingErrorKey] = underlyingError;
  730. }
  731. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:[userInfo copy]];
  732. }
  733. + (NSError *)unexpectedResponseWithDeserializedResponse:(id)deserializedResponse {
  734. NSDictionary *userInfo;
  735. if (deserializedResponse) {
  736. userInfo = @{
  737. FIRAuthErrorUserInfoDeserializedResponseKey : deserializedResponse,
  738. };
  739. }
  740. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:userInfo];
  741. }
  742. + (NSError *)unexpectedResponseWithDeserializedResponse:(nullable id)deserializedResponse
  743. underlyingError:(NSError *)underlyingError {
  744. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  745. if (deserializedResponse) {
  746. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  747. }
  748. if (underlyingError) {
  749. userInfo[NSUnderlyingErrorKey] = underlyingError;
  750. }
  751. return [self errorWithCode:FIRAuthInternalErrorCodeUnexpectedResponse userInfo:[userInfo copy]];
  752. }
  753. + (NSError *)RPCResponseDecodingErrorWithDeserializedResponse:(id)deserializedResponse
  754. underlyingError:(NSError *)underlyingError {
  755. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  756. if (deserializedResponse) {
  757. userInfo[FIRAuthErrorUserInfoDeserializedResponseKey] = deserializedResponse;
  758. }
  759. if (underlyingError) {
  760. userInfo[NSUnderlyingErrorKey] = underlyingError;
  761. }
  762. return [self errorWithCode:FIRAuthInternalErrorCodeRPCResponseDecodingError
  763. userInfo:[userInfo copy]];
  764. }
  765. + (NSError *)emailAlreadyInUseErrorWithEmail:(nullable NSString *)email {
  766. NSDictionary *userInfo;
  767. if (email.length) {
  768. userInfo = @{
  769. FIRAuthErrorUserInfoEmailKey : email,
  770. };
  771. }
  772. return [self errorWithCode:FIRAuthInternalErrorCodeEmailAlreadyInUse userInfo:userInfo];
  773. }
  774. + (NSError *)userDisabledErrorWithMessage:(nullable NSString *)message {
  775. return [self errorWithCode:FIRAuthInternalErrorCodeUserDisabled message:message];
  776. }
  777. + (NSError *)wrongPasswordErrorWithMessage:(nullable NSString *)message {
  778. return [self errorWithCode:FIRAuthInternalErrorCodeWrongPassword message:message];
  779. }
  780. + (NSError *)tooManyRequestsErrorWithMessage:(nullable NSString *)message {
  781. return [self errorWithCode:FIRAuthInternalErrorCodeTooManyRequests message:message];
  782. }
  783. + (NSError *)invalidCustomTokenErrorWithMessage:(nullable NSString *)message {
  784. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCustomToken message:message];
  785. }
  786. + (NSError *)customTokenMistmatchErrorWithMessage:(nullable NSString *)message {
  787. return [self errorWithCode:FIRAuthInternalErrorCodeCustomTokenMismatch message:message];
  788. }
  789. + (NSError *)invalidCredentialErrorWithMessage:(nullable NSString *)message {
  790. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidCredential message:message];
  791. }
  792. + (NSError *)requiresRecentLoginErrorWithMessage:(nullable NSString *)message {
  793. return [self errorWithCode:FIRAuthInternalErrorCodeRequiresRecentLogin message:message];
  794. }
  795. + (NSError *)invalidUserTokenErrorWithMessage:(nullable NSString *)message {
  796. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidUserToken message:message];
  797. }
  798. + (NSError *)invalidEmailErrorWithMessage:(nullable NSString *)message {
  799. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidEmail message:message];
  800. }
  801. + (NSError *)accountExistsWithDifferentCredentialErrorWithEmail:(nullable NSString *)email {
  802. NSDictionary *userInfo;
  803. if (email.length) {
  804. userInfo = @{
  805. FIRAuthErrorUserInfoEmailKey : email,
  806. };
  807. }
  808. return [self errorWithCode:FIRAuthInternalErrorCodeAccountExistsWithDifferentCredential
  809. userInfo:userInfo];
  810. }
  811. + (NSError *)providerAlreadyLinkedError {
  812. return [self errorWithCode:FIRAuthInternalErrorCodeProviderAlreadyLinked];
  813. }
  814. + (NSError *)noSuchProviderError {
  815. return [self errorWithCode:FIRAuthInternalErrorCodeNoSuchProvider];
  816. }
  817. + (NSError *)userTokenExpiredErrorWithMessage:(nullable NSString *)message {
  818. return [self errorWithCode:FIRAuthInternalErrorCodeUserTokenExpired message:message];
  819. }
  820. + (NSError *)userNotFoundErrorWithMessage:(nullable NSString *)message {
  821. return [self errorWithCode:FIRAuthInternalErrorCodeUserNotFound message:message];
  822. }
  823. + (NSError *)invalidAPIKeyError {
  824. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAPIKey];
  825. }
  826. + (NSError *)userMismatchError {
  827. return [self errorWithCode:FIRAuthInternalErrorCodeUserMismatch];
  828. }
  829. + (NSError *)credentialAlreadyInUseErrorWithMessage:(nullable NSString *)message
  830. credential:(nullable FIRAuthCredential *)credential
  831. email:(nullable NSString *)email {
  832. NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
  833. if (credential) {
  834. #pragma clang diagnostic push
  835. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  836. // TODO(wangyue): Remove the deprecated code on next breaking change.
  837. userInfo[FIRAuthUpdatedCredentialKey] = credential;
  838. #pragma clang diagnostic pop
  839. userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey] = credential;
  840. }
  841. if (email.length) {
  842. userInfo[FIRAuthErrorUserInfoEmailKey] = email;
  843. }
  844. if (userInfo.count) {
  845. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse
  846. userInfo:userInfo];
  847. }
  848. return [self errorWithCode:FIRAuthInternalErrorCodeCredentialAlreadyInUse message:message];
  849. }
  850. + (NSError *)operationNotAllowedErrorWithMessage:(nullable NSString *)message {
  851. return [self errorWithCode:FIRAuthInternalErrorCodeOperationNotAllowed message:message];
  852. }
  853. + (NSError *)weakPasswordErrorWithServerResponseReason:(nullable NSString *)reason {
  854. NSDictionary *userInfo;
  855. if (reason.length) {
  856. userInfo = @{
  857. NSLocalizedFailureReasonErrorKey : reason,
  858. };
  859. }
  860. return [self errorWithCode:FIRAuthInternalErrorCodeWeakPassword userInfo:userInfo];
  861. }
  862. + (NSError *)appNotAuthorizedError {
  863. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotAuthorized];
  864. }
  865. + (NSError *)expiredActionCodeErrorWithMessage:(nullable NSString *)message {
  866. return [self errorWithCode:FIRAuthInternalErrorCodeExpiredActionCode message:message];
  867. }
  868. + (NSError *)invalidActionCodeErrorWithMessage:(nullable NSString *)message {
  869. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidActionCode message:message];
  870. }
  871. + (NSError *)invalidMessagePayloadErrorWithMessage:(nullable NSString *)message {
  872. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidMessagePayload message:message];
  873. }
  874. + (NSError *)invalidSenderErrorWithMessage:(nullable NSString *)message {
  875. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidSender message:message];
  876. }
  877. + (NSError *)invalidRecipientEmailErrorWithMessage:(nullable NSString *)message {
  878. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidRecipientEmail message:message];
  879. }
  880. + (NSError *)missingIosBundleIDErrorWithMessage:(nullable NSString *)message {
  881. return [self errorWithCode:FIRAuthinternalErrorCodeMissingIosBundleID message:message];
  882. }
  883. + (NSError *)missingAndroidPackageNameErrorWithMessage:(nullable NSString *)message {
  884. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAndroidPackageName message:message];
  885. }
  886. + (NSError *)unauthorizedDomainErrorWithMessage:(nullable NSString *)message {
  887. return [self errorWithCode:FIRAuthInternalErrorCodeUnauthorizedDomain message:message];
  888. }
  889. + (NSError *)invalidContinueURIErrorWithMessage:(nullable NSString *)message {
  890. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidContinueURI message:message];
  891. }
  892. + (NSError *)missingContinueURIErrorWithMessage:(nullable NSString *)message {
  893. return[self errorWithCode:FIRAuthInternalErrorCodeMissingContinueURI message:message];
  894. }
  895. + (NSError *)missingEmailErrorWithMessage:(nullable NSString *)message {
  896. return [self errorWithCode:FIRAuthInternalErrorCodeMissingEmail message:message];
  897. }
  898. + (NSError *)missingPhoneNumberErrorWithMessage:(nullable NSString *)message {
  899. return [self errorWithCode:FIRAuthInternalErrorCodeMissingPhoneNumber message:message];
  900. }
  901. + (NSError *)invalidPhoneNumberErrorWithMessage:(nullable NSString *)message {
  902. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidPhoneNumber message:message];
  903. }
  904. + (NSError *)missingVerificationCodeErrorWithMessage:(nullable NSString *)message {
  905. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationCode message:message];
  906. }
  907. + (NSError *)invalidVerificationCodeErrorWithMessage:(nullable NSString *)message {
  908. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationCode message:message];
  909. }
  910. + (NSError *)missingVerificationIDErrorWithMessage:(nullable NSString *)message {
  911. return [self errorWithCode:FIRAuthInternalErrorCodeMissingVerificationID message:message];
  912. }
  913. + (NSError *)invalidVerificationIDErrorWithMessage:(nullable NSString *)message {
  914. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidVerificationID message:message];
  915. }
  916. + (NSError *)sessionExpiredErrorWithMessage:(nullable NSString *)message {
  917. return [self errorWithCode:FIRAuthInternalErrorCodeSessionExpired message:message];
  918. }
  919. + (NSError *)missingAppCredentialWithMessage:(nullable NSString *)message {
  920. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppCredential message:message];
  921. }
  922. + (NSError *)invalidAppCredentialWithMessage:(nullable NSString *)message {
  923. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidAppCredential message:message];
  924. }
  925. + (NSError *)quotaExceededErrorWithMessage:(nullable NSString *)message {
  926. return [self errorWithCode:FIRAuthInternalErrorCodeQuotaExceeded message:message];
  927. }
  928. + (NSError *)missingAppTokenErrorWithUnderlyingError:(nullable NSError *)underlyingError {
  929. return [self errorWithCode:FIRAuthInternalErrorCodeMissingAppToken
  930. underlyingError:underlyingError];
  931. }
  932. + (NSError *)localPlayerNotAuthenticatedError {
  933. return [self errorWithCode:FIRAuthInternalErrorCodeLocalPlayerNotAuthenticated];
  934. }
  935. + (NSError *)gameKitNotLinkedError {
  936. return [self errorWithCode:FIRAuthInternalErrorCodeGameKitNotLinked];
  937. }
  938. + (NSError *)notificationNotForwardedError {
  939. return [self errorWithCode:FIRAuthInternalErrorCodeNotificationNotForwarded];
  940. }
  941. + (NSError *)appNotVerifiedErrorWithMessage:(nullable NSString *)message {
  942. return [self errorWithCode:FIRAuthInternalErrorCodeAppNotVerified message:message];
  943. }
  944. + (NSError *)captchaCheckFailedErrorWithMessage:(nullable NSString *)message {
  945. return [self errorWithCode:FIRAuthInternalErrorCodeCaptchaCheckFailed message:message];
  946. }
  947. + (NSError *)webContextAlreadyPresentedErrorWithMessage:(nullable NSString *)message {
  948. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextAlreadyPresented message:message];
  949. }
  950. + (NSError *)webContextCancelledErrorWithMessage:(nullable NSString *)message {
  951. return [self errorWithCode:FIRAuthInternalErrorCodeWebContextCancelled message:message];
  952. }
  953. + (NSError *)appVerificationUserInteractionFailureWithReason:(NSString *)reason {
  954. NSDictionary *userInfo;
  955. if (reason.length) {
  956. userInfo = @{
  957. NSLocalizedFailureReasonErrorKey : reason,
  958. };
  959. }
  960. return [self errorWithCode:FIRAuthInternalErrorCodeAppVerificationUserInteractionFailure
  961. userInfo:userInfo];
  962. }
  963. + (NSError *)webSignInUserInteractionFailureWithReason:(nullable NSString *)reason {
  964. NSDictionary *userInfo;
  965. if (reason.length) {
  966. userInfo = @{
  967. NSLocalizedFailureReasonErrorKey : reason,
  968. };
  969. }
  970. return [self errorWithCode:FIRAuthInternalErrorCodeWebSignInUserInteractionFailure
  971. userInfo:userInfo];
  972. }
  973. + (nullable NSError *)URLResponseErrorWithCode:(NSString *)code message:(nullable NSString *)message {
  974. if ([code isEqualToString:kURLResponseErrorCodeInvalidClientID]) {
  975. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidClientID message:message];
  976. }
  977. if ([code isEqualToString:kURLResponseErrorCodeNetworkRequestFailed]) {
  978. return [self errorWithCode:FIRAuthInternalErrorCodeWebNetworkRequestFailed message:message];
  979. }
  980. if ([code isEqualToString:kURLResponseErrorCodeInternalError]) {
  981. return [self errorWithCode:FIRAuthInternalErrorCodeWebInternalError message:message];
  982. }
  983. return nil;
  984. }
  985. + (NSError *)nullUserErrorWithMessage:(nullable NSString *)message {
  986. return [self errorWithCode:FIRAuthInternalErrorCodeNullUser message:message];
  987. }
  988. + (NSError *)invalidDynamicLinkDomainErrorWithMessage:(nullable NSString *)message {
  989. return [self errorWithCode:FIRAuthInternalErrorCodeInvalidDynamicLinkDomain message:message];
  990. }
  991. + (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status {
  992. NSString *failureReason = [NSString stringWithFormat:@"%@ (%li)", keychainFunction, (long)status];
  993. return [self errorWithCode:FIRAuthInternalErrorCodeKeychainError userInfo:@{
  994. NSLocalizedFailureReasonErrorKey : failureReason,
  995. }];
  996. }
  997. @end
  998. NS_ASSUME_NONNULL_END