暂无描述

FIRAuth.h 42KB

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