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.

927 lines
42 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 <AvailabilityMacros.h>
  17. #import <Foundation/Foundation.h>
  18. #import "FIRAuthErrors.h"
  19. #if TARGET_OS_IOS
  20. #import "FIRAuthAPNSTokenType.h"
  21. #endif
  22. @class FIRActionCodeSettings;
  23. @class FIRApp;
  24. @class FIRAuth;
  25. @class FIRAuthCredential;
  26. @class FIRAuthDataResult;
  27. @class FIRAuthSettings;
  28. @class FIRUser;
  29. @protocol FIRAuthStateListener;
  30. NS_ASSUME_NONNULL_BEGIN
  31. /** @typedef FIRUserUpdateCallback
  32. @brief The type of block invoked when a request to update the current user is completed.
  33. */
  34. typedef void (^FIRUserUpdateCallback)(NSError *_Nullable error) NS_SWIFT_NAME(UserUpdateCallback);
  35. /** @typedef FIRAuthStateDidChangeListenerHandle
  36. @brief The type of handle returned by `FIRAuth.addAuthStateDidChangeListener:`.
  37. */
  38. typedef id<NSObject> FIRAuthStateDidChangeListenerHandle
  39. NS_SWIFT_NAME(AuthStateDidChangeListenerHandle);
  40. /** @typedef FIRAuthStateDidChangeListenerBlock
  41. @brief The type of block which can be registered as a listener for auth state did change events.
  42. @param auth The FIRAuth object on which state changes occurred.
  43. @param user Optionally; the current signed in user, if any.
  44. */
  45. typedef void(^FIRAuthStateDidChangeListenerBlock)(FIRAuth *auth, FIRUser *_Nullable user)
  46. NS_SWIFT_NAME(AuthStateDidChangeListenerBlock);
  47. /** @typedef FIRIDTokenDidChangeListenerHandle
  48. @brief The type of handle returned by `FIRAuth.addIDTokenDidChangeListener:`.
  49. */
  50. typedef id<NSObject> FIRIDTokenDidChangeListenerHandle
  51. NS_SWIFT_NAME(IDTokenDidChangeListenerHandle);
  52. /** @typedef FIRIDTokenDidChangeListenerBlock
  53. @brief The type of block which can be registered as a listener for ID token did change events.
  54. @param auth The FIRAuth object on which ID token changes occurred.
  55. @param user Optionally; the current signed in user, if any.
  56. */
  57. typedef void(^FIRIDTokenDidChangeListenerBlock)(FIRAuth *auth, FIRUser *_Nullable user)
  58. NS_SWIFT_NAME(IDTokenDidChangeListenerBlock);
  59. /** @typedef FIRAuthDataResultCallback
  60. @brief The type of block invoked when sign-in related events complete.
  61. @param authResult Optionally; Result of sign-in request containing both the user and
  62. the additional user info associated with the user.
  63. @param error Optionally; the error which occurred - or nil if the request was successful.
  64. */
  65. typedef void (^FIRAuthDataResultCallback)(FIRAuthDataResult *_Nullable authResult,
  66. NSError *_Nullable error)
  67. NS_SWIFT_NAME(AuthDataResultCallback);
  68. #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  69. /**
  70. @brief The name of the `NSNotificationCenter` notification which is posted when the auth state
  71. changes (for example, a new token has been produced, a user signs in or signs out). The
  72. object parameter of the notification is the sender `FIRAuth` instance.
  73. */
  74. extern const NSNotificationName FIRAuthStateDidChangeNotification
  75. NS_SWIFT_NAME(AuthStateDidChange);
  76. #else
  77. /**
  78. @brief The name of the `NSNotificationCenter` notification which is posted when the auth state
  79. changes (for example, a new token has been produced, a user signs in or signs out). The
  80. object parameter of the notification is the sender `FIRAuth` instance.
  81. */
  82. extern NSString *const FIRAuthStateDidChangeNotification
  83. NS_SWIFT_NAME(AuthStateDidChangeNotification);
  84. #endif // defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  85. /** @typedef FIRAuthResultCallback
  86. @brief The type of block invoked when sign-in related events complete.
  87. @param user Optionally; the signed in user, if any.
  88. @param error Optionally; if an error occurs, this is the NSError object that describes the
  89. problem. Set to nil otherwise.
  90. */
  91. typedef void (^FIRAuthResultCallback)(FIRUser *_Nullable user, NSError *_Nullable error)
  92. NS_SWIFT_NAME(AuthResultCallback);
  93. /** @typedef FIRProviderQueryCallback
  94. @brief The type of block invoked when a list of identity providers for a given email address is
  95. requested.
  96. @param providers Optionally; a list of provider identifiers, if any.
  97. @see FIRGoogleAuthProviderID etc.
  98. @param error Optionally; if an error occurs, this is the NSError object that describes the
  99. problem. Set to nil otherwise.
  100. */
  101. typedef void (^FIRProviderQueryCallback)(NSArray<NSString *> *_Nullable providers,
  102. NSError *_Nullable error)
  103. NS_SWIFT_NAME(ProviderQueryCallback);
  104. /** @typedef FIRSignInMethodQueryCallback
  105. @brief The type of block invoked when a list of sign-in methods for a given email address is
  106. requested.
  107. */
  108. typedef void (^FIRSignInMethodQueryCallback)(NSArray<NSString *> *_Nullable,
  109. NSError *_Nullable)
  110. NS_SWIFT_NAME(SignInMethodQueryCallback);
  111. /** @typedef FIRSendPasswordResetCallback
  112. @brief The type of block invoked when sending a password reset email.
  113. @param error Optionally; if an error occurs, this is the NSError object that describes the
  114. problem. Set to nil otherwise.
  115. */
  116. typedef void (^FIRSendPasswordResetCallback)(NSError *_Nullable error)
  117. NS_SWIFT_NAME(SendPasswordResetCallback);
  118. /** @typedef FIRSendSignInLinkToEmailCallback
  119. @brief The type of block invoked when sending an email sign-in link email.
  120. */
  121. typedef void (^FIRSendSignInLinkToEmailCallback)(NSError *_Nullable error)
  122. NS_SWIFT_NAME(SendSignInLinkToEmailCallback);
  123. /** @typedef FIRConfirmPasswordResetCallback
  124. @brief The type of block invoked when performing a password reset.
  125. @param error Optionally; if an error occurs, this is the NSError object that describes the
  126. problem. Set to nil otherwise.
  127. */
  128. typedef void (^FIRConfirmPasswordResetCallback)(NSError *_Nullable error)
  129. NS_SWIFT_NAME(ConfirmPasswordResetCallback);
  130. /** @typedef FIRVerifyPasswordResetCodeCallback
  131. @brief The type of block invoked when verifying that an out of band code should be used to
  132. perform password reset.
  133. @param email Optionally; the email address of the user for which the out of band code applies.
  134. @param error Optionally; if an error occurs, this is the NSError object that describes the
  135. problem. Set to nil otherwise.
  136. */
  137. typedef void (^FIRVerifyPasswordResetCodeCallback)(NSString *_Nullable email,
  138. NSError *_Nullable error)
  139. NS_SWIFT_NAME(VerifyPasswordResetCodeCallback);
  140. /** @typedef FIRApplyActionCodeCallback
  141. @brief The type of block invoked when applying an action code.
  142. @param error Optionally; if an error occurs, this is the NSError object that describes the
  143. problem. Set to nil otherwise.
  144. */
  145. typedef void (^FIRApplyActionCodeCallback)(NSError *_Nullable error)
  146. NS_SWIFT_NAME(ApplyActionCodeCallback);
  147. /**
  148. @brief Keys used to retrieve operation data from a `FIRActionCodeInfo` object by the
  149. `dataForKey` method.
  150. */
  151. typedef NS_ENUM(NSInteger, FIRActionDataKey) {
  152. /**
  153. * The email address to which the code was sent.
  154. * For FIRActionCodeOperationRecoverEmail, the new email address for the account.
  155. */
  156. FIRActionCodeEmailKey = 0,
  157. /** For FIRActionCodeOperationRecoverEmail, the current email address for the account. */
  158. FIRActionCodeFromEmailKey = 1
  159. } NS_SWIFT_NAME(ActionDataKey);
  160. /** @class FIRActionCodeInfo
  161. @brief Manages information regarding action codes.
  162. */
  163. NS_SWIFT_NAME(ActionCodeInfo)
  164. @interface FIRActionCodeInfo : NSObject
  165. /**
  166. @brief Operations which can be performed with action codes.
  167. */
  168. typedef NS_ENUM(NSInteger, FIRActionCodeOperation) {
  169. /** Action code for unknown operation. */
  170. FIRActionCodeOperationUnknown = 0,
  171. /** Action code for password reset operation. */
  172. FIRActionCodeOperationPasswordReset = 1,
  173. /** Action code for verify email operation. */
  174. FIRActionCodeOperationVerifyEmail = 2,
  175. /** Action code for recover email operation. */
  176. FIRActionCodeOperationRecoverEmail = 3,
  177. /** Action code for email link operation. */
  178. FIRActionCodeOperationEmailLink = 4,
  179. } NS_SWIFT_NAME(ActionCodeOperation);
  180. /**
  181. @brief The operation being performed.
  182. */
  183. @property(nonatomic, readonly) FIRActionCodeOperation operation;
  184. /** @fn dataForKey:
  185. @brief The operation being performed.
  186. @param key The FIRActionDataKey value used to retrieve the operation data.
  187. @return The operation data pertaining to the provided action code key.
  188. */
  189. - (NSString *)dataForKey:(FIRActionDataKey)key;
  190. /** @fn init
  191. @brief please use initWithOperation: instead.
  192. */
  193. - (instancetype)init NS_UNAVAILABLE;
  194. @end
  195. /** @typedef FIRCheckActionCodeCallBack
  196. @brief The type of block invoked when performing a check action code operation.
  197. @param info Metadata corresponding to the action code.
  198. @param error Optionally; if an error occurs, this is the NSError object that describes the
  199. problem. Set to nil otherwise.
  200. */
  201. typedef void (^FIRCheckActionCodeCallBack)(FIRActionCodeInfo *_Nullable info,
  202. NSError *_Nullable error)
  203. NS_SWIFT_NAME(CheckActionCodeCallback);
  204. /** @class FIRAuth
  205. @brief Manages authentication for Firebase apps.
  206. @remarks This class is thread-safe.
  207. */
  208. NS_SWIFT_NAME(Auth)
  209. @interface FIRAuth : NSObject
  210. /** @fn auth
  211. @brief Gets the auth object for the default Firebase app.
  212. @remarks The default Firebase app must have already been configured or an exception will be
  213. raised.
  214. */
  215. + (FIRAuth *)auth NS_SWIFT_NAME(auth());
  216. /** @fn authWithApp:
  217. @brief Gets the auth object for a `FIRApp`.
  218. @param app The FIRApp for which to retrieve the associated FIRAuth instance.
  219. @return The FIRAuth instance associated with the given FIRApp.
  220. */
  221. + (FIRAuth *)authWithApp:(FIRApp *)app NS_SWIFT_NAME(auth(app:));
  222. /** @property app
  223. @brief Gets the `FIRApp` object that this auth object is connected to.
  224. */
  225. @property(nonatomic, weak, readonly, nullable) FIRApp *app;
  226. /** @property currentUser
  227. @brief Synchronously gets the cached current user, or null if there is none.
  228. */
  229. @property(nonatomic, strong, readonly, nullable) FIRUser *currentUser;
  230. /** @property languageCode
  231. @brief The current user language code. This property can be set to the app's current language by
  232. calling `useAppLanguage`.
  233. @remarks The string used to set this property must be a language code that follows BCP 47.
  234. */
  235. @property (nonatomic, copy, nullable) NSString *languageCode;
  236. /** @property settings
  237. @brief Contains settings related to the auth object.
  238. */
  239. @property (nonatomic, copy, nullable) FIRAuthSettings *settings;
  240. #if TARGET_OS_IOS
  241. /** @property APNSToken
  242. @brief The APNs token used for phone number authentication. The type of the token (production
  243. or sandbox) will be attempted to be automatcially detected.
  244. @remarks If swizzling is disabled, the APNs Token must be set for phone number auth to work,
  245. by either setting this property or by calling `setAPNSToken:type:`
  246. */
  247. @property(nonatomic, strong, nullable) NSData *APNSToken;
  248. #endif
  249. /** @fn init
  250. @brief Please access auth instances using `FIRAuth.auth` and `FIRAuth.authForApp:`.
  251. */
  252. - (instancetype)init NS_UNAVAILABLE;
  253. /** @fn updateCurrentUser:completion:
  254. @brief Sets the currentUser on the calling Auth instance to the provided user object.
  255. @param user The user object to be set as the current user of the calling Auth instance.
  256. @param completion Optionally; a block invoked after the user of the calling Auth instance has
  257. been updated or an error was encountered.
  258. */
  259. - (void)updateCurrentUser:(FIRUser *)user completion:(nullable FIRUserUpdateCallback)completion;
  260. /** @fn fetchProvidersForEmail:completion:
  261. @brief Fetches the list of IdPs that can be used for signing in with the provided email address.
  262. Useful for an "identifier-first" sign-in flow.
  263. @param email The email address for which to obtain a list of identity providers.
  264. @param completion Optionally; a block which is invoked when the list of providers for the
  265. specified email address is ready or an error was encountered. Invoked asynchronously on the
  266. main thread in the future.
  267. @remarks Possible error codes:
  268. + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  269. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  270. */
  271. - (void)fetchProvidersForEmail:(NSString *)email
  272. completion:(nullable FIRProviderQueryCallback)completion;
  273. /** @fn fetchSignInMethodsForEmail:completion:
  274. @brief Fetches the list of all sign-in methods previously used for the provided email address.
  275. @param email The email address for which to obtain a list of sign-in methods.
  276. @param completion Optionally; a block which is invoked when the list of sign in methods for the
  277. specified email address is ready or an error was encountered. Invoked asynchronously on the
  278. main thread in the future.
  279. @remarks Possible error codes:
  280. + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  281. @remarks See @c FIRAuthErrors for a list of error codes that are common to all API methods.
  282. */
  283. - (void)fetchSignInMethodsForEmail:(NSString *)email
  284. completion:(nullable FIRSignInMethodQueryCallback)completion;
  285. /** @fn signInWithEmail:password:completion:
  286. @brief Signs in using an email address and password.
  287. @param email The user's email address.
  288. @param password The user's password.
  289. @param completion Optionally; a block which is invoked when the sign in flow finishes, or is
  290. canceled. Invoked asynchronously on the main thread in the future.
  291. @remarks Possible error codes:
  292. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and password
  293. accounts are not enabled. Enable them in the Auth section of the
  294. Firebase console.
  295. + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  296. + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted
  297. sign in with an incorrect password.
  298. + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  299. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  300. */
  301. - (void)signInWithEmail:(NSString *)email
  302. password:(NSString *)password
  303. completion:(nullable FIRAuthDataResultCallback)completion;
  304. /** @fn signInWithEmail:link:completion:
  305. @brief Signs in using an email address and email sign-in link.
  306. @param email The user's email address.
  307. @param link The email sign-in link.
  308. @param completion Optionally; a block which is invoked when the sign in flow finishes, or is
  309. canceled. Invoked asynchronously on the main thread in the future.
  310. @remarks Possible error codes:
  311. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and email sign-in link
  312. accounts are not enabled. Enable them in the Auth section of the
  313. Firebase console.
  314. + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  315. + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is invalid.
  316. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  317. */
  318. - (void)signInWithEmail:(NSString *)email
  319. link:(NSString *)link
  320. completion:(nullable FIRAuthDataResultCallback)completion;
  321. /** @fn signInAndRetrieveDataWithEmail:password:completion:
  322. @brief Please use `signInWithEmail:password:completion:` for Objective-C or
  323. `signIn(withEmail:password:completion:)` for Swift instead.
  324. @param email The user's email address.
  325. @param password The user's password.
  326. @param completion Optionally; a block which is invoked when the sign in flow finishes, or is
  327. canceled. Invoked asynchronously on the main thread in the future.
  328. @remarks Possible error codes:
  329. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and password
  330. accounts are not enabled. Enable them in the Auth section of the
  331. Firebase console.
  332. + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  333. + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted
  334. sign in with an incorrect password.
  335. + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  336. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  337. */
  338. - (void)signInAndRetrieveDataWithEmail:(NSString *)email
  339. password:(NSString *)password
  340. completion:(nullable FIRAuthDataResultCallback)completion
  341. DEPRECATED_MSG_ATTRIBUTE(
  342. "Please use signInWithEmail:password:completion: for"
  343. " Objective-C or signIn(withEmail:password:completion:) for"
  344. " Swift instead.");
  345. /** @fn signInWithCredential:completion:
  346. @brief Please use `signInAndRetrieveDataWithCredential:completion:` for Objective-C or
  347. `signInAndRetrieveData(with:completion:)` for swift instead
  348. @param credential The credential supplied by the IdP.
  349. @param completion Optionally; a block which is invoked when the sign in flow finishes, or is
  350. canceled. Invoked asynchronously on the main thread in the future.
  351. @remarks Possible error codes:
  352. + `FIRAuthErrorCodeInvalidCredential` - Indicates the supplied credential is invalid.
  353. This could happen if it has expired or it is malformed.
  354. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that accounts
  355. with the identity provider represented by the credential are not enabled.
  356. Enable them in the Auth section of the Firebase console.
  357. + `FIRAuthErrorCodeAccountExistsWithDifferentCredential` - Indicates the email asserted
  358. by the credential (e.g. the email in a Facebook access token) is already in use by an
  359. existing account, that cannot be authenticated with this sign-in method. Call
  360. fetchProvidersForEmail for this users email and then prompt them to sign in with any of
  361. the sign-in providers returned. This error will only be thrown if the "One account per
  362. email address" setting is enabled in the Firebase console, under Auth settings.
  363. + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  364. + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted sign in with an
  365. incorrect password, if credential is of the type EmailPasswordAuthCredential.
  366. + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  367. + `FIRAuthErrorCodeMissingVerificationID` - Indicates that the phone auth credential was
  368. created with an empty verification ID.
  369. + `FIRAuthErrorCodeMissingVerificationCode` - Indicates that the phone auth credential
  370. was created with an empty verification code.
  371. + `FIRAuthErrorCodeInvalidVerificationCode` - Indicates that the phone auth credential
  372. was created with an invalid verification Code.
  373. + `FIRAuthErrorCodeInvalidVerificationID` - Indicates that the phone auth credential was
  374. created with an invalid verification ID.
  375. + `FIRAuthErrorCodeSessionExpired` - Indicates that the SMS code has expired.
  376. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods
  377. */
  378. - (void)signInWithCredential:(FIRAuthCredential *)credential
  379. completion:(nullable FIRAuthResultCallback)completion DEPRECATED_MSG_ATTRIBUTE(
  380. "Please use signInAndRetrieveDataWithCredential:completion:"
  381. " for Objective-C or signInAndRetrieveData(with:completion:)"
  382. " for Swift instead.");
  383. /** @fn signInAndRetrieveDataWithCredential:completion:
  384. @brief Asynchronously signs in to Firebase with the given 3rd-party credentials (e.g. a Facebook
  385. login Access Token, a Google ID Token/Access Token pair, etc.) and returns additional
  386. identity provider data.
  387. @param credential The credential supplied by the IdP.
  388. @param completion Optionally; a block which is invoked when the sign in flow finishes, or is
  389. canceled. Invoked asynchronously on the main thread in the future.
  390. @remarks Possible error codes:
  391. + `FIRAuthErrorCodeInvalidCredential` - Indicates the supplied credential is invalid.
  392. This could happen if it has expired or it is malformed.
  393. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that accounts
  394. with the identity provider represented by the credential are not enabled.
  395. Enable them in the Auth section of the Firebase console.
  396. + `FIRAuthErrorCodeAccountExistsWithDifferentCredential` - Indicates the email asserted
  397. by the credential (e.g. the email in a Facebook access token) is already in use by an
  398. existing account, that cannot be authenticated with this sign-in method. Call
  399. fetchProvidersForEmail for this users email and then prompt them to sign in with any of
  400. the sign-in providers returned. This error will only be thrown if the "One account per
  401. email address" setting is enabled in the Firebase console, under Auth settings.
  402. + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  403. + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted sign in with an
  404. incorrect password, if credential is of the type EmailPasswordAuthCredential.
  405. + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  406. + `FIRAuthErrorCodeMissingVerificationID` - Indicates that the phone auth credential was
  407. created with an empty verification ID.
  408. + `FIRAuthErrorCodeMissingVerificationCode` - Indicates that the phone auth credential
  409. was created with an empty verification code.
  410. + `FIRAuthErrorCodeInvalidVerificationCode` - Indicates that the phone auth credential
  411. was created with an invalid verification Code.
  412. + `FIRAuthErrorCodeInvalidVerificationID` - Indicates that the phone auth credential was
  413. created with an invalid verification ID.
  414. + `FIRAuthErrorCodeSessionExpired` - Indicates that the SMS code has expired.
  415. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods
  416. */
  417. - (void)signInAndRetrieveDataWithCredential:(FIRAuthCredential *)credential
  418. completion:(nullable FIRAuthDataResultCallback)completion;
  419. /** @fn signInAnonymouslyWithCompletion:
  420. @brief Asynchronously creates and becomes an anonymous user.
  421. @param completion Optionally; a block which is invoked when the sign in finishes, or is
  422. canceled. Invoked asynchronously on the main thread in the future.
  423. @remarks If there is already an anonymous user signed in, that user will be returned instead.
  424. If there is any other existing user signed in, that user will be signed out.
  425. @remarks Possible error codes:
  426. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that anonymous accounts are
  427. not enabled. Enable them in the Auth section of the Firebase console.
  428. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  429. */
  430. - (void)signInAnonymouslyWithCompletion:(nullable FIRAuthDataResultCallback)completion;
  431. /** @fn signInAnonymouslyAndRetrieveDataWithCompletion:
  432. @brief `Please use sign `signInAnonymouslyWithCompletion:` for Objective-C or
  433. `signInAnonymously(Completion:)` for Swift instead.
  434. @param completion Optionally; a block which is invoked when the sign in finishes, or is
  435. canceled. Invoked asynchronously on the main thread in the future.
  436. @remarks If there is already an anonymous user signed in, that user will be returned instead.
  437. If there is any other existing user signed in, that user will be signed out.
  438. @remarks Possible error codes:
  439. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that anonymous accounts are
  440. not enabled. Enable them in the Auth section of the Firebase console.
  441. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  442. @remarks This method will only exist until the next major Firebase release following 4.x.x.
  443. After the next major release the method `signInAnonymouslyWithCompletion` will support the
  444. `FIRAuthDataResultCallback`.
  445. */
  446. - (void)signInAnonymouslyAndRetrieveDataWithCompletion:
  447. (nullable FIRAuthDataResultCallback)completion
  448. DEPRECATED_MSG_ATTRIBUTE("Please use signInAnonymouslyWithCompletion: for Objective-C or"
  449. " signInAnonymously(Completion:) for swift instead.");
  450. /** @fn signInWithCustomToken:completion:
  451. @brief Asynchronously signs in to Firebase with the given Auth token.
  452. @param token A self-signed custom auth token.
  453. @param completion Optionally; a block which is invoked when the sign in finishes, or is
  454. canceled. Invoked asynchronously on the main thread in the future.
  455. @remarks Possible error codes:
  456. + `FIRAuthErrorCodeInvalidCustomToken` - Indicates a validation error with
  457. the custom token.
  458. + `FIRAuthErrorCodeCustomTokenMismatch` - Indicates the service account and the API key
  459. belong to different projects.
  460. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  461. */
  462. - (void)signInWithCustomToken:(NSString *)token
  463. completion:(nullable FIRAuthDataResultCallback)completion;
  464. /** @fn signInAndRetrieveDataWithCustomToken:completion:
  465. @brief Please use `signInWithCustomToken:completion:` or `signIn(withCustomToken:completion:)`
  466. for Swift instead.
  467. @param token A self-signed custom auth token.
  468. @param completion Optionally; a block which is invoked when the sign in finishes, or is
  469. canceled. Invoked asynchronously on the main thread in the future.
  470. @remarks Possible error codes:
  471. + `FIRAuthErrorCodeInvalidCustomToken` - Indicates a validation error with
  472. the custom token.
  473. + `FIRAuthErrorCodeCustomTokenMismatch` - Indicates the service account and the API key
  474. belong to different projects.
  475. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  476. @remarks This method will only exist until the next major Firebase release following 4.x.x.
  477. After the next major release the method `createUserWithEmail:password:completion:` will
  478. support the `FIRAuthDataResultCallback`.
  479. */
  480. - (void)signInAndRetrieveDataWithCustomToken:(NSString *)token
  481. completion:(nullable FIRAuthDataResultCallback)completion
  482. DEPRECATED_MSG_ATTRIBUTE(
  483. "Please use signInWithCustomToken:completion:"
  484. "for Objective-C or signIn(withCustomToken:completion:) for"
  485. " Swift instead.");
  486. /** @fn createUserWithEmail:password:completion:
  487. @brief Creates and, on success, signs in a user with the given email address and password.
  488. @param email The user's email address.
  489. @param password The user's desired password.
  490. @param completion Optionally; a block which is invoked when the sign up flow finishes, or is
  491. canceled. Invoked asynchronously on the main thread in the future.
  492. @remarks Possible error codes:
  493. + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  494. + `FIRAuthErrorCodeEmailAlreadyInUse` - Indicates the email used to attempt sign up
  495. already exists. Call fetchProvidersForEmail to check which sign-in mechanisms the user
  496. used, and prompt the user to sign in with one of those.
  497. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and password accounts
  498. are not enabled. Enable them in the Auth section of the Firebase console.
  499. + `FIRAuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is
  500. considered too weak. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo
  501. dictionary object will contain more detailed explanation that can be shown to the user.
  502. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  503. */
  504. - (void)createUserWithEmail:(NSString *)email
  505. password:(NSString *)password
  506. completion:(nullable FIRAuthDataResultCallback)completion;
  507. /** @fn createUserAndRetrieveDataWithEmail:password:completion:
  508. @brief Please use `createUserAndRetrieveDataWithEmail:password:completion:` or
  509. `createUser(withEmail:password:completion:)` for Swift instead.
  510. @param email The user's email address.
  511. @param password The user's desired password.
  512. @param completion Optionally; a block which is invoked when the sign up flow finishes, or is
  513. canceled. Invoked asynchronously on the main thread in the future.
  514. @remarks Possible error codes:
  515. + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  516. + `FIRAuthErrorCodeEmailAlreadyInUse` - Indicates the email used to attempt sign up
  517. already exists. Call fetchProvidersForEmail to check which sign-in mechanisms the user
  518. used, and prompt the user to sign in with one of those.
  519. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and password accounts
  520. are not enabled. Enable them in the Auth section of the Firebase console.
  521. + `FIRAuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is
  522. considered too weak. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo
  523. dictionary object will contain more detailed explanation that can be shown to the user.
  524. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  525. @remarks This method will only exist until the next major Firebase release following 4.x.x.
  526. After the next major release the method `createUserWithEmail:password:completion:` will
  527. support the `FIRAuthDataResultCallback`.
  528. */
  529. - (void)createUserAndRetrieveDataWithEmail:(NSString *)email
  530. password:(NSString *)password
  531. completion:(nullable FIRAuthDataResultCallback)completion
  532. DEPRECATED_MSG_ATTRIBUTE(
  533. "Please use createUserWithEmail:password:completion: for"
  534. " Objective-C or createUser(withEmail:password:completion:)"
  535. " for Swift instead.");
  536. /** @fn confirmPasswordResetWithCode:newPassword:completion:
  537. @brief Resets the password given a code sent to the user outside of the app and a new password
  538. for the user.
  539. @param newPassword The new password.
  540. @param completion Optionally; a block which is invoked when the request finishes. Invoked
  541. asynchronously on the main thread in the future.
  542. @remarks Possible error codes:
  543. + `FIRAuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is
  544. considered too weak.
  545. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates the administrator disabled sign
  546. in with the specified identity provider.
  547. + `FIRAuthErrorCodeExpiredActionCode` - Indicates the OOB code is expired.
  548. + `FIRAuthErrorCodeInvalidActionCode` - Indicates the OOB code is invalid.
  549. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods.
  550. */
  551. - (void)confirmPasswordResetWithCode:(NSString *)code
  552. newPassword:(NSString *)newPassword
  553. completion:(FIRConfirmPasswordResetCallback)completion;
  554. /** @fn checkActionCode:completion:
  555. @brief Checks the validity of an out of band code.
  556. @param code The out of band code to check validity.
  557. @param completion Optionally; a block which is invoked when the request finishes. Invoked
  558. asynchronously on the main thread in the future.
  559. */
  560. - (void)checkActionCode:(NSString *)code completion:(FIRCheckActionCodeCallBack)completion;
  561. /** @fn verifyPasswordResetCode:completion:
  562. @brief Checks the validity of a verify password reset code.
  563. @param code The password reset code to be verified.
  564. @param completion Optionally; a block which is invoked when the request finishes. Invoked
  565. asynchronously on the main thread in the future.
  566. */
  567. - (void)verifyPasswordResetCode:(NSString *)code
  568. completion:(FIRVerifyPasswordResetCodeCallback)completion;
  569. /** @fn applyActionCode:completion:
  570. @brief Applies out of band code.
  571. @param code The out of band code to be applied.
  572. @param completion Optionally; a block which is invoked when the request finishes. Invoked
  573. asynchronously on the main thread in the future.
  574. @remarks This method will not work for out of band codes which require an additional parameter,
  575. such as password reset code.
  576. */
  577. - (void)applyActionCode:(NSString *)code
  578. completion:(FIRApplyActionCodeCallback)completion;
  579. /** @fn sendPasswordResetWithEmail:completion:
  580. @brief Initiates a password reset for the given email address.
  581. @param email The email address of the user.
  582. @param completion Optionally; a block which is invoked when the request finishes. Invoked
  583. asynchronously on the main thread in the future.
  584. @remarks Possible error codes:
  585. + `FIRAuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was
  586. sent in the request.
  587. + `FIRAuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in
  588. the console for this action.
  589. + `FIRAuthErrorCodeInvalidMessagePayload` - Indicates an invalid email template for
  590. sending update email.
  591. */
  592. - (void)sendPasswordResetWithEmail:(NSString *)email
  593. completion:(nullable FIRSendPasswordResetCallback)completion;
  594. /** @fn sendPasswordResetWithEmail:actionCodeSetting:completion:
  595. @brief Initiates a password reset for the given email address and @FIRActionCodeSettings object.
  596. @param email The email address of the user.
  597. @param actionCodeSettings An `FIRActionCodeSettings` object containing settings related to
  598. handling action codes.
  599. @param completion Optionally; a block which is invoked when the request finishes. Invoked
  600. asynchronously on the main thread in the future.
  601. @remarks Possible error codes:
  602. + `FIRAuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was
  603. sent in the request.
  604. + `FIRAuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in
  605. the console for this action.
  606. + `FIRAuthErrorCodeInvalidMessagePayload` - Indicates an invalid email template for
  607. sending update email.
  608. + `FIRAuthErrorCodeMissingIosBundleID` - Indicates that the iOS bundle ID is missing when
  609. `handleCodeInApp` is set to YES.
  610. + `FIRAuthErrorCodeMissingAndroidPackageName` - Indicates that the android package name
  611. is missing when the `androidInstallApp` flag is set to true.
  612. + `FIRAuthErrorCodeUnauthorizedDomain` - Indicates that the domain specified in the
  613. continue URL is not whitelisted in the Firebase console.
  614. + `FIRAuthErrorCodeInvalidContinueURI` - Indicates that the domain specified in the
  615. continue URI is not valid.
  616. */
  617. - (void)sendPasswordResetWithEmail:(NSString *)email
  618. actionCodeSettings:(FIRActionCodeSettings *)actionCodeSettings
  619. completion:(nullable FIRSendPasswordResetCallback)completion;
  620. /** @fn sendSignInLinkToEmail:actionCodeSettings:completion:
  621. @brief Sends a sign in with email link to provided email address.
  622. @param email The email address of the user.
  623. @param actionCodeSettings An `FIRActionCodeSettings` object containing settings related to
  624. handling action codes.
  625. @param completion Optionally; a block which is invoked when the request finishes. Invoked
  626. asynchronously on the main thread in the future.
  627. */
  628. - (void)sendSignInLinkToEmail:(NSString *)email
  629. actionCodeSettings:(FIRActionCodeSettings *)actionCodeSettings
  630. completion:(nullable FIRSendSignInLinkToEmailCallback)completion;
  631. /** @fn signOut:
  632. @brief Signs out the current user.
  633. @param error Optionally; if an error occurs, upon return contains an NSError object that
  634. describes the problem; is nil otherwise.
  635. @return @YES when the sign out request was successful. @NO otherwise.
  636. @remarks Possible error codes:
  637. + `FIRAuthErrorCodeKeychainError` - Indicates an error occurred when accessing the
  638. keychain. The `NSLocalizedFailureReasonErrorKey` field in the `NSError.userInfo`
  639. dictionary will contain more information about the error encountered.
  640. */
  641. - (BOOL)signOut:(NSError *_Nullable *_Nullable)error;
  642. /** @fn isSignInWithEmailLink
  643. @brief Checks if link is an email sign-in link.
  644. @param link The email sign-in link.
  645. @return @YES when the link passed matches the expected format of an email sign-in link.
  646. */
  647. - (BOOL)isSignInWithEmailLink:(NSString *)link;
  648. /** @fn addAuthStateDidChangeListener:
  649. @brief Registers a block as an "auth state did change" listener. To be invoked when:
  650. + The block is registered as a listener,
  651. + A user with a different UID from the current user has signed in, or
  652. + The current user has signed out.
  653. @param listener The block to be invoked. The block is always invoked asynchronously on the main
  654. thread, even for it's initial invocation after having been added as a listener.
  655. @remarks The block is invoked immediately after adding it according to it's standard invocation
  656. semantics, asynchronously on the main thread. Users should pay special attention to
  657. making sure the block does not inadvertently retain objects which should not be retained by
  658. the long-lived block. The block itself will be retained by `FIRAuth` until it is
  659. unregistered or until the `FIRAuth` instance is otherwise deallocated.
  660. @return A handle useful for manually unregistering the block as a listener.
  661. */
  662. - (FIRAuthStateDidChangeListenerHandle)addAuthStateDidChangeListener:
  663. (FIRAuthStateDidChangeListenerBlock)listener;
  664. /** @fn removeAuthStateDidChangeListener:
  665. @brief Unregisters a block as an "auth state did change" listener.
  666. @param listenerHandle The handle for the listener.
  667. */
  668. - (void)removeAuthStateDidChangeListener:(FIRAuthStateDidChangeListenerHandle)listenerHandle;
  669. /** @fn addIDTokenDidChangeListener:
  670. @brief Registers a block as an "ID token did change" listener. To be invoked when:
  671. + The block is registered as a listener,
  672. + A user with a different UID from the current user has signed in,
  673. + The ID token of the current user has been refreshed, or
  674. + The current user has signed out.
  675. @param listener The block to be invoked. The block is always invoked asynchronously on the main
  676. thread, even for it's initial invocation after having been added as a listener.
  677. @remarks The block is invoked immediately after adding it according to it's standard invocation
  678. semantics, asynchronously on the main thread. Users should pay special attention to
  679. making sure the block does not inadvertently retain objects which should not be retained by
  680. the long-lived block. The block itself will be retained by `FIRAuth` until it is
  681. unregistered or until the `FIRAuth` instance is otherwise deallocated.
  682. @return A handle useful for manually unregistering the block as a listener.
  683. */
  684. - (FIRIDTokenDidChangeListenerHandle)addIDTokenDidChangeListener:
  685. (FIRIDTokenDidChangeListenerBlock)listener;
  686. /** @fn removeIDTokenDidChangeListener:
  687. @brief Unregisters a block as an "ID token did change" listener.
  688. @param listenerHandle The handle for the listener.
  689. */
  690. - (void)removeIDTokenDidChangeListener:(FIRIDTokenDidChangeListenerHandle)listenerHandle;
  691. /** @fn useAppLanguage
  692. @brief Sets `languageCode` to the app's current language.
  693. */
  694. - (void)useAppLanguage;
  695. #if TARGET_OS_IOS
  696. /** @fn canHandleURL:
  697. @brief Whether the specific URL is handled by `FIRAuth` .
  698. @param URL The URL received by the application delegate from any of the openURL method.
  699. @return Whether or the URL is handled. YES means the URL is for Firebase Auth
  700. so the caller should ignore the URL from further processing, and NO means the
  701. the URL is for the app (or another libaray) so the caller should continue handling
  702. this URL as usual.
  703. @remarks If swizzling is disabled, URLs received by the application delegate must be forwarded
  704. to this method for phone number auth to work.
  705. */
  706. - (BOOL)canHandleURL:(nonnull NSURL *)URL;
  707. /** @fn setAPNSToken:type:
  708. @brief Sets the APNs token along with its type.
  709. @remarks If swizzling is disabled, the APNs Token must be set for phone number auth to work,
  710. by either setting calling this method or by setting the `APNSToken` property.
  711. */
  712. - (void)setAPNSToken:(NSData *)token type:(FIRAuthAPNSTokenType)type;
  713. /** @fn canHandleNotification:
  714. @brief Whether the specific remote notification is handled by `FIRAuth` .
  715. @param userInfo A dictionary that contains information related to the
  716. notification in question.
  717. @return Whether or the notification is handled. YES means the notification is for Firebase Auth
  718. so the caller should ignore the notification from further processing, and NO means the
  719. the notification is for the app (or another libaray) so the caller should continue handling
  720. this notification as usual.
  721. @remarks If swizzling is disabled, related remote notifications must be forwarded to this method
  722. for phone number auth to work.
  723. */
  724. - (BOOL)canHandleNotification:(NSDictionary *)userInfo;
  725. #endif // TARGET_OS_IOS
  726. @end
  727. NS_ASSUME_NONNULL_END