FIRAuth.h 39 KB

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