MultiFactor

public abstract classMultiFactor


Defines multi-factor related properties and operations pertaining to aFirebaseUser. This class acts as the main entry point for enrolling or un-enrolling second factors for a user, and provides access to their currently enrolled factors.

Summary

Public constructors

Public methods

abstract @NonNullTask<Void>
enroll(
    @NonNullMultiFactorAssertion multiFactorAssertion,
    @NullableString displayName
)

Enrolls a second factor as identified by theMultiFactorAssertion parameter for the current user.

abstract @NonNullList<MultiFactorInfo>

Returns a list of theMultiFactorInfo already associated with this user.

abstract @NonNullTask<MultiFactorSession>

Returns a session identifier for a second factor enrollment operation.

abstract @NonNullTask<Void>
unenroll(@NonNullString factorUid)

Unenrolls a second factor from this user.

abstract @NonNullTask<Void>
unenroll(@NonNullMultiFactorInfo multiFactorInfo)

Unenrolls a second factor from this user.

Public constructors

MultiFactor

public MultiFactor()

Public methods

enroll

public abstract @NonNullTask<Voidenroll(
    @NonNullMultiFactorAssertion multiFactorAssertion,
    @NullableString displayName
)

Enrolls a second factor as identified by theMultiFactorAssertion parameter for the current user.

On successful enrollment, existing Firebase sessions are revoked, and an email notification is sent to the user’s email. The user's must have a verified email to enroll a second factor.

AMultiFactorAssertion can be generated usinggetAssertion for enrolling phone number as a second factor orgetAssertionForEnrollment for enrolling TOTP as a second factor.

Parameters
@NonNullMultiFactorAssertion multiFactorAssertion

the assertion representing the second factor to enroll

@NullableString displayName

an optional name for identifying this second factor

getEnrolledFactors

public abstract @NonNullList<MultiFactorInfogetEnrolledFactors()

Returns a list of theMultiFactorInfo already associated with this user.

If the user does not have any enrolled factors, the list will be empty.

getSession

public abstract @NonNullTask<MultiFactorSessiongetSession()

Returns a session identifier for a second factor enrollment operation. This is used to identify the current user trying to enroll a second factor.

To be used when building aPhoneAuthOptions instance to callverifyPhoneNumber for phone factor enrollment, or when generating aTotpSecret instance for TOTP factor enrollment.

unenroll

public abstract @NonNullTask<Voidunenroll(@NonNullString factorUid)

Unenrolls a second factor from this user.

ThefactorUid to be passed in can be retrieved fromgetEnrolledFactors.

unenroll

public abstract @NonNullTask<Voidunenroll(@NonNullMultiFactorInfo multiFactorInfo)

Unenrolls a second factor from this user.

TheMultiFactorInfo to be passed in can be gotten fromgetEnrolledFactors.

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.