PhoneAuthProvider

public classPhoneAuthProvider


Represents the phone number authentication mechanism. Use this class to obtain s.

Summary

Nested types

A 'token' that can be used to force re-sending an SMS verification code.

Registered callbacks for the different phone auth events.

Constants

static finalString

Unique string identifier for Phone sign-in method.

static finalString
PROVIDER_ID = "phone"

Unique string identifier for this provider type.

Public methods

static @NonNullPhoneAuthCredential
getCredential(@NonNullString verificationId, @NonNullString smsCode)

Returns a new instance ofAuthCredential that is associated with a phone number.

static @NonNullPhoneAuthProvider

This method is deprecated.

Instead, useverifyPhoneNumber

static @NonNullPhoneAuthProvider

This method is deprecated.

Instead, useverifyPhoneNumber

static void

Starts the phone verification process with the settings defined inPhoneAuthOptions.

void
verifyPhoneNumber(
    @NonNullString phoneNumber,
    long timeout,
    @NonNullTimeUnit unit,
    @NonNullActivity activity,
    @NonNullPhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks
)

This method is deprecated.

Instead, useverifyPhoneNumber

void
verifyPhoneNumber(
    @NonNullString phoneNumber,
    long timeout,
    @NonNullTimeUnit unit,
    @NonNullActivity activity,
    @NonNullPhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks,
    @NullablePhoneAuthProvider.ForceResendingToken forceResendingToken
)

This method is deprecated.

Instead, useverifyPhoneNumber

Constants

PHONE_SIGN_IN_METHOD

public static final String PHONE_SIGN_IN_METHOD = "phone"

Unique string identifier for Phone sign-in method.

PROVIDER_ID

public static final String PROVIDER_ID = "phone"

Unique string identifier for this provider type.

Public methods

getCredential

public static @NonNullPhoneAuthCredential getCredential(@NonNullString verificationId, @NonNullString smsCode)

Returns a new instance ofAuthCredential that is associated with a phone number. Used when callingsignInWithCredential orlinkWithCredential.

Parameters
@NonNullString verificationId

a validverificationId retrieved by callingverifyPhoneNumber

@NonNullString smsCode

the 6 digit SMS-code sent to the user

getInstance

public static @NonNullPhoneAuthProvider getInstance()
This method is deprecated.

Instead, useverifyPhoneNumber

Initializes a newPhoneAuthProvider using the default FirebaseAuth instance.

getInstance

public static @NonNullPhoneAuthProvider getInstance(@NonNullFirebaseAuth firebaseAuth)
This method is deprecated.

Instead, useverifyPhoneNumber

Static method to initialize a newPhoneAuthProvider for the specified Auth instance.

verifyPhoneNumber

public static void verifyPhoneNumber(@NonNullPhoneAuthOptions options)

Starts the phone verification process with the settings defined inPhoneAuthOptions.

verifyPhoneNumber

public void verifyPhoneNumber(
    @NonNullString phoneNumber,
    long timeout,
    @NonNullTimeUnit unit,
    @NonNullActivity activity,
    @NonNullPhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks
)
This method is deprecated.

Instead, useverifyPhoneNumber

Starts the phone number verification process for the given phone number. Either sends an SMS with a 6 digit code to the phone number specified or triggers the callback with a completeAuthCredential that can be used to log in the user.

The specified callback will be Activity-scoped, i.e. it will be automatically removed duringonStop. This function is reentrant and can be called again inonStart. No duplicated SMS will be sent out upon re-entry (before timeout).

Make sure to test all scenarios below:

  • You directly get back anAuthCredential if Google Play services verified the phone number instantly or helped you auto-retrieve the verification code.
  • auto-retrieve verification code timed out.
  • error cases when you receiveonVerificationFailed.
Parameters
@NonNullString phoneNumber

the phone number for the account the user is signing up for or signing into. Make sure to pass in a phone number with country code prefixed with plus sign ('+').

long timeout

the maximum amount of time you are willing to wait for SMS auto-retrieval to be completed by the library. Maximum allowed value is 2 minutes. Use 0 to disable SMS-auto-retrieval. Setting this to 0 will also causeonCodeAutoRetrievalTimeOut to be called immediately. If you specified a positive value less than 30 seconds, library will default to 30 seconds.

@NonNullTimeUnit unit

theTimeUnit for the timeout

@NonNullActivity activity

the Activity to which the callbacks are scoped.

@NonNullPhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks

the callbacks to get the status of phone number verification. The callbacks will be automatically removed when the specified activity has stopped. When a test phone number and sms code pair is set viasetAutoRetrievedSmsCodeForPhoneNumber and in the Firebase console,onCodeAutoRetrievalTimeOut will never be triggered.

verifyPhoneNumber

public void verifyPhoneNumber(
    @NonNullString phoneNumber,
    long timeout,
    @NonNullTimeUnit unit,
    @NonNullActivity activity,
    @NonNullPhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks,
    @NullablePhoneAuthProvider.ForceResendingToken forceResendingToken
)
This method is deprecated.

Instead, useverifyPhoneNumber

SeeverifyPhoneNumber for details. This overload allows specifying a .

Parameters
@NonNullString phoneNumber

the phone number for the account the user is signing up for or signing into. Make sure to pass in a phone number with country code prefixed with plus sign ('+').

long timeout

the maximum amount of time you are willing to wait for SMS auto-retrieval to be completed by the library. Maximum allowed value is 2 minutes. Use 0 to disable SMS-auto-retrieval. Setting this to 0 will also causeonCodeAutoRetrievalTimeOut to be called immediately. If you specified a positive value less than 30 seconds, library will default to 30 seconds.

@NonNullTimeUnit unit

theTimeUnit for the timeout

@NonNullActivity activity

the Activity to which the callbacks are scoped.

@NonNullPhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks

the callbacks to get the status of phone number verification. The callbacks will be automatically removed when the specified activity has stopped. When a test phone number and sms code pair is set viasetAutoRetrievedSmsCodeForPhoneNumber and in the Firebase console,onCodeAutoRetrievalTimeOut will never be triggered.

@NullablePhoneAuthProvider.ForceResendingToken forceResendingToken

the ForceResendingToken obtained fromonCodeSent callback to force re-sending another verification SMS before the auto-retrieval timeout.

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.