FirebaseAuth

public abstract classFirebaseAuth


The entry point of the Firebase Authentication SDK.

First, obtain an instance of this class by callinggetInstance.

Then, sign up or sign in a user with one of the following methods:

Finally, callgetCurrentUser to get aFirebaseUser object, which contains information about the signed-in user.

Summary

Nested types

Listener called when there is a change in the authentication state.

Listener called when the id token is changed.

Public methods

void

Registers a listener to changes in the user authentication state.

void

Registers a listener to changes in the token authentication state.

@NonNullTask<Void>

Applies the givencode, which can be any out of band code which is valid according tocheckActionCode that does not also passverifyPasswordResetCode, which requires an additional parameter.

@NonNullTask<ActionCodeResult>

Checks that thecode given is valid.

@NonNullTask<Void>

Changes the user's password tonewPassword for the account for which thecode is valid.

@NonNullTask<AuthResult>
createUserWithEmailAndPassword(
    @NonNullString email,
    @NonNullString password
)

Tries to create a new user account with the given email address and password.

@NonNullTask<SignInMethodQueryResult>

This method is deprecated.

Migrating off of this method is recommended as a security best-practice.

@NonNullFirebaseApp

Returns theFirebaseApp instance to which thisFirebaseAuth belongs.

@NullableFirebaseUser

Returns the currently signed-inFirebaseUser or null if there is none.

@NullableString

Returns the custom auth domain previously set on this instance ornull if none was set.

@NonNullFirebaseAuthSettings

Returns theFirebaseAuthSettings instance for thisFirebaseAuth instance.

static @NonNullFirebaseAuth

Returns an instance of this class corresponding to the defaultFirebaseApp instance.

static @NonNullFirebaseAuth

Returns an instance of this class corresponding to the givenFirebaseApp instance.

@NullableString

Returns the language code set insetLanguageCode.

@NullableTask<AuthResult>

Returns aTask wrapping anAuthResult.

@NullableString

Returns the Tenant ID previously set on this instance ornull if none was set.

@NonNullTask<Void>

Initializes the reCAPTCHA Enterprise client proactively to enhance reCAPTCHA signal collection and to complete reCAPTCHA-protected flows in a single attempt.

boolean

Determines if the given link is a link intended for use withgetCredentialWithLink.

void

Unregisters a listener to authentication changes.

void

Unregisters a listener to authentication changes.

@NonNullTask<Void>

Revokes the providedaccessToken.

@NonNullTask<Void>

CallssendPasswordResetEmail without any ActionCodeSettings.

@NonNullTask<Void>
sendPasswordResetEmail(
    @NonNullString email,
    @NullableActionCodeSettings actionCodeSettings
)

Triggers the Firebase Authentication backend to send a password-reset email to the given email address, which must correspond to an existing user of your app.

@NonNullTask<Void>
sendSignInLinkToEmail(
    @NonNullString email,
    @NonNullActionCodeSettings actionCodeSettings
)

Sends an email to the specified email which will contain a link to be used to sign in the user.

void

Sets the custom auth domain that is used to handle all sign-in redirects.

@NonNullTask<Void>

For internal use in FirebaseUI only.

void

Sets the user-facing language code for auth operations that can be internationalized, such assendEmailVerification.

void

Sets the Tenant ID to be passed on all future sign-in/sign-up operations and sign in or sign up users to the specified project as identified by the tenant.

@NonNullTask<AuthResult>

Signs in the user anonymously without requiring any credential.

@NonNullTask<AuthResult>

Tries to sign in a user with the givenAuthCredential.

@NonNullTask<AuthResult>

Tries to sign in a user with a given Custom Token.

@NonNullTask<AuthResult>

Tries to sign in a user with the given email address and password.

@NonNullTask<AuthResult>

Tries to sign in a user with the given email address and link.

void

Signs out the current user and clears it from the disk cache.

@NonNullTask<AuthResult>
startActivityForSignInWithProvider(
    @NonNullActivity activity,
    @NonNullFederatedAuthProvider federatedAuthProvider
)

