AuthErrors.swift 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. /// Error Codes common to all API Methods:
  16. @objc(FIRAuthErrors) open class AuthErrors: NSObject {
  17. /// The Firebase Auth error domain.
  18. @objc public static let domain: String = "FIRAuthErrorDomain"
  19. /// The name of the key for the error short string of an error code.
  20. @objc public static let userInfoNameKey: String = "FIRAuthErrorUserInfoNameKey"
  21. /// Error codes for Email operations
  22. ///
  23. /// Errors with one of the following three codes:
  24. /// * `accountExistsWithDifferentCredential`
  25. /// * `credentialAlreadyInUse`
  26. /// * emailAlreadyInUse`
  27. ///
  28. /// may contain an `NSError.userInfo` dictionary object which contains this key. The value
  29. /// associated with this key is an NSString of the email address of the account that already
  30. /// exists.
  31. @objc public static let userInfoEmailKey: String = "FIRAuthErrorUserInfoEmailKey"
  32. /// The key used to read the updated Auth credential from the userInfo dictionary of the
  33. /// NSError object returned. This is the updated auth credential the developer should use for
  34. /// recovery if applicable.
  35. @objc public static let userInfoUpdatedCredentialKey: String =
  36. "FIRAuthErrorUserInfoUpdatedCredentialKey"
  37. /// The key used to read the MFA resolver from the userInfo dictionary of the NSError object
  38. /// returned when 2FA is required for sign-incompletion.
  39. @objc(FIRAuthErrorUserInfoMultiFactorResolverKey)
  40. public static let userInfoMultiFactorResolverKey: String =
  41. "FIRAuthErrorUserInfoMultiFactorResolverKey"
  42. }
  43. /// Error codes used by Firebase Auth.
  44. @objc(FIRAuthErrorCode) public enum AuthErrorCode: Int, Error {
  45. /// Indicates a validation error with the custom token.
  46. case invalidCustomToken = 17000
  47. /// Indicates the service account and the API key belong to different projects.
  48. case customTokenMismatch = 17002
  49. /// Indicates the IDP token or requestUri is invalid.
  50. case invalidCredential = 17004
  51. /// Indicates the user's account is disabled on the server.
  52. case userDisabled = 17005
  53. /// Indicates the administrator disabled sign in with the specified identity provider.
  54. case operationNotAllowed = 17006
  55. /// Indicates the email used to attempt a sign up is already in use.
  56. case emailAlreadyInUse = 17007
  57. /// Indicates the email is invalid.
  58. case invalidEmail = 17008
  59. /// Indicates the user attempted sign in with a wrong password.
  60. case wrongPassword = 17009
  61. /// Indicates that too many requests were made to a server method.
  62. case tooManyRequests = 17010
  63. /// Indicates the user account was not found.
  64. case userNotFound = 17011
  65. /// Indicates account linking is required.
  66. case accountExistsWithDifferentCredential = 17012
  67. /// Indicates the user has attempted to change email or password more than 5 minutes after
  68. /// signing in.
  69. case requiresRecentLogin = 17014
  70. /// Indicates an attempt to link a provider to which the account is already linked.
  71. case providerAlreadyLinked = 17015
  72. /// Indicates an attempt to unlink a provider that is not linked.
  73. case noSuchProvider = 17016
  74. /// Indicates user's saved auth credential is invalid the user needs to sign in again.
  75. case invalidUserToken = 17017
  76. /// Indicates a network error occurred (such as a timeout interrupted connection or
  77. /// unreachable host). These types of errors are often recoverable with a retry. The
  78. /// `NSUnderlyingError` field in the `NSError.userInfo` dictionary will contain the error
  79. /// encountered.
  80. case networkError = 17020
  81. /// Indicates the saved token has expired for example the user may have changed account
  82. /// password on another device. The user needs to sign in again on the device that made this
  83. /// request.
  84. case userTokenExpired = 17021
  85. /// Indicates an invalid API key was supplied in the request.
  86. case invalidAPIKey = 17023
  87. /// Indicates that an attempt was made to reauthenticate with a user which is not the current
  88. /// user.
  89. case userMismatch = 17024
  90. /// Indicates an attempt to link with a credential that has already been linked with a
  91. /// different Firebase account.
  92. case credentialAlreadyInUse = 17025
  93. /// Indicates an attempt to set a password that is considered too weak.
  94. case weakPassword = 17026
  95. /// Indicates the App is not authorized to use Firebase Authentication with the
  96. /// provided API Key.
  97. case appNotAuthorized = 17028
  98. /// Indicates the OOB code is expired.
  99. case expiredActionCode = 17029
  100. /// Indicates the OOB code is invalid.
  101. case invalidActionCode = 17030
  102. /// Indicates that there are invalid parameters in the payload during a
  103. /// "send password reset email" attempt.
  104. case invalidMessagePayload = 17031
  105. /// Indicates that the sender email is invalid during a "send password reset email" attempt.
  106. case invalidSender = 17032
  107. /// Indicates that the recipient email is invalid.
  108. case invalidRecipientEmail = 17033
  109. /// Indicates that an email address was expected but one was not provided.
  110. case missingEmail = 17034
  111. // The enum values 17035 is reserved and should NOT be used for new error codes.
  112. /// Indicates that the iOS bundle ID is missing when a iOS App Store ID is provided.
  113. case missingIosBundleID = 17036
  114. /// Indicates that the android package name is missing when the `androidInstallApp` flag is set
  115. /// to `true`.
  116. case missingAndroidPackageName = 17037
  117. /// Indicates that the domain specified in the continue URL is not allowlisted in the Firebase
  118. /// console.
  119. case unauthorizedDomain = 17038
  120. /// Indicates that the domain specified in the continue URI is not valid.
  121. case invalidContinueURI = 17039
  122. /// Indicates that a continue URI was not provided in a request to the backend which requires one.
  123. case missingContinueURI = 17040
  124. /// Indicates that a phone number was not provided in a call to
  125. /// `verifyPhoneNumber:completion:`.
  126. case missingPhoneNumber = 17041
  127. /// Indicates that an invalid phone number was provided in a call to
  128. /// `verifyPhoneNumber:completion:`.
  129. case invalidPhoneNumber = 17042
  130. /// Indicates that the phone auth credential was created with an empty verification code.
  131. case missingVerificationCode = 17043
  132. /// Indicates that an invalid verification code was used in the verifyPhoneNumber request.
  133. case invalidVerificationCode = 17044
  134. /// Indicates that the phone auth credential was created with an empty verification ID.
  135. case missingVerificationID = 17045
  136. /// Indicates that an invalid verification ID was used in the verifyPhoneNumber request.
  137. case invalidVerificationID = 17046
  138. /// Indicates that the APNS device token is missing in the verifyClient request.
  139. case missingAppCredential = 17047
  140. /// Indicates that an invalid APNS device token was used in the verifyClient request.
  141. case invalidAppCredential = 17048
  142. // The enum values between 17048 and 17051 are reserved and should NOT be used for new error
  143. // codes.
  144. /// Indicates that the SMS code has expired.
  145. case sessionExpired = 17051
  146. /// Indicates that the quota of SMS messages for a given project has been exceeded.
  147. case quotaExceeded = 17052
  148. /// Indicates that the APNs device token could not be obtained. The app may not have set up
  149. /// remote notification correctly or may fail to forward the APNs device token to Auth
  150. /// if app delegate swizzling is disabled.
  151. case missingAppToken = 17053
  152. /// Indicates that the app fails to forward remote notification to FIRAuth.
  153. case notificationNotForwarded = 17054
  154. /// Indicates that the app could not be verified by Firebase during phone number authentication.
  155. case appNotVerified = 17055
  156. /// Indicates that the reCAPTCHA token is not valid.
  157. case captchaCheckFailed = 17056
  158. /// Indicates that an attempt was made to present a new web context while one was already being
  159. /// presented.
  160. case webContextAlreadyPresented = 17057
  161. /// Indicates that the URL presentation was cancelled prematurely by the user.
  162. case webContextCancelled = 17058
  163. /// Indicates a general failure during the app verification flow.
  164. case appVerificationUserInteractionFailure = 17059
  165. /// Indicates that the clientID used to invoke a web flow is invalid.
  166. case invalidClientID = 17060
  167. /// Indicates that a network request within a SFSafariViewController or WKWebView failed.
  168. case webNetworkRequestFailed = 17061
  169. /// Indicates that an internal error occurred within a SFSafariViewController or WKWebView.
  170. case webInternalError = 17062
  171. /// Indicates a general failure during a web sign-in flow.
  172. case webSignInUserInteractionFailure = 17063
  173. /// Indicates that the local player was not authenticated prior to attempting Game Center signin.
  174. case localPlayerNotAuthenticated = 17066
  175. /// Indicates that a non-null user was expected as an argument to the operation but a null
  176. /// user was provided.
  177. case nullUser = 17067
  178. /// Represents the error code for when the given provider id for a web operation is invalid.
  179. case invalidProviderID = 17071
  180. /// Represents the error code for when an attempt is made to update the current user with a
  181. /// tenantId that differs from the current FirebaseAuth instance's tenantId.
  182. case tenantIDMismatch = 17072
  183. /// Represents the error code for when a request is made to the backend with an associated tenant
  184. /// ID for an operation that does not support multi-tenancy.
  185. case unsupportedTenantOperation = 17073
  186. /// Indicates that the provided Firebase Hosting Link domain is not owned by the current project.
  187. case invalidHostingLinkDomain = 17214
  188. /// Indicates that the credential is rejected because it's malformed or mismatching.
  189. case rejectedCredential = 17075
  190. /// Indicates that the GameKit framework is not linked prior to attempting Game Center signin.
  191. case gameKitNotLinked = 17076
  192. /// Indicates that the second factor is required for signin.
  193. case secondFactorRequired = 17078
  194. /// Indicates that the multi factor session is missing.
  195. case missingMultiFactorSession = 17081
  196. /// Indicates that the multi factor info is missing.
  197. case missingMultiFactorInfo = 17082
  198. /// Indicates that the multi factor session is invalid.
  199. case invalidMultiFactorSession = 17083
  200. /// Indicates that the multi factor info is not found.
  201. case multiFactorInfoNotFound = 17084
  202. /// Indicates that the operation is admin restricted.
  203. case adminRestrictedOperation = 17085
  204. /// Indicates that the email is required for verification.
  205. case unverifiedEmail = 17086
  206. /// Indicates that the second factor is already enrolled.
  207. case secondFactorAlreadyEnrolled = 17087
  208. /// Indicates that the maximum second factor count is exceeded.
  209. case maximumSecondFactorCountExceeded = 17088
  210. /// Indicates that the first factor is not supported.
  211. case unsupportedFirstFactor = 17089
  212. /// Indicates that the a verified email is required to changed to.
  213. case emailChangeNeedsVerification = 17090
  214. /// Indicates that the request does not contain a client identifier.
  215. case missingClientIdentifier = 17093
  216. /// Indicates that the nonce is missing or invalid.
  217. case missingOrInvalidNonce = 17094
  218. /// Raised when a Cloud Function returns a blocking error. Will include a message returned from
  219. /// the function.
  220. case blockingCloudFunctionError = 17105
  221. /// Indicates that reCAPTCHA Enterprise integration is not enabled for this project.
  222. case recaptchaNotEnabled = 17200
  223. /// Indicates that the reCAPTCHA token is missing from the backend request.
  224. case missingRecaptchaToken = 17201
  225. /// Indicates that the reCAPTCHA token sent with the backend request is invalid.
  226. case invalidRecaptchaToken = 17202
  227. /// Indicates that the requested reCAPTCHA action is invalid.
  228. case invalidRecaptchaAction = 17203
  229. /// Indicates that the client type is missing from the request.
  230. case missingClientType = 17204
  231. /// Indicates that the reCAPTCHA version is missing from the request.
  232. case missingRecaptchaVersion = 17205
  233. /// Indicates that the reCAPTCHA version sent to the backend is invalid.
  234. case invalidRecaptchaVersion = 17206
  235. /// Indicates that the request type sent to the backend is invalid.
  236. case invalidReqType = 17207
  237. /// Indicates that the reCAPTCHA SDK is not linked to the app.
  238. case recaptchaSDKNotLinked = 17208
  239. /// Indicates that the reCAPTCHA SDK site key wasn't found.
  240. case recaptchaSiteKeyMissing = 17209
  241. /// Indicates that the reCAPTCHA SDK actions class failed to create.
  242. case recaptchaActionCreationFailed = 17210
  243. /// Indicates an error occurred while attempting to access the keychain.
  244. case keychainError = 17995
  245. /// Indicates an internal error occurred.
  246. case internalError = 17999
  247. /// Raised when a JWT fails to parse correctly. May be accompanied by an underlying error
  248. /// describing which step of the JWT parsing process failed.
  249. case malformedJWT = 18000
  250. var errorDescription: String {
  251. switch self {
  252. case .invalidCustomToken:
  253. return kErrorInvalidCustomToken
  254. case .customTokenMismatch:
  255. return kErrorCustomTokenMismatch
  256. case .invalidEmail:
  257. return kErrorInvalidEmail
  258. case .invalidCredential:
  259. return kErrorInvalidCredential
  260. case .userDisabled:
  261. return kErrorUserDisabled
  262. case .emailAlreadyInUse:
  263. return kErrorEmailAlreadyInUse
  264. case .wrongPassword:
  265. return kErrorWrongPassword
  266. case .tooManyRequests:
  267. return kErrorTooManyRequests
  268. case .accountExistsWithDifferentCredential:
  269. return kErrorAccountExistsWithDifferentCredential
  270. case .requiresRecentLogin:
  271. return kErrorRequiresRecentLogin
  272. case .providerAlreadyLinked:
  273. return kErrorProviderAlreadyLinked
  274. case .noSuchProvider:
  275. return kErrorNoSuchProvider
  276. case .invalidUserToken:
  277. return kErrorInvalidUserToken
  278. case .networkError:
  279. return kErrorNetworkError
  280. case .keychainError:
  281. return kErrorKeychainError
  282. case .missingClientIdentifier:
  283. return kErrorMissingClientIdentifier
  284. case .userTokenExpired:
  285. return kErrorUserTokenExpired
  286. case .userNotFound:
  287. return kErrorUserNotFound
  288. case .invalidAPIKey:
  289. return kErrorInvalidAPIKey
  290. case .credentialAlreadyInUse:
  291. return kErrorCredentialAlreadyInUse
  292. case .internalError:
  293. return kErrorInternalError
  294. case .userMismatch:
  295. return FIRAuthErrorMessageUserMismatch
  296. case .operationNotAllowed:
  297. return kErrorOperationNotAllowed
  298. case .weakPassword:
  299. return kErrorWeakPassword
  300. case .appNotAuthorized:
  301. return kErrorAppNotAuthorized
  302. case .expiredActionCode:
  303. return kErrorExpiredActionCode
  304. case .invalidActionCode:
  305. return kErrorInvalidActionCode
  306. case .invalidSender:
  307. return kErrorInvalidSender
  308. case .invalidMessagePayload:
  309. return kErrorInvalidMessagePayload
  310. case .invalidRecipientEmail:
  311. return kErrorInvalidRecipientEmail
  312. case .missingIosBundleID:
  313. return kErrorMissingIosBundleID
  314. case .missingAndroidPackageName:
  315. return kErrorMissingAndroidPackageName
  316. case .unauthorizedDomain:
  317. return kErrorUnauthorizedDomain
  318. case .invalidContinueURI:
  319. return kErrorInvalidContinueURI
  320. case .missingContinueURI:
  321. return kErrorMissingContinueURI
  322. case .missingEmail:
  323. return kErrorMissingEmail
  324. case .missingPhoneNumber:
  325. return kErrorMissingPhoneNumber
  326. case .invalidPhoneNumber:
  327. return kErrorInvalidPhoneNumber
  328. case .missingVerificationCode:
  329. return kErrorMissingVerificationCode
  330. case .invalidVerificationCode:
  331. return kErrorInvalidVerificationCode
  332. case .missingVerificationID:
  333. return kErrorMissingVerificationID
  334. case .invalidVerificationID:
  335. return kErrorInvalidVerificationID
  336. case .sessionExpired:
  337. return kErrorSessionExpired
  338. case .missingAppCredential:
  339. return kErrorMissingAppCredential
  340. case .invalidAppCredential:
  341. return kErrorInvalidAppCredential
  342. case .quotaExceeded:
  343. return kErrorQuotaExceeded
  344. case .missingAppToken:
  345. return kErrorMissingAppToken
  346. case .notificationNotForwarded:
  347. return kErrorNotificationNotForwarded
  348. case .appNotVerified:
  349. return kErrorAppNotVerified
  350. case .captchaCheckFailed:
  351. return kErrorCaptchaCheckFailed
  352. case .webContextAlreadyPresented:
  353. return kErrorWebContextAlreadyPresented
  354. case .webContextCancelled:
  355. return kErrorWebContextCancelled
  356. case .invalidClientID:
  357. return kErrorInvalidClientID
  358. case .appVerificationUserInteractionFailure:
  359. return kErrorAppVerificationUserInteractionFailure
  360. case .webNetworkRequestFailed:
  361. return kErrorWebRequestFailed
  362. case .nullUser:
  363. return kErrorNullUser
  364. case .invalidProviderID:
  365. return kErrorInvalidProviderID
  366. case .invalidHostingLinkDomain:
  367. return kErrorInvalidHostingLinkDomain
  368. case .webInternalError:
  369. return kErrorWebInternalError
  370. case .webSignInUserInteractionFailure:
  371. return kErrorAppVerificationUserInteractionFailure
  372. case .malformedJWT:
  373. return kErrorMalformedJWT
  374. case .localPlayerNotAuthenticated:
  375. return kErrorLocalPlayerNotAuthenticated
  376. case .gameKitNotLinked:
  377. return kErrorGameKitNotLinked
  378. case .secondFactorRequired:
  379. return kErrorSecondFactorRequired
  380. case .missingMultiFactorSession:
  381. return FIRAuthErrorMessageMissingMultiFactorSession
  382. case .missingMultiFactorInfo:
  383. return FIRAuthErrorMessageMissingMultiFactorInfo
  384. case .invalidMultiFactorSession:
  385. return FIRAuthErrorMessageInvalidMultiFactorSession
  386. case .multiFactorInfoNotFound:
  387. return FIRAuthErrorMessageMultiFactorInfoNotFound
  388. case .adminRestrictedOperation:
  389. return FIRAuthErrorMessageAdminRestrictedOperation
  390. case .unverifiedEmail:
  391. return FIRAuthErrorMessageUnverifiedEmail
  392. case .secondFactorAlreadyEnrolled:
  393. return FIRAuthErrorMessageSecondFactorAlreadyEnrolled
  394. case .maximumSecondFactorCountExceeded:
  395. return FIRAuthErrorMessageMaximumSecondFactorCountExceeded
  396. case .unsupportedFirstFactor:
  397. return FIRAuthErrorMessageUnsupportedFirstFactor
  398. case .emailChangeNeedsVerification:
  399. return FIRAuthErrorMessageEmailChangeNeedsVerification
  400. case .rejectedCredential:
  401. return kErrorRejectedCredential
  402. case .missingOrInvalidNonce:
  403. return kErrorMissingOrInvalidNonce
  404. case .tenantIDMismatch:
  405. return kErrorTenantIDMismatch
  406. case .unsupportedTenantOperation:
  407. return kErrorUnsupportedTenantOperation
  408. case .blockingCloudFunctionError:
  409. return kErrorBlockingCloudFunctionReturnedError
  410. case .recaptchaNotEnabled:
  411. return kErrorRecaptchaNotEnabled
  412. case .missingRecaptchaToken:
  413. return kErrorMissingRecaptchaToken
  414. case .invalidRecaptchaToken:
  415. return kErrorInvalidRecaptchaToken
  416. case .invalidRecaptchaAction:
  417. return kErrorInvalidRecaptchaAction
  418. case .missingClientType:
  419. return kErrorMissingClientType
  420. case .missingRecaptchaVersion:
  421. return kErrorMissingRecaptchaVersion
  422. case .invalidRecaptchaVersion:
  423. return kErrorInvalidRecaptchaVersion
  424. case .invalidReqType:
  425. return kErrorInvalidReqType
  426. case .recaptchaSDKNotLinked:
  427. return kErrorRecaptchaSDKNotLinked
  428. case .recaptchaSiteKeyMissing:
  429. return kErrorSiteKeyMissing
  430. case .recaptchaActionCreationFailed:
  431. return kErrorRecaptchaActionCreationFailed
  432. }
  433. }
  434. /// The error code. It's redundant but implemented for compatibility with the Objective-C
  435. /// implementation.
  436. public var code: Self {
  437. return self
  438. }
  439. var errorCodeString: String {
  440. switch self {
  441. case .invalidCustomToken:
  442. return "ERROR_INVALID_CUSTOM_TOKEN"
  443. case .customTokenMismatch:
  444. return "ERROR_CUSTOM_TOKEN_MISMATCH"
  445. case .invalidEmail:
  446. return "ERROR_INVALID_EMAIL"
  447. case .invalidCredential:
  448. return "ERROR_INVALID_CREDENTIAL"
  449. case .userDisabled:
  450. return "ERROR_USER_DISABLED"
  451. case .emailAlreadyInUse:
  452. return "ERROR_EMAIL_ALREADY_IN_USE"
  453. case .wrongPassword:
  454. return "ERROR_WRONG_PASSWORD"
  455. case .tooManyRequests:
  456. return "ERROR_TOO_MANY_REQUESTS"
  457. case .accountExistsWithDifferentCredential:
  458. return "ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL"
  459. case .requiresRecentLogin:
  460. return "ERROR_REQUIRES_RECENT_LOGIN"
  461. case .providerAlreadyLinked:
  462. return "ERROR_PROVIDER_ALREADY_LINKED"
  463. case .noSuchProvider:
  464. return "ERROR_NO_SUCH_PROVIDER"
  465. case .invalidUserToken:
  466. return "ERROR_INVALID_USER_TOKEN"
  467. case .networkError:
  468. return "ERROR_NETWORK_REQUEST_FAILED"
  469. case .keychainError:
  470. return "ERROR_KEYCHAIN_ERROR"
  471. case .missingClientIdentifier:
  472. return "ERROR_MISSING_CLIENT_IDENTIFIER"
  473. case .userTokenExpired:
  474. return "ERROR_USER_TOKEN_EXPIRED"
  475. case .userNotFound:
  476. return "ERROR_USER_NOT_FOUND"
  477. case .invalidAPIKey:
  478. return "ERROR_INVALID_API_KEY"
  479. case .credentialAlreadyInUse:
  480. return "ERROR_CREDENTIAL_ALREADY_IN_USE"
  481. case .internalError:
  482. return "ERROR_INTERNAL_ERROR"
  483. case .userMismatch:
  484. return "ERROR_USER_MISMATCH"
  485. case .operationNotAllowed:
  486. return "ERROR_OPERATION_NOT_ALLOWED"
  487. case .weakPassword:
  488. return "ERROR_WEAK_PASSWORD"
  489. case .appNotAuthorized:
  490. return "ERROR_APP_NOT_AUTHORIZED"
  491. case .expiredActionCode:
  492. return "ERROR_EXPIRED_ACTION_CODE"
  493. case .invalidActionCode:
  494. return "ERROR_INVALID_ACTION_CODE"
  495. case .invalidMessagePayload:
  496. return "ERROR_INVALID_MESSAGE_PAYLOAD"
  497. case .invalidSender:
  498. return "ERROR_INVALID_SENDER"
  499. case .invalidRecipientEmail:
  500. return "ERROR_INVALID_RECIPIENT_EMAIL"
  501. case .missingIosBundleID:
  502. return "ERROR_MISSING_IOS_BUNDLE_ID"
  503. case .missingAndroidPackageName:
  504. return "ERROR_MISSING_ANDROID_PKG_NAME"
  505. case .unauthorizedDomain:
  506. return "ERROR_UNAUTHORIZED_DOMAIN"
  507. case .invalidContinueURI:
  508. return "ERROR_INVALID_CONTINUE_URI"
  509. case .missingContinueURI:
  510. return "ERROR_MISSING_CONTINUE_URI"
  511. case .missingEmail:
  512. return "ERROR_MISSING_EMAIL"
  513. case .missingPhoneNumber:
  514. return "ERROR_MISSING_PHONE_NUMBER"
  515. case .invalidPhoneNumber:
  516. return "ERROR_INVALID_PHONE_NUMBER"
  517. case .missingVerificationCode:
  518. return "ERROR_MISSING_VERIFICATION_CODE"
  519. case .invalidVerificationCode:
  520. return "ERROR_INVALID_VERIFICATION_CODE"
  521. case .missingVerificationID:
  522. return "ERROR_MISSING_VERIFICATION_ID"
  523. case .invalidVerificationID:
  524. return "ERROR_INVALID_VERIFICATION_ID"
  525. case .sessionExpired:
  526. return "ERROR_SESSION_EXPIRED"
  527. case .missingAppCredential:
  528. return "MISSING_APP_CREDENTIAL"
  529. case .invalidAppCredential:
  530. return "INVALID_APP_CREDENTIAL"
  531. case .quotaExceeded:
  532. return "ERROR_QUOTA_EXCEEDED"
  533. case .missingAppToken:
  534. return "ERROR_MISSING_APP_TOKEN"
  535. case .notificationNotForwarded:
  536. return "ERROR_NOTIFICATION_NOT_FORWARDED"
  537. case .appNotVerified:
  538. return "ERROR_APP_NOT_VERIFIED"
  539. case .captchaCheckFailed:
  540. return "ERROR_CAPTCHA_CHECK_FAILED"
  541. case .webContextAlreadyPresented:
  542. return "ERROR_WEB_CONTEXT_ALREADY_PRESENTED"
  543. case .webContextCancelled:
  544. return "ERROR_WEB_CONTEXT_CANCELLED"
  545. case .invalidClientID:
  546. return "ERROR_INVALID_CLIENT_ID"
  547. case .appVerificationUserInteractionFailure:
  548. return "ERROR_APP_VERIFICATION_FAILED"
  549. case .webNetworkRequestFailed:
  550. return "ERROR_WEB_NETWORK_REQUEST_FAILED"
  551. case .nullUser:
  552. return "ERROR_NULL_USER"
  553. case .invalidProviderID:
  554. return "ERROR_INVALID_PROVIDER_ID"
  555. case .invalidHostingLinkDomain:
  556. return "ERROR_INVALID_HOSTING_LINK_DOMAIN"
  557. case .webInternalError:
  558. return "ERROR_WEB_INTERNAL_ERROR"
  559. case .webSignInUserInteractionFailure:
  560. return "ERROR_WEB_USER_INTERACTION_FAILURE"
  561. case .malformedJWT:
  562. return "ERROR_MALFORMED_JWT"
  563. case .localPlayerNotAuthenticated:
  564. return "ERROR_LOCAL_PLAYER_NOT_AUTHENTICATED"
  565. case .gameKitNotLinked:
  566. return "ERROR_GAME_KIT_NOT_LINKED"
  567. case .secondFactorRequired:
  568. return "ERROR_SECOND_FACTOR_REQUIRED"
  569. case .missingMultiFactorSession:
  570. return "ERROR_MISSING_MULTI_FACTOR_SESSION"
  571. case .missingMultiFactorInfo:
  572. return "ERROR_MISSING_MULTI_FACTOR_INFO"
  573. case .invalidMultiFactorSession:
  574. return "ERROR_INVALID_MULTI_FACTOR_SESSION"
  575. case .multiFactorInfoNotFound:
  576. return "ERROR_MULTI_FACTOR_INFO_NOT_FOUND"
  577. case .adminRestrictedOperation:
  578. return "ERROR_ADMIN_RESTRICTED_OPERATION"
  579. case .unverifiedEmail:
  580. return "ERROR_UNVERIFIED_EMAIL"
  581. case .secondFactorAlreadyEnrolled:
  582. return "ERROR_SECOND_FACTOR_ALREADY_ENROLLED"
  583. case .maximumSecondFactorCountExceeded:
  584. return "ERROR_MAXIMUM_SECOND_FACTOR_COUNT_EXCEEDED"
  585. case .unsupportedFirstFactor:
  586. return "ERROR_UNSUPPORTED_FIRST_FACTOR"
  587. case .emailChangeNeedsVerification:
  588. return "ERROR_EMAIL_CHANGE_NEEDS_VERIFICATION"
  589. case .rejectedCredential:
  590. return "ERROR_REJECTED_CREDENTIAL"
  591. case .missingOrInvalidNonce:
  592. return "ERROR_MISSING_OR_INVALID_NONCE"
  593. case .tenantIDMismatch:
  594. return "ERROR_TENANT_ID_MISMATCH"
  595. case .unsupportedTenantOperation:
  596. return "ERROR_UNSUPPORTED_TENANT_OPERATION"
  597. case .blockingCloudFunctionError:
  598. return "ERROR_BLOCKING_CLOUD_FUNCTION_RETURNED_ERROR"
  599. case .recaptchaNotEnabled:
  600. return "ERROR_RECAPTCHA_NOT_ENABLED"
  601. case .missingRecaptchaToken:
  602. return "ERROR_MISSING_RECAPTCHA_TOKEN"
  603. case .invalidRecaptchaToken:
  604. return "ERROR_INVALID_RECAPTCHA_TOKEN"
  605. case .invalidRecaptchaAction:
  606. return "ERROR_INVALID_RECAPTCHA_ACTION"
  607. case .missingClientType:
  608. return "ERROR_MISSING_CLIENT_TYPE"
  609. case .missingRecaptchaVersion:
  610. return "ERROR_MISSING_RECAPTCHA_VERSION"
  611. case .invalidRecaptchaVersion:
  612. return "ERROR_INVALID_RECAPTCHA_VERSION"
  613. case .invalidReqType:
  614. return "ERROR_INVALID_REQ_TYPE"
  615. case .recaptchaSDKNotLinked:
  616. return "ERROR_RECAPTCHA_SDK_NOT_LINKED"
  617. case .recaptchaSiteKeyMissing:
  618. return "ERROR_RECAPTCHA_SITE_KEY_MISSING"
  619. case .recaptchaActionCreationFailed:
  620. return "ERROR_RECAPTCHA_ACTION_CREATION_FAILED"
  621. }
  622. }
  623. }
  624. // MARK: - Standard Error Messages
  625. private let kErrorInvalidCustomToken =
  626. "The custom token format is incorrect. Please check the documentation."
  627. private let kErrorCustomTokenMismatch =
  628. "The custom token corresponds to a different audience."
  629. private let kErrorInvalidEmail = "The email address is badly formatted."
  630. private let kErrorInvalidCredential =
  631. "The supplied auth credential is malformed or has expired."
  632. private let kErrorUserDisabled =
  633. "The user account has been disabled by an administrator."
  634. private let kErrorEmailAlreadyInUse =
  635. "The email address is already in use by another account."
  636. private let kErrorWrongPassword =
  637. "The password is invalid or the user does not have a password."
  638. private let kErrorTooManyRequests =
  639. "We have blocked all requests from this device due to unusual activity. Try again later."
  640. private let kErrorAccountExistsWithDifferentCredential =
  641. "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address."
  642. private let kErrorRequiresRecentLogin =
  643. "This operation is sensitive and requires recent authentication. Log in again before retrying this request."
  644. private let kErrorProviderAlreadyLinked =
  645. "[ERROR_PROVIDER_ALREADY_LINKED] - User can only be linked to one identity for the given provider."
  646. private let kErrorNoSuchProvider =
  647. "User was not linked to an account with the given provider."
  648. private let kErrorInvalidUserToken =
  649. "This user's credential isn't valid for this project. This can happen if the user's token has been tampered with, or if the user doesn’t belong to the project associated with the API key used in your request."
  650. private let kErrorNetworkError =
  651. "Network error (such as timeout, interrupted connection or unreachable host) has occurred."
  652. private let kErrorKeychainError =
  653. "An error occurred when accessing the keychain. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo dictionary will contain more information about the error encountered"
  654. private let kErrorUserTokenExpired =
  655. "The user's credential is no longer valid. The user must sign in again."
  656. private let kErrorUserNotFound =
  657. "There is no user record corresponding to this identifier. The user may have been deleted."
  658. private let kErrorInvalidAPIKey = "An invalid API Key was supplied in the request."
  659. private let FIRAuthErrorMessageUserMismatch =
  660. "The supplied credentials do not correspond to the previously signed in user."
  661. private let kErrorCredentialAlreadyInUse =
  662. "This credential is already associated with a different user account."
  663. private let kErrorOperationNotAllowed =
  664. "The given sign-in provider is disabled for this Firebase project. Enable it in the Firebase console, under the sign-in method tab of the Auth section."
  665. private let kErrorWeakPassword = "The password must be 6 characters long or more."
  666. private let kErrorAppNotAuthorized =
  667. "This app is not authorized to use Firebase Authentication with the provided API key. Review your key configuration in the Google API console and ensure that it accepts requests from your app's bundle ID."
  668. private let kErrorExpiredActionCode = "The action code has expired."
  669. private let kErrorInvalidActionCode =
  670. "The action code is invalid. This can happen if the code is malformed, expired, or has already been used."
  671. private let kErrorInvalidMessagePayload =
  672. "The action code is invalid. This can happen if the code is malformed, expired, or has already been used."
  673. private let kErrorInvalidSender =
  674. "The email template corresponding to this action contains invalid characters in its message. Please fix by going to the Auth email templates section in the Firebase Console."
  675. private let kErrorInvalidRecipientEmail =
  676. "The action code is invalid. This can happen if the code is malformed, expired, or has already been used."
  677. private let kErrorMissingIosBundleID =
  678. "An iOS Bundle ID must be provided if an App Store ID is provided."
  679. private let kErrorMissingAndroidPackageName =
  680. "An Android Package Name must be provided if the Android App is required to be installed."
  681. private let kErrorUnauthorizedDomain =
  682. "The domain of the continue URL is not allowlisted. Please allowlist the domain in the Firebase console."
  683. private let kErrorInvalidContinueURI =
  684. "The continue URL provided in the request is invalid."
  685. private let kErrorMissingEmail = "An email address must be provided."
  686. private let kErrorMissingContinueURI =
  687. "A continue URL must be provided in the request."
  688. private let kErrorMissingPhoneNumber =
  689. "To send verification codes, provide a phone number for the recipient."
  690. private let kErrorInvalidPhoneNumber =
  691. "The format of the phone number provided is incorrect. Please enter the phone number in a format that can be parsed into E.164 format. E.164 phone numbers are written in the format [+][country code][subscriber number including area code]."
  692. private let kErrorMissingVerificationCode =
  693. "The phone auth credential was created with an empty SMS verification Code."
  694. private let kErrorInvalidVerificationCode =
  695. "The multifactor verification code used to create the auth credential is invalid. " +
  696. "Re-collect the verification code and be sure to use the verification code provided by the user."
  697. private let kErrorMissingVerificationID =
  698. "The phone auth credential was created with an empty verification ID."
  699. private let kErrorInvalidVerificationID =
  700. "The verification ID used to create the phone auth credential is invalid."
  701. private let kErrorLocalPlayerNotAuthenticated =
  702. "The local player is not authenticated. Please log the local player in to Game Center."
  703. private let kErrorGameKitNotLinked =
  704. "The GameKit framework is not linked. Please turn on the Game Center capability."
  705. private let kErrorSessionExpired =
  706. "The SMS code has expired. Please re-send the verification code to try again."
  707. private let kErrorMissingAppCredential =
  708. "The phone verification request is missing an APNs Device token. Firebase Auth automatically detects APNs Device Tokens, however, if method swizzling is disabled, the APNs token must be set via the APNSToken property on FIRAuth or by calling setAPNSToken:type on FIRAuth."
  709. private let kErrorInvalidAppCredential =
  710. "The APNs device token provided is either incorrect or does not match the private certificate uploaded to the Firebase Console."
  711. private let kErrorQuotaExceeded = "The quota for this operation has been exceeded."
  712. private let kErrorMissingAppToken =
  713. "There seems to be a problem with your project's Firebase phone number authentication set-up, please make sure to follow the instructions found at https://firebase.google.com/docs/auth/ios/phone-auth"
  714. private let kErrorNotificationNotForwarded =
  715. "If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to" +
  716. "be forwarded to FirebaseAuth's canHandleNotification method."
  717. private let kErrorAppNotVerified =
  718. "Firebase could not retrieve the silent push notification and therefore could not verify your app. Ensure that you configured your app correctly to receive push notifications."
  719. private let kErrorCaptchaCheckFailed =
  720. "The reCAPTCHA response token provided is either invalid, expired or already"
  721. private let kErrorWebContextAlreadyPresented =
  722. "User interaction is still ongoing, another view cannot be presented."
  723. private let kErrorWebContextCancelled = "The interaction was cancelled by the user."
  724. private let kErrorInvalidClientID =
  725. "The OAuth client ID provided is either invalid or does not match the specified API key."
  726. private let kErrorWebRequestFailed =
  727. "A network error (such as timeout, interrupted connection, or unreachable host) has occurred within the web context."
  728. private let kErrorWebInternalError =
  729. "An internal error has occurred within the SFSafariViewController or WKWebView."
  730. private let kErrorAppVerificationUserInteractionFailure =
  731. "The app verification process has failed, print and inspect the error details for more information"
  732. private let kErrorNullUser =
  733. "A null user object was provided as the argument for an operation which requires a non-null user object."
  734. private let kErrorInvalidProviderID =
  735. "The provider ID provided for the attempted web operation is invalid."
  736. private let kErrorInvalidDynamicLinkDomain =
  737. "The Firebase Dynamic Link domain used is either not configured or is unauthorized for the current project."
  738. private let kErrorInvalidHostingLinkDomain =
  739. "The provided hosting link domain is not configured in Firebase Hosting or is not owned by the current project."
  740. private let kErrorInternalError =
  741. "An internal error has occurred, print and inspect the error details for more information."
  742. private let kErrorMalformedJWT =
  743. "Failed to parse JWT. Check the userInfo dictionary for the full token."
  744. private let kErrorSecondFactorRequired =
  745. "Please complete a second factor challenge to finish signing into this account."
  746. private let FIRAuthErrorMessageMissingMultiFactorSession =
  747. "The request is missing proof of first factor successful sign-in."
  748. private let FIRAuthErrorMessageMissingMultiFactorInfo =
  749. "No second factor identifier is provided."
  750. private let FIRAuthErrorMessageInvalidMultiFactorSession =
  751. "The request does not contain a valid proof of first factor successful sign-in."
  752. private let FIRAuthErrorMessageMultiFactorInfoNotFound =
  753. "The user does not have a second factor matching the identifier provided."
  754. private let FIRAuthErrorMessageAdminRestrictedOperation =
  755. "This operation is restricted to administrators only."
  756. private let FIRAuthErrorMessageUnverifiedEmail =
  757. "The operation requires a verified email."
  758. private let FIRAuthErrorMessageSecondFactorAlreadyEnrolled =
  759. "The second factor is already enrolled on this account."
  760. private let FIRAuthErrorMessageMaximumSecondFactorCountExceeded =
  761. "The maximum allowed number of second factors on a user has been exceeded."
  762. private let FIRAuthErrorMessageUnsupportedFirstFactor =
  763. "Enrolling a second factor or signing in with a multi-factor account requires sign-in with a supported first factor."
  764. private let FIRAuthErrorMessageEmailChangeNeedsVerification =
  765. "Multi-factor users must always have a verified email."
  766. private let kErrorDynamicLinkNotActivated =
  767. "Please activate Dynamic Links in the Firebase Console and agree to the terms and conditions."
  768. private let kErrorRejectedCredential =
  769. "The request contains malformed or mismatching credentials."
  770. private let kErrorMissingClientIdentifier =
  771. "The request does not contain a client identifier."
  772. private let kErrorMissingOrInvalidNonce =
  773. "The request contains malformed or mismatched credentials."
  774. private let kErrorTenantIDMismatch =
  775. "The provided user's tenant ID does not match the Auth instance's tenant ID."
  776. private let kErrorUnsupportedTenantOperation =
  777. "This operation is not supported in a multi-tenant context."
  778. private let kErrorBlockingCloudFunctionReturnedError =
  779. "Blocking cloud function returned an error."
  780. private let kErrorRecaptchaNotEnabled =
  781. "reCAPTCHA Enterprise is not enabled for this project."
  782. private let kErrorMissingRecaptchaToken =
  783. "The backend request is missing the reCAPTCHA verification token."
  784. private let kErrorInvalidRecaptchaToken =
  785. "The reCAPTCHA verification token is invalid or has expired."
  786. private let kErrorInvalidRecaptchaAction =
  787. "The reCAPTCHA verification failed due to an invalid action."
  788. private let kErrorMissingClientType =
  789. "The request is missing a client type or the client type is invalid."
  790. private let kErrorMissingRecaptchaVersion =
  791. "The request is missing the reCAPTCHA version parameter."
  792. private let kErrorInvalidRecaptchaVersion =
  793. "The request specifies an invalid version of reCAPTCHA."
  794. private let kErrorInvalidReqType =
  795. "The request is not supported or is invalid."
  796. // TODO(chuanr, ObjC): point the link to GCIP doc once available.
  797. private let kErrorRecaptchaSDKNotLinked =
  798. "The reCAPTCHA SDK is not linked to your app. See " +
  799. "https://cloud.google.com/recaptcha-enterprise/docs/instrument-ios-apps"
  800. private let kErrorSiteKeyMissing =
  801. "The reCAPTCHA SDK site key wasn't found. See " +
  802. "https://cloud.google.com/recaptcha-enterprise/docs/instrument-ios-apps"
  803. private let kErrorRecaptchaActionCreationFailed =
  804. "The reCAPTCHA SDK action class failed to initialize. See " +
  805. "https://cloud.google.com/recaptcha-enterprise/docs/instrument-ios-apps"