You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

440 lines
19 KiB

6 years ago
  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 <Foundation/Foundation.h>
  17. #import "FIRAuthErrors.h"
  18. /** @var FIRAuthPublicErrorCodeFlag
  19. @brief Bitmask value indicating the error represents a public error code when this bit is
  20. zeroed. Error codes which don't contain this flag will be wrapped in an @c NSError whose
  21. code is @c FIRAuthErrorCodeInternalError.
  22. */
  23. static const NSInteger FIRAuthPublicErrorCodeFlag = 1 << 20;
  24. /** @var FIRAuthInternalErrorDomain
  25. @brief The Firebase Auth error domain for internal errors.
  26. */
  27. extern NSString *const FIRAuthInternalErrorDomain;
  28. /** @var FIRAuthErrorUserInfoDeserializedResponseKey
  29. @brief Errors with the code @c FIRAuthErrorCodeUnexpectedResponseError,
  30. @c FIRAuthErrorCodeUnexpectedErrorResponseError, and
  31. @c FIRAuthInternalErrorCodeRPCResponseDecodingError may contain an @c NSError.userInfo
  32. dictionary which contains this key. The value associated with this key is an object of
  33. unspecified contents containing the deserialized server response.
  34. */
  35. extern NSString *const FIRAuthErrorUserInfoDeserializedResponseKey;
  36. /** @var FIRAuthErrorUserInfoDataKey
  37. @brief Errors with the code @c FIRAuthErrorCodeUnexpectedResponseError or
  38. @c FIRAuthErrorCodeUnexpectedErrorResponseError may contain an @c NSError.userInfo
  39. dictionary which contains this key. The value associated with this key is an @c NSString
  40. which represents the response from a server to an RPC which could not be deserialized.
  41. */
  42. extern NSString *const FIRAuthErrorUserInfoDataKey;
  43. /** @var FIRAuthInternalErrorCode
  44. @brief Error codes used internally by Firebase Auth.
  45. @remarks All errors are generated using an internal error code. These errors are automatically
  46. converted to the appropriate public version of the @c NSError by the methods in
  47. @c FIRAuthErrorUtils
  48. */
  49. typedef NS_ENUM(NSInteger, FIRAuthInternalErrorCode) {
  50. /** @var FIRAuthInternalErrorCodeNetworkError
  51. @brief Indicates a network error occurred (such as a timeout, interrupted connection, or
  52. unreachable host.)
  53. @remarks These types of errors are often recoverable with a retry.
  54. See the @c NSUnderlyingError value in the @c NSError.userInfo dictionary for details about
  55. the network error which occurred.
  56. */
  57. FIRAuthInternalErrorCodeNetworkError = FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeNetworkError,
  58. /** @var FIRAuthInternalErrorCodeEmailAlreadyInUse
  59. @brief The email used to attempt a sign-up already exists.
  60. */
  61. FIRAuthInternalErrorCodeEmailAlreadyInUse =
  62. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeEmailAlreadyInUse,
  63. /** @var FIRAuthInternalErrorCodeUserDisabled
  64. @brief Indicates the user's account is disabled on the server side.
  65. */
  66. FIRAuthInternalErrorCodeUserDisabled = FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeUserDisabled,
  67. /** @var FIRAuthInternalErrorCodeWrongPassword
  68. @brief Indicates the user attempted sign in with a wrong password
  69. */
  70. FIRAuthInternalErrorCodeWrongPassword =
  71. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeWrongPassword,
  72. /** @var FIRAuthInternalErrorCodeKeychainError
  73. @brief Indicates an error occurred accessing the keychain.
  74. @remarks The @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo dictionary
  75. will contain more information about the error encountered.
  76. */
  77. FIRAuthInternalErrorCodeKeychainError =
  78. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeKeychainError,
  79. /** @var FIRAuthInternalErrorCodeInternalError
  80. @brief An internal error occurred.
  81. @remarks This value is here for consistency. It's also used to make the implementation of
  82. wrapping internal errors simpler.
  83. */
  84. FIRAuthInternalErrorCodeInternalError =
  85. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInternalError,
  86. /** @var FIRAuthInternalErrorCodeTooManyRequests
  87. @brief Indicates that too many requests were made to a server method.
  88. */
  89. FIRAuthInternalErrorCodeTooManyRequests =
  90. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeTooManyRequests,
  91. /** @var FIRAuthInternalErrorCodeInvalidCustomToken
  92. @brief Indicates a validation error with the custom token.
  93. */
  94. FIRAuthInternalErrorCodeInvalidCustomToken =
  95. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidCustomToken,
  96. /** @var FIRAuthInternalErrorCodeCredentialMismatch
  97. @brief Indicates the service account and the API key belong to different projects.
  98. */
  99. FIRAuthInternalErrorCodeCustomTokenMismatch =
  100. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeCustomTokenMismatch,
  101. /** @var FIRAuthInternalErrorCodeInvalidCredential
  102. @brief Indicates the IDP token or requestUri is invalid.
  103. */
  104. FIRAuthInternalErrorCodeInvalidCredential =
  105. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidCredential,
  106. /** @var FIRAuthInternalErrorCodeRequiresRecentLogin
  107. @brief Indicates the user has attemped to change email or password more than 5 minutes after
  108. signing in.
  109. */
  110. FIRAuthInternalErrorCodeRequiresRecentLogin =
  111. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeRequiresRecentLogin,
  112. /** @var FIRAuthInternalErrorCodeInvalidUserToken
  113. @brief Indicates user's saved auth credential is invalid, the user needs to sign in again.
  114. */
  115. FIRAuthInternalErrorCodeInvalidUserToken =
  116. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidUserToken,
  117. /** @var FIRAuthInternalErrorCodeInvalidEmail
  118. @brief Indicates the email identifier is invalid.
  119. */
  120. FIRAuthInternalErrorCodeInvalidEmail =
  121. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidEmail,
  122. /** @var FIRAuthInternalErrorCodeAccountExistsWithDifferentCredential
  123. @brief Indicates account linking is needed.
  124. */
  125. FIRAuthInternalErrorCodeAccountExistsWithDifferentCredential =
  126. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeAccountExistsWithDifferentCredential,
  127. /** @var FIRAuthInternalErrorCodeProviderAlreadyLinked
  128. @brief Indicates an attempt to link a provider to which we are already linked.
  129. */
  130. FIRAuthInternalErrorCodeProviderAlreadyLinked =
  131. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeProviderAlreadyLinked,
  132. /** @var FIRAuthInternalErrorCodeNoSuchProvider
  133. @brief Indicates an attempt to unlink a provider that is not is not linked.
  134. */
  135. FIRAuthInternalErrorCodeNoSuchProvider =
  136. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeNoSuchProvider,
  137. /** @var FIRAuthInternalErrorCodeUserTokenExpired
  138. @brief Indicates the token issue time is older than account's valid_since time.
  139. */
  140. FIRAuthInternalErrorCodeUserTokenExpired =
  141. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeUserTokenExpired,
  142. /** @var FIRAuthInternalErrorCodeUserNotFound
  143. @brief Indicates the user account was been found.
  144. */
  145. FIRAuthInternalErrorCodeUserNotFound =
  146. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeUserNotFound,
  147. /** @var FIRAuthInternalErrorCodeInvalidAPIKey
  148. @brief Indicates an invalid API Key was supplied in the request.
  149. */
  150. FIRAuthInternalErrorCodeInvalidAPIKey =
  151. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidAPIKey,
  152. /** @var FIRAuthInternalErrorCodeOperationNotAllowed
  153. @brief Indicates that admin disabled sign-in with the specified IDP.
  154. */
  155. FIRAuthInternalErrorCodeOperationNotAllowed =
  156. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeOperationNotAllowed,
  157. /** @var FIRAuthInternalErrorCodeUserMismatch
  158. @brief Indicates that user attempted to reauthenticate with a user other than the current
  159. user.
  160. */
  161. FIRAuthInternalErrorCodeUserMismatch =
  162. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeUserMismatch,
  163. /** @var FIRAuthInternalErrorCodeCredentialAlreadyInUse
  164. @brief Indicates an attempt to link with a credential that has already been linked with a
  165. different Firebase account.
  166. */
  167. FIRAuthInternalErrorCodeCredentialAlreadyInUse =
  168. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeCredentialAlreadyInUse,
  169. /** @var FIRAuthInternalErrorCodeWeakPassword
  170. @brief Indicates an attempt to set a password that is considered too weak.
  171. */
  172. FIRAuthInternalErrorCodeWeakPassword =
  173. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeWeakPassword,
  174. /** @var FIRAuthInternalErrorCodeAppNotAuthorized
  175. @brief Indicates the App is not authorized to use Firebase Authentication with the
  176. provided API Key.
  177. */
  178. FIRAuthInternalErrorCodeAppNotAuthorized =
  179. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeAppNotAuthorized,
  180. /** @var FIRAuthInternalErrorCodeExpiredActionCode
  181. @brief Indicates the OOB code is expired.
  182. */
  183. FIRAuthInternalErrorCodeExpiredActionCode =
  184. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeExpiredActionCode,
  185. /** @var FIRAuthInternalErrorCodeInvalidActionCode
  186. @brief Indicates the OOB code is invalid.
  187. */
  188. FIRAuthInternalErrorCodeInvalidActionCode =
  189. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidActionCode,
  190. /** Indicates that there are invalid parameters in the payload during a "send password reset email
  191. * " attempt.
  192. */
  193. FIRAuthInternalErrorCodeInvalidMessagePayload =
  194. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidMessagePayload,
  195. /** Indicates that the sender email is invalid during a "send password reset email" attempt.
  196. */
  197. FIRAuthInternalErrorCodeInvalidSender =
  198. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidSender,
  199. /** Indicates that the recipient email is invalid.
  200. */
  201. FIRAuthInternalErrorCodeInvalidRecipientEmail =
  202. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidRecipientEmail,
  203. /** Indicates that the iOS bundle ID is missing when a iOS App Store ID is provided.
  204. */
  205. FIRAuthinternalErrorCodeMissingIosBundleID =
  206. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingIosBundleID,
  207. /** Indicates that the android package name is missing when the @c androidInstallApp flag is set
  208. to true.
  209. */
  210. FIRAuthInternalErrorCodeMissingAndroidPackageName =
  211. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingAndroidPackageName,
  212. /** Indicates that the domain specified in the continue URL is not whitelisted in the Firebase
  213. console.
  214. */
  215. FIRAuthInternalErrorCodeUnauthorizedDomain =
  216. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeUnauthorizedDomain,
  217. /** Indicates that the domain specified in the continue URI is not valid.
  218. */
  219. FIRAuthInternalErrorCodeInvalidContinueURI =
  220. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidContinueURI,
  221. /** Indicates that a continue URI was not provided in a request to the backend which requires
  222. one.
  223. */
  224. FIRAuthInternalErrorCodeMissingContinueURI =
  225. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingContinueURI,
  226. /** Indicates that an email address was expected but one was not provided.
  227. */
  228. FIRAuthInternalErrorCodeMissingEmail =
  229. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingEmail,
  230. /** Indicates that a phone number was not provided in a call to @c verifyPhoneNumber:completion:.
  231. */
  232. FIRAuthInternalErrorCodeMissingPhoneNumber =
  233. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingPhoneNumber,
  234. /** Indicates that an invalid phone number was provided in a call to @c
  235. verifyPhoneNumber:completion:.
  236. */
  237. FIRAuthInternalErrorCodeInvalidPhoneNumber =
  238. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidPhoneNumber,
  239. /** Indicates that the phone auth credential was created with an empty verification code.
  240. */
  241. FIRAuthInternalErrorCodeMissingVerificationCode =
  242. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingVerificationCode,
  243. /** Indicates that an invalid verification code was used in the verifyPhoneNumber request.
  244. */
  245. FIRAuthInternalErrorCodeInvalidVerificationCode =
  246. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidVerificationCode,
  247. /** Indicates that the phone auth credential was created with an empty verification ID.
  248. */
  249. FIRAuthInternalErrorCodeMissingVerificationID =
  250. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingVerificationID,
  251. /** Indicates that the APNS device token is missing in the verifyClient request.
  252. */
  253. FIRAuthInternalErrorCodeMissingAppCredential =
  254. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingAppCredential,
  255. /** Indicates that an invalid APNS device token was used in the verifyClient request.
  256. */
  257. FIRAuthInternalErrorCodeInvalidAppCredential =
  258. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidAppCredential,
  259. /** Indicates that the reCAPTCHA token is not valid.
  260. */
  261. FIRAuthInternalErrorCodeCaptchaCheckFailed =
  262. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeCaptchaCheckFailed,
  263. /** Indicates that an invalid verification ID was used in the verifyPhoneNumber request.
  264. */
  265. FIRAuthInternalErrorCodeInvalidVerificationID =
  266. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidVerificationID,
  267. /** Indicates that the quota of SMS messages for a given project has been exceeded.
  268. */
  269. FIRAuthInternalErrorCodeQuotaExceeded =
  270. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeQuotaExceeded,
  271. /** Indicates that an attempt was made to present a new web context while one was already being
  272. presented.
  273. */
  274. FIRAuthInternalErrorCodeWebContextAlreadyPresented =
  275. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeWebContextAlreadyPresented,
  276. /** Indicates that the URL presentation was cancelled prematurely by the user.
  277. */
  278. FIRAuthInternalErrorCodeWebContextCancelled =
  279. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeWebContextCancelled,
  280. /** Indicates a general failure during the app verification flow.
  281. */
  282. FIRAuthInternalErrorCodeAppVerificationUserInteractionFailure =
  283. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeAppVerificationUserInteractionFailure,
  284. /** Indicates that the clientID used to invoke a web flow is invalid.
  285. */
  286. FIRAuthInternalErrorCodeInvalidClientID =
  287. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidClientID,
  288. /** Indicates that a network request within a SFSafariViewController or UIWebview failed.
  289. */
  290. FIRAuthInternalErrorCodeWebNetworkRequestFailed =
  291. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeWebNetworkRequestFailed,
  292. /** Indicates that an internal error occured within a SFSafariViewController or UIWebview.
  293. */
  294. FIRAuthInternalErrorCodeWebInternalError =
  295. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeWebInternalError,
  296. // The enum values between 17046 and 17051 are reserved and should NOT be used for new error
  297. // codes.
  298. /** Indicates that the SMS code has expired
  299. */
  300. FIRAuthInternalErrorCodeSessionExpired =
  301. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeSessionExpired,
  302. FIRAuthInternalErrorCodeMissingAppToken =
  303. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMissingAppToken,
  304. FIRAuthInternalErrorCodeNotificationNotForwarded =
  305. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeNotificationNotForwarded,
  306. FIRAuthInternalErrorCodeAppNotVerified =
  307. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeAppNotVerified,
  308. /** Indicates that a non-null user was expected as an argmument to the operation but a null
  309. user was provided.
  310. */
  311. FIRAuthInternalErrorCodeNullUser =
  312. FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeNullUser,
  313. /** @var FIRAuthInternalErrorCodeRPCRequestEncodingError
  314. @brief Indicates an error encoding the RPC request.
  315. @remarks This is typically due to some sort of unexpected input value.
  316. See the @c NSUnderlyingError value in the @c NSError.userInfo dictionary for details.
  317. */
  318. FIRAuthInternalErrorCodeRPCRequestEncodingError = 1,
  319. /** @var FIRAuthInternalErrorCodeJSONSerializationError
  320. @brief Indicates an error serializing an RPC request.
  321. @remarks This is typically due to some sort of unexpected input value.
  322. If an @c NSJSONSerialization.isValidJSONObject: check fails, the error will contain no
  323. @c NSUnderlyingError key in the @c NSError.userInfo dictionary. If an error was
  324. encountered calling @c NSJSONSerialization.dataWithJSONObject:options:error:, the
  325. resulting error will be associated with the @c NSUnderlyingError key in the
  326. @c NSError.userInfo dictionary.
  327. */
  328. FIRAuthInternalErrorCodeJSONSerializationError = 2,
  329. /** @var FIRAuthInternalErrorCodeUnexpectedErrorResponse
  330. @brief Indicates an HTTP error occurred and the data returned either couldn't be deserialized
  331. or couldn't be decoded.
  332. @remarks See the @c NSUnderlyingError value in the @c NSError.userInfo dictionary for details
  333. about the HTTP error which occurred.
  334. If the response could be deserialized as JSON then the @c NSError.userInfo dictionary will
  335. contain a value for the key @c FIRAuthErrorUserInfoDeserializedResponseKey which is the
  336. deserialized response value.
  337. If the response could not be deserialized as JSON then the @c NSError.userInfo dictionary
  338. will contain values for the @c NSUnderlyingErrorKey and @c FIRAuthErrorUserInfoDataKey
  339. keys.
  340. */
  341. FIRAuthInternalErrorCodeUnexpectedErrorResponse = 3,
  342. /** @var FIRAuthInternalErrorCodeUnexpectedResponse
  343. @brief Indicates the HTTP response indicated the request was a successes, but the response
  344. contains something other than a JSON-encoded dictionary, or the data type of the response
  345. indicated it is different from the type of response we expected.
  346. @remarks See the @c NSUnderlyingError value in the @c NSError.userInfo dictionary.
  347. If this key is present in the dictionary, it may contain an error from
  348. @c NSJSONSerialization error (indicating the response received was of the wrong data
  349. type).
  350. See the @c FIRAuthErrorUserInfoDeserializedResponseKey value in the @c NSError.userInfo
  351. dictionary. If the response could be deserialized, it's deserialized representation will
  352. be associated with this key. If the @c NSUnderlyingError value in the @c NSError.userInfo
  353. dictionary is @c nil, this indicates the JSON didn't represent a dictionary.
  354. */
  355. FIRAuthInternalErrorCodeUnexpectedResponse = 4,
  356. /** @var FIRAuthInternalErrorCodeRPCResponseDecodingError
  357. @brief Indicates an error decoding the RPC response.
  358. This is typically due to some sort of unexpected response value from the server.
  359. @remarks See the @c NSUnderlyingError value in the @c NSError.userInfo dictionary for details.
  360. See the @c FIRErrorUserInfoDecodedResponseKey value in the @c NSError.userInfo dictionary.
  361. The deserialized representation of the response will be associated with this key.
  362. */
  363. FIRAuthInternalErrorCodeRPCResponseDecodingError = 5,
  364. };