Signs in the user using the mobile browser (either a Custom Chrome Tab or the device's default browser) for the givenprovider.

@NonNullTask<Void>

Sets the current user to a copy of the given user, but associated with this 'sFirebaseApp.

void

Sets the user-facing language code to be the default app language.

void
useEmulator(@NonNullString host, int port)

Modifies this FirebaseAuth instance to communicate with the Firebase Authentication emulator.

@NonNullTask<String>

Checks that thecode is a valid password reset out of band code.

Public fields

currentUser

public @NullableFirebaseUser currentUser

customAuthDomain

public String customAuthDomain

languageCode

public String languageCode

tenantId

public String tenantId

Public methods

addAuthStateListener

public void addAuthStateListener(@NonNullFirebaseAuth.AuthStateListener listener)

Registers a listener to changes in the user authentication state. There can be more than one listener registered at the same time for one or moreFirebaseAuth instances.

The listeners call back in the UI thread, on the following events:

  • Right after the listener has been registered
  • When a user signs in
  • When the current user signs out
  • When the current user changes

It is a recommended practice to always listen to sign-out events, as you may want to prompt the user to sign in again and maybe restrict the information or actions they have access to.

UseremoveAuthStateListener to unregister a listener.

SeeaddIdTokenListener if you want to listen to token refreshes.

See Also:AuthStateListener

addIdTokenListener

public void addIdTokenListener(@NonNullFirebaseAuth.IdTokenListener listener)

Registers a listener to changes in the token authentication state. There can be more than one listener registered at the same time for one or moreFirebaseAuth instances.

The listeners call back in the UI thread, on the following events:

  • Right after the listener has been registered
  • When a user signs in
  • When the current user signs out
  • When the current user changes
  • When there is a change in the current user's token

It is a recommended practice to always listen to sign-out events, as you may want to prompt the user to sign in again and maybe restrict the information or actions they have access to.

UseremoveIdTokenListener to unregister a listener.

SeeaddAuthStateListener if you do not want to listen to token refreshes.

See Also:IdTokenListener

applyActionCode

public @NonNullTask<VoidapplyActionCode(@NonNullString code)

Applies the givencode, which can be any out of band code which is valid according tocheckActionCode that does not also passverifyPasswordResetCode, which requires an additional parameter.

checkActionCode

public @NonNullTask<ActionCodeResultcheckActionCode(@NonNullString code)

Checks that thecode given is valid. This code will have been generated bysendPasswordResetEmail orsendEmailVerification valid for a single use.

Returns
@NonNullTask<ActionCodeResult>

Task which you can use to see the result via theActionCodeResult, which holds the user email for which that ActionCode is valid, as well as the which is being performed.

confirmPasswordReset

public @NonNullTask<VoidconfirmPasswordReset(@NonNullString code, @NonNullString newPassword)

Changes the user's password tonewPassword for the account for which thecode is valid. Code validity can be checked withverifyPasswordResetCode. This use case is only valid for signed-out users, and behavior is undefined for signed-in users. Password changes for signed-in users should be made usingupdatePassword.

Exceptions

See Also:

createUserWithEmailAndPassword

public @NonNullTask<AuthResultcreateUserWithEmailAndPassword(
    @NonNullString email,
    @NonNullString password
)

Tries to create a new user account with the given email address and password. If successful, it also signs the user in into the app.

Access the signed-in user withgetCurrentUser.

Upon successful completion, this operation triggers anonIdTokenChanged event in all registered s and anonAuthStateChanged event in all registeredAuthStateListeners.

Important: you must enable Email &Password accounts in the Firebase console before you can use this method.

Exceptions

See Also:

Returns
@NonNullTask<AuthResult>

Task ofAuthResult with the result of the operation

fetchSignInMethodsForEmail

public @NonNullTask<SignInMethodQueryResultfetchSignInMethodsForEmail(@NonNullString email)
This method is deprecated.

Migrating off of this method is recommended as a security best-practice. Learn more in the Identity Platform documentation forEmail Enumeration Protection.

Returns a list of signin methods that can be used to sign in a given user (identified by its main email address). This will match thegetSignInMethod for the credential you would generate for the appropriate signin mechanism.

This method is useful when you support multiple authentication mechanisms if you want to implement an email-first authentication flow. It is also useful to resolve a thrown onsignInWithCredential.

Exceptions
Parameters
@NonNullString email

the email address that identifies the user to fetch the providers from

Returns
@NonNullTask<SignInMethodQueryResult>

Task ofSignInMethodQueryResult with the result of the operation. An empty list is returned whenEmail Enumeration Protection is enabled, irrespective of the number of authentication methods available for the given email.

getApp

public @NonNullFirebaseApp getApp()

Returns theFirebaseApp instance to which thisFirebaseAuth belongs.

getCurrentUser

public @NullableFirebaseUser getCurrentUser()

Returns the currently signed-inFirebaseUser or null if there is none.

UsegetCurrentUser() != null to check if a user is signed in.

Returns
@NullableFirebaseUser

the signed-in user or null

getCustomAuthDomain

public @NullableString getCustomAuthDomain()

Returns the custom auth domain previously set on this instance ornull if none was set.

getFirebaseAuthSettings

public @NonNullFirebaseAuthSettings getFirebaseAuthSettings()

Returns theFirebaseAuthSettings instance for thisFirebaseAuth instance.

getInstance

@Keep
public static @NonNullFirebaseAuth getInstance()

Returns an instance of this class corresponding to the defaultFirebaseApp instance.

Note: Firebase Authentication does not currently support Android Direct Boot.

For Applications that use Direct Boot, check if android.content.Context.isDeviceProtectedStorage isfalse before you callFirebaseAuth.getInstance().

getInstance

@Keep
public static @NonNullFirebaseAuth getInstance(@NonNullFirebaseApp firebaseApp)

Returns an instance of this class corresponding to the givenFirebaseApp instance.

Note: Firebase Authentication does not currently support Android Direct Boot.

For Applications that use Direct Boot, check if android.content.Context.isDeviceProtectedStorage isfalse before you callFirebaseAuth.getInstance(firebaseApp).

getLanguageCode

public @NullableString getLanguageCode()

Returns the language code set insetLanguageCode.

getPendingAuthResult

public @NullableTask<AuthResultgetPendingAuthResult()

Returns aTask wrapping anAuthResult. This will return a non-null value if your app launches a web sign-in flow and the OS cleans up your hostingActivity while in the background (likely due to a low-memory event). The returned result is the value thatstartActivityForSignInWithProvider would have returned, which includes any Exceptions thrown. Otherwise, returns null.

This method will only return a non-null result for a sign-in once. A non-null value will only be present for suitably recent sign-ins to help prevent false positive sign-ins.

getTenantId

public @NullableString getTenantId()

Returns the Tenant ID previously set on this instance ornull if none was set.

initializeRecaptchaConfig

public @NonNullTask<VoidinitializeRecaptchaConfig()

Initializes the reCAPTCHA Enterprise client proactively to enhance reCAPTCHA signal collection and to complete reCAPTCHA-protected flows in a single attempt.

Exceptions
  • FirebaseAuthException thrown on initialization failures. Common reasons are:
    • running on an unsupported API version (< 19, KITKAT).
    • the reCAPTCHA config fetch API call failed.
    • network errors causing other API call/download failures.
Returns
@NonNullTask<Void>

Task indicating if initialization was successful.

isSignInWithEmailLink

public boolean isSignInWithEmailLink(@NonNullString link)

Determines if the given link is a link intended for use withgetCredentialWithLink. These links are generated bysendSignInLinkToEmail.

removeAuthStateListener

public void removeAuthStateListener(
    @NonNullFirebaseAuth.AuthStateListener listener
)

Unregisters a listener to authentication changes.

See Also:AuthStateListener

removeIdTokenListener

public void removeIdTokenListener(@NonNullFirebaseAuth.IdTokenListener listener)

Unregisters a listener to authentication changes.

See Also:IdTokenListener

revokeAccessToken

public @NonNullTask<VoidrevokeAccessToken(@NonNullString accessToken)

Revokes the providedaccessToken. Currently supports revoking Apple-issuedaccessToken only.

sendPasswordResetEmail

public @NonNullTask<VoidsendPasswordResetEmail(@NonNullString email)

CallssendPasswordResetEmail without any ActionCodeSettings.

sendPasswordResetEmail

public @NonNullTask<VoidsendPasswordResetEmail(
    @NonNullString email,
    @NullableActionCodeSettings actionCodeSettings
)

Triggers the Firebase Authentication backend to send a password-reset email to the given email address, which must correspond to an existing user of your app. Takes in an which allows linking back to your app from the sent email.

Exceptions
Parameters
@NonNullString email

the email of the account to which you wish to issue an account reset email

@NullableActionCodeSettings actionCodeSettings

the settings used to allow your app to handle the link sent in the email on iOS, web, and Android.

Returns
@NonNullTask<Void>

Task to track completion of the sending operation

sendSignInLinkToEmail

public @NonNullTask<VoidsendSignInLinkToEmail(
    @NonNullString email,
    @NonNullActionCodeSettings actionCodeSettings
)

Sends an email to the specified email which will contain a link to be used to sign in the user.

Throws
java.lang.IllegalArgumentException

when given anActionCodeSettings that does not havecanHandleCodeInApp set to true.

See alsogetCredentialWithLink

setCustomAuthDomain

public void setCustomAuthDomain(@NonNullString domain)

Sets the custom auth domain that is used to handle all sign-in redirects. End-users will see this domain when signing in.

The domain must be allowlisted in the Firebase Console. If the domain contains a scheme (https:// orhttp://) or trailing slashes, they will be stripped off.

setFirebaseUIVersion

public @NonNullTask<VoidsetFirebaseUIVersion(@NullableString firebaseUIVersion)

For internal use in FirebaseUI only.

setLanguageCode

public void setLanguageCode(@NonNullString languageCode)

Sets the user-facing language code for auth operations that can be internationalized, such assendEmailVerification. This language code should follow the conventions defined by the IETF in BCP47.

setTenantId

public void setTenantId(@NonNullString tenantId)

Sets the Tenant ID to be passed on all future sign-in/sign-up operations and sign in or sign up users to the specified project as identified by the tenant. If you change this field, future sign-in/sign-ups will contain the new value.

This is set to null as default and users are signed into the agent project.

Note: this is different from what the current user's Tenant ID is; you can change this instance's Tenant ID without affecting the current user.

signInAnonymously

public @NonNullTask<AuthResultsignInAnonymously()

Signs in the user anonymously without requiring any credential.

This method creates a new account in your Firebase Authentication system, except in the case where there was already an anonymous user signed in into this app. Access the signed-in user withgetCurrentUser.

Upon successful completion, this operation triggers anonIdTokenChanged event in all registered s and anonAuthStateChanged event in all registeredAuthStateListeners.

Anonymous users do not require any credential, and are useful in situations where you want to persist information about your users before asking them to sign in. For example, they may be useful when implementing a signed-out shopping cart in an e-commerce application.

Due to the unauthenticated nature of this kind of user, they are not transferrable across devices. In order to allow your app's users to keep their information, ask them to provide some other authentication credentials, and link them to the current user withlinkWithCredential.

Important: you must enable Anonymous accounts in the Firebase console before being able to use them.

Returns
@NonNullTask<AuthResult>

Task ofAuthResult with the result of the operation

signInWithCredential

public @NonNullTask<AuthResultsignInWithCredential(@NonNullAuthCredential credential)

Tries to sign in a user with the givenAuthCredential.

Use this method to sign in a user into your Firebase Authentication system. First retrieve thecredential either directly from the user, in case ofEmailAuthCredential, or from a supported authentication SDK, such as Google Sign-In or Facebook. Later access the signed-in user withgetCurrentUser.

For allAuthCredential types exceptEmailAuthCredential, this method will create an account for the user in the case that it didn't exist before.

Important: you must configure the authentication providers in the Firebase console before you can use them.

Exceptions

See Also:

Returns
@NonNullTask<AuthResult>

Task ofAuthResult with the result of the operation

signInWithCustomToken

public @NonNullTask<AuthResultsignInWithCustomToken(@NonNullString token)

Tries to sign in a user with a given Custom Token.

Use this method after you retrieve a Firebase Auth Custom Token from your server, to sign in a user into your Firebase Authentication system. Access the signed-in user withgetCurrentUser.

Upon successful completion, this operation triggers anonIdTokenChanged event in all registered s and anonAuthStateChanged event in all registeredAuthStateListeners.

This operation might create an account if theuid specified in the token corresponds to a user without a record in the system.

Read how to use Custom Token authentication and the cases where it is useful inthe guides.

Exceptions
Returns
@NonNullTask<AuthResult>

Task ofAuthResult with the result of the operation

signInWithEmailAndPassword

public @NonNullTask<AuthResultsignInWithEmailAndPassword(@NonNullString email, @NonNullString password)

Tries to sign in a user with the given email address and password.

Access the signed-in user withgetCurrentUser.

Upon successful completion, this operation triggers anonIdTokenChanged event in all registered s and anonAuthStateChanged event in all registeredAuthStateListeners.

This is equivalent to callingsignInWithCredential with an generated bygetCredential.

Important: you must enable Email &Password accounts in the Firebase console before being able to use this method.

Exceptions

See also:

Returns
@NonNullTask<AuthResult>

Task ofAuthResult with the result of the operation

signInWithEmailLink

public @NonNullTask<AuthResultsignInWithEmailLink(@NonNullString email, @NonNullString link)

Tries to sign in a user with the given email address and link. This link should be generated bysendSignInLinkToEmail.

Access the signed-in user withgetCurrentUser.

Upon successful completion, this operation triggers anonIdTokenChanged event in all registered s and anonAuthStateChanged event in all registeredAuthStateListeners.

This is equivalent to callingsignInWithCredential with an generated bygetCredentialWithLink.

Important: you must enable Passwordless sign-in in the Firebase console before being able to use this method.

Exceptions

See also:

Returns
@NonNullTask<AuthResult>

Task ofAuthResult with the result of the operation

signOut

public void signOut()

Signs out the current user and clears it from the disk cache.

Upon successful completion, this operation triggers anonIdTokenChanged event in all registered s and anonAuthStateChanged event in all registeredAuthStateListeners.

startActivityForSignInWithProvider

public @NonNullTask<AuthResultstartActivityForSignInWithProvider(
    @NonNullActivity activity,
    @NonNullFederatedAuthProvider federatedAuthProvider
)

Signs in the user using the mobile browser (either a Custom Chrome Tab or the device's default browser) for the givenprovider.

Note: this call has a UI associated with it, unlike the majority of calls in FirebaseAuth.

Exceptions
Parameters
@NonNullActivity activity

the currentActivity from which you intend to launch this flow.

@NonNullFederatedAuthProvider federatedAuthProvider

anFederatedAuthProvider configured with information about how you intend the user to sign in.

Returns
@NonNullTask<AuthResult>

aTask with a reference to anAuthResult with user information upon success

updateCurrentUser

public @NonNullTask<VoidupdateCurrentUser(@NonNullFirebaseUser user)

Sets the current user to a copy of the given user, but associated with this 'sFirebaseApp. If the given user isn't for this project, then a will be returned via the Task.

useAppLanguage

public void useAppLanguage()

Sets the user-facing language code to be the default app language.

useEmulator

public void useEmulator(@NonNullString host, int port)

Modifies this FirebaseAuth instance to communicate with the Firebase Authentication emulator.

Note: this must be called before this instance has been used to do any operations.

Parameters
@NonNullString host

the emulator host (e.g. 10.0.2.2)

int port

the emulator port (e.g. 8080)

verifyPasswordResetCode

public @NonNullTask<StringverifyPasswordResetCode(@NonNullString code)

Checks that thecode is a valid password reset out of band code. This code will have been generated by a call tosendPasswordResetEmail, and is valid for a single use.

Returns
@NonNullTask<String>

Task which holds the email for which this code is applicable.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.