No Description

FIRAuth.h 36KB

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