FIRAuth


@interface FIRAuth : NSObject

Manages authentication for Firebase apps. This class is thread-safe.

  • Gets the auth object for the default Firebase app. The default Firebase app must have already been configured or an exception will be raised.

    Declaration

    Objective-C

    + (nonnull FIRAuth *)auth;
  • Gets the auth object for a FIRApp.

    Declaration

    Objective-C

    + (nonnull FIRAuth *)authWithApp:(nonnull FIRApp *)app;

    Parameters

    app

    The FIRApp for which to retrieve the associated FIRAuth instance.

    Return Value

    The FIRAuth instance associated with the given FIRApp.

  • app

    Gets the FIRApp object that this auth object is connected to.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) FIRApp *app;
  • Synchronously gets the cached current user, or null if there is none.

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic, nullable) FIRUser *currentUser;
  • The current user language code. This property can be set to the app’s current language by calling useAppLanguage.

    The string used to set this property must be a language code that follows BCP 47.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSString *languageCode;
  • Contains settings related to the auth object.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) FIRAuthSettings *settings;
  • The APNs token used for phone number authentication. The type of the token (production or sandbox) will be attempted to be automatcially detected. If swizzling is disabled, the APNs Token must be set for phone number auth to work, by either setting this property or by calling setAPNSToken:type:

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) NSData *APNSToken;
  • Please access auth instances using FIRAuth.auth and FIRAuth.authForApp:.

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Sets the currentUser on the calling Auth instance to the provided user object.

    Declaration

    Objective-C

    - (void)updateCurrentUser:(nonnull FIRUser *)user
                   completion:(nullable FIRUserUpdateCallback)completion;

    Parameters

    user

    The user object to be set as the current user of the calling Auth instance.

    completion

    Optionally; a block invoked after the user of the calling Auth instance has been updated or an error was encountered.

  • Fetches the list of IdPs that can be used for signing in with the provided email address. Useful for an identifier-first sign-in flow.

    Possible error codes:

    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Objective-C

    - (void)fetchProvidersForEmail:(nonnull NSString *)email
                        completion:(nullable FIRProviderQueryCallback)completion;

    Parameters

    email

    The email address for which to obtain a list of identity providers.

    completion

    Optionally; a block which is invoked when the list of providers for the specified email address is ready or an error was encountered. Invoked asynchronously on the main thread in the future.

  • Fetches the list of all sign-in methods previously used for the provided email address.

    Possible error codes:

    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Objective-C

    - (void)fetchSignInMethodsForEmail:(nonnull NSString *)email
                            completion:
                                (nullable FIRSignInMethodQueryCallback)completion;

    Parameters

    email

    The email address for which to obtain a list of sign-in methods.

    completion

    Optionally; a block which is invoked when the list of sign in methods for the specified email address is ready or an error was encountered. Invoked asynchronously on the main thread in the future.

  • Signs in using an email address and password.

    Possible error codes:

    + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and password
        accounts are not enabled. Enable them in the Auth section of the
        Firebase console.
    + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
    + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted
        sign in with an incorrect password.
    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Objective-C

    - (void)signInWithEmail:(nonnull NSString *)email
                   password:(nonnull NSString *)password
                 completion:(nullable FIRAuthDataResultCallback)completion;

    Parameters

    email

    The user’s email address.

    password

    The user’s password.

    completion

    Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Signs in using an email address and email sign-in link.

    Possible error codes:

    + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and email sign-in link
        accounts are not enabled. Enable them in the Auth section of the
        Firebase console.
    + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is invalid.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Objective-C

    - (void)signInWithEmail:(nonnull NSString *)email
                       link:(nonnull NSString *)link
                 completion:(nullable FIRAuthDataResultCallback)completion;

    Parameters

    email

    The user’s email address.

    link

    The email sign-in link.

    completion

    Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Please use signInWithEmail:password:completion: for Objective-C or signIn(withEmail:password:completion:) for Swift instead.

    Declaration

    Objective-C

    - (void)signInAndRetrieveDataWithEmail:(nonnull NSString *)email
                                  password:(nonnull NSString *)password
                                completion:
                                    (nullable FIRAuthDataResultCallback)completion;

    Parameters

    email

    The user’s email address.

    password

    The user’s password.

    completion

    Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Please use signInAndRetrieveDataWithCredential:completion: for Objective-C or signInAndRetrieveData(with:completion:) for swift instead

    Possible error codes:

    + `FIRAuthErrorCodeInvalidCredential` - Indicates the supplied credential is invalid.
        This could happen if it has expired or it is malformed.
    + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that accounts
        with the identity provider represented by the credential are not enabled.
        Enable them in the Auth section of the Firebase console.
    + `FIRAuthErrorCodeAccountExistsWithDifferentCredential` - Indicates the email asserted
        by the credential (e.g. the email in a Facebook access token) is already in use by an
        existing account, that cannot be authenticated with this sign-in method. Call
        fetchProvidersForEmail for this users email and then prompt them to sign in with any of
        the sign-in providers returned. This error will only be thrown if the "One account per
        email address" setting is enabled in the Firebase console, under Auth settings.
    + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
    + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted sign in with an
        incorrect password, if credential is of the type EmailPasswordAuthCredential.
    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
    + `FIRAuthErrorCodeMissingVerificationID` - Indicates that the phone auth credential was
        created with an empty verification ID.
    + `FIRAuthErrorCodeMissingVerificationCode` - Indicates that the phone auth credential
        was created with an empty verification code.
    + `FIRAuthErrorCodeInvalidVerificationCode` - Indicates that the phone auth credential
        was created with an invalid verification Code.
    + `FIRAuthErrorCodeInvalidVerificationID` - Indicates that the phone auth credential was
        created with an invalid verification ID.
    + `FIRAuthErrorCodeSessionExpired` - Indicates that the SMS code has expired.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods

    Declaration

    Objective-C

    - (void)signInWithCredential:(nonnull FIRAuthCredential *)credential
                      completion:(nullable FIRAuthResultCallback)completion;

    Parameters

    credential

    The credential supplied by the IdP.

    completion

    Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Signs in using the provided auth provider instance.

    Possible error codes:

    • FIRAuthErrorCodeOperationNotAllowed - Indicates that email and password accounts are not enabled. Enable them in the Auth section of the Firebase console.
    • FIRAuthErrorCodeUserDisabled - Indicates the user’s account is disabled.
    • FIRAuthErrorCodeWebNetworkRequestFailed - Indicates that a network request within a SFSafariViewController or UIWebview failed.
    • FIRAuthErrorCodeWebInternalError - Indicates that an internal error occurred within a SFSafariViewController or UIWebview.
    • FIRAuthErrorCodeWebSignInUserInteractionFailure - Indicates a general failure during a web sign-in flow.
    • FIRAuthErrorCodeWebContextAlreadyPresented - Indicates that an attempt was made to present a new web context while one was already being presented.
    • FIRAuthErrorCodeWebContextCancelled - Indicates that the URL presentation was cancelled prematurely by the user.
    • FIRAuthErrorCodeAccountExistsWithDifferentCredential - Indicates the email asserted by the credential (e.g. the email in a Facebook access token) is already in use by an existing account, that cannot be authenticated with this sign-in method. Call fetchProvidersForEmail for this user’s email and then prompt them to sign in with any of the sign-in providers returned. This error will only be thrown if the “One account per email address” setting is enabled in the Firebase console, under Auth settings.

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Objective-C

    - (void)signInWithProvider:(nonnull id<FIRFederatedAuthProvider>)provider
                    UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
                    completion:(nullable FIRAuthDataResultCallback)completion;

    Parameters

    provider

    An isntance of an auth provider used to initiate the sign-in flow.

    UIDelegate

    Optionally an instance of a class conforming to the FIRAuthUIDelegate protocol, this is used for presenting the web context. If nil, a default FIRAuthUIDelegate will be used.

    completion

    Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Asynchronously signs in to Firebase with the given 3rd-party credentials (e.g. a Facebook login Access Token, a Google ID Token/Access Token pair, etc.) and returns additional identity provider data.

    Possible error codes:

    + `FIRAuthErrorCodeInvalidCredential` - Indicates the supplied credential is invalid.
        This could happen if it has expired or it is malformed.
    + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that accounts
        with the identity provider represented by the credential are not enabled.
        Enable them in the Auth section of the Firebase console.
    + `FIRAuthErrorCodeAccountExistsWithDifferentCredential` - Indicates the email asserted
        by the credential (e.g. the email in a Facebook access token) is already in use by an
        existing account, that cannot be authenticated with this sign-in method. Call
        fetchProvidersForEmail for this users email and then prompt them to sign in with any of
        the sign-in providers returned. This error will only be thrown if the "One account per
        email address" setting is enabled in the Firebase console, under Auth settings.
    + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
    + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted sign in with an
        incorrect password, if credential is of the type EmailPasswordAuthCredential.
    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
    + `FIRAuthErrorCodeMissingVerificationID` - Indicates that the phone auth credential was
        created with an empty verification ID.
    + `FIRAuthErrorCodeMissingVerificationCode` - Indicates that the phone auth credential
        was created with an empty verification code.
    + `FIRAuthErrorCodeInvalidVerificationCode` - Indicates that the phone auth credential
        was created with an invalid verification Code.
    + `FIRAuthErrorCodeInvalidVerificationID` - Indicates that the phone auth credential was
        created with an invalid verification ID.
    + `FIRAuthErrorCodeSessionExpired` - Indicates that the SMS code has expired.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods

    Declaration

    Objective-C

    - (void)
    signInAndRetrieveDataWithCredential:(nonnull FIRAuthCredential *)credential
                             completion:
                                 (nullable FIRAuthDataResultCallback)completion;

    Parameters

    credential

    The credential supplied by the IdP.

    completion

    Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Asynchronously creates and becomes an anonymous user.

    If there is already an anonymous user signed in, that user will be returned instead. If there is any other existing user signed in, that user will be signed out.

    Possible error codes:

    + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that anonymous accounts are
        not enabled. Enable them in the Auth section of the Firebase console.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Objective-C

    - (void)signInAnonymouslyWithCompletion:
        (nullable FIRAuthDataResultCallback)completion;

    Parameters

    completion

    Optionally; a block which is invoked when the sign in finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Please use signsignInAnonymouslyWithCompletion:for Objective-C or signInAnonymously(Completion:)` for Swift instead.

    Declaration

    Objective-C

    - (void)signInAnonymouslyAndRetrieveDataWithCompletion:
        (nullable FIRAuthDataResultCallback)completion;

    Parameters

    completion

    Optionally; a block which is invoked when the sign in finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Asynchronously signs in to Firebase with the given Auth token.

    Possible error codes:

    + `FIRAuthErrorCodeInvalidCustomToken` - Indicates a validation error with
        the custom token.
    + `FIRAuthErrorCodeCustomTokenMismatch` - Indicates the service account and the API key
        belong to different projects.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Objective-C

    - (void)signInWithCustomToken:(nonnull NSString *)token
                       completion:(nullable FIRAuthDataResultCallback)completion;

    Parameters

    token

    A self-signed custom auth token.

    completion

    Optionally; a block which is invoked when the sign in finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Please use signInWithCustomToken:completion: or signIn(withCustomToken:completion:) for Swift instead.

    Declaration

    Objective-C

    - (void)signInAndRetrieveDataWithCustomToken:(nonnull NSString *)token
                                      completion:
                                          (nullable FIRAuthDataResultCallback)
                                              completion;

    Parameters

    token

    A self-signed custom auth token.

    completion

    Optionally; a block which is invoked when the sign in finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Creates and, on success, signs in a user with the given email address and password.

    Possible error codes:

    + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
    + `FIRAuthErrorCodeEmailAlreadyInUse` - Indicates the email used to attempt sign up
        already exists. Call fetchProvidersForEmail to check which sign-in mechanisms the user
        used, and prompt the user to sign in with one of those.
    + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that email and password accounts
        are not enabled. Enable them in the Auth section of the Firebase console.
    + `FIRAuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is
        considered too weak. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo
        dictionary object will contain more detailed explanation that can be shown to the user.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Objective-C

    - (void)createUserWithEmail:(nonnull NSString *)email
                       password:(nonnull NSString *)password
                     completion:(nullable FIRAuthDataResultCallback)completion;

    Parameters

    email

    The user’s email address.

    password

    The user’s desired password.

    completion

    Optionally; a block which is invoked when the sign up flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Please use createUserAndRetrieveDataWithEmail:password:completion: or createUser(withEmail:password:completion:) for Swift instead.

    Declaration

    Objective-C

    - (void)createUserAndRetrieveDataWithEmail:(nonnull NSString *)email
                                      password:(nonnull NSString *)password
                                    completion:(nullable FIRAuthDataResultCallback)
                                                   completion;

    Parameters

    email

    The user’s email address.

    password

    The user’s desired password.

    completion

    Optionally; a block which is invoked when the sign up flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

  • Resets the password given a code sent to the user outside of the app and a new password for the user.

    Possible error codes:

    + `FIRAuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is
        considered too weak.
    + `FIRAuthErrorCodeOperationNotAllowed` - Indicates the administrator disabled sign
        in with the specified identity provider.
    + `FIRAuthErrorCodeExpiredActionCode` - Indicates the OOB code is expired.
    + `FIRAuthErrorCodeInvalidActionCode` - Indicates the OOB code is invalid.
    

    See FIRAuthErrors for a list of error codes that are common to all API methods.

    Declaration

    Objective-C

    - (void)confirmPasswordResetWithCode:(nonnull NSString *)code
                             newPassword:(nonnull NSString *)newPassword
                              completion:(nonnull FIRConfirmPasswordResetCallback)
                                             completion;

    Parameters

    newPassword

    The new password.

    completion

    Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

  • Checks the validity of an out of band code.

    Declaration

    Objective-C

    - (void)checkActionCode:(nonnull NSString *)code
                 completion:(nonnull FIRCheckActionCodeCallBack)completion;

    Parameters

    code

    The out of band code to check validity.

    completion

    Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

  • Checks the validity of a verify password reset code.

    Declaration

    Objective-C

    - (void)verifyPasswordResetCode:(nonnull NSString *)code
                         completion:
                             (nonnull FIRVerifyPasswordResetCodeCallback)completion;

    Parameters

    code

    The password reset code to be verified.

    completion

    Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

  • Applies out of band code.

    This method will not work for out of band codes which require an additional parameter, such as password reset code.

    Declaration

    Objective-C

    - (void)applyActionCode:(nonnull NSString *)code
                 completion:(nonnull FIRApplyActionCodeCallback)completion;

    Parameters

    code

    The out of band code to be applied.

    completion

    Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

  • Initiates a password reset for the given email address.

    Possible error codes:

    + `FIRAuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was
        sent in the request.
    + `FIRAuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in
        the console for this action.
    + `FIRAuthErrorCodeInvalidMessagePayload` - Indicates an invalid email template for
        sending update email.
    

    Declaration

    Objective-C

    - (void)sendPasswordResetWithEmail:(nonnull NSString *)email
                            completion:
                                (nullable FIRSendPasswordResetCallback)completion;

    Parameters

    email

    The email address of the user.

    completion

    Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

  • Initiates a password reset for the given email address and @FIRActionCodeSettings object.

    Possible error codes:

    + `FIRAuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was
        sent in the request.
    + `FIRAuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in
        the console for this action.
    + `FIRAuthErrorCodeInvalidMessagePayload` - Indicates an invalid email template for
        sending update email.
    + `FIRAuthErrorCodeMissingIosBundleID` - Indicates that the iOS bundle ID is missing when
        `handleCodeInApp` is set to YES.
    + `FIRAuthErrorCodeMissingAndroidPackageName` - Indicates that the android package name
        is missing when the `androidInstallApp` flag is set to true.
    + `FIRAuthErrorCodeUnauthorizedDomain` - Indicates that the domain specified in the
        continue URL is not whitelisted in the Firebase console.
    + `FIRAuthErrorCodeInvalidContinueURI` - Indicates that the domain specified in the
        continue URI is not valid.
    

    Declaration

    Objective-C

    - (void)
    sendPasswordResetWithEmail:(nonnull NSString *)email
            actionCodeSettings:(nonnull FIRActionCodeSettings *)actionCodeSettings
                    completion:(nullable FIRSendPasswordResetCallback)completion;

    Parameters

    email

    The email address of the user.

    actionCodeSettings

    An FIRActionCodeSettings object containing settings related to handling action codes.

    completion

    Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

  • Sends a sign in with email link to provided email address.

    Declaration

    Objective-C

    - (void)
    sendSignInLinkToEmail:(nonnull NSString *)email
       actionCodeSettings:(nonnull FIRActionCodeSettings *)actionCodeSettings
               completion:(nullable FIRSendSignInLinkToEmailCallback)completion;

    Parameters

    email

    The email address of the user.

    actionCodeSettings

    An FIRActionCodeSettings object containing settings related to handling action codes.