PhoneAuthProvider

class PhoneAuthProvider


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

const String!

Unique string identifier for Phone sign-in method.

const String!
PROVIDER_ID = "phone"

Unique string identifier for this provider type.

Public functions

java-static PhoneAuthCredential
getCredential(verificationId: String, smsCode: String)

Returns a new instance of AuthCredential that is associated with a phone number.

java-static PhoneAuthProvider

This function is deprecated.

Instead, use verifyPhoneNumber

java-static PhoneAuthProvider
getInstance(firebaseAuth: FirebaseAuth)

This function is deprecated.

Instead, use verifyPhoneNumber

java-static Unit

Starts the phone verification process with the settings defined in PhoneAuthOptions.

Unit
verifyPhoneNumber(
    phoneNumber: String,
    timeout: Long,
    unit: TimeUnit,
    activity: Activity,
    callbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks
)

This function is deprecated.

Instead, use verifyPhoneNumber

Unit
verifyPhoneNumber(
    phoneNumber: String,
    timeout: Long,
    unit: TimeUnit,
    activity: Activity,
    callbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks,
    forceResendingToken: PhoneAuthProvider.ForceResendingToken?
)

This function is deprecated.

Instead, use verifyPhoneNumber

Constants

PHONE_SIGN_IN_METHOD

const val PHONE_SIGN_IN_METHOD = "phone": String!

Unique string identifier for Phone sign-in method.

PROVIDER_ID

const val PROVIDER_ID = "phone": String!

Unique string identifier for this provider type.

Public functions

getCredential

java-static fun getCredential(verificationId: String, smsCode: String): PhoneAuthCredential

Returns a new instance of AuthCredential that is associated with a phone number. Used when calling signInWithCredential or linkWithCredential.

Parameters
verificationId: String

a valid verificationId retrieved by calling verifyPhoneNumber

smsCode: String

the 6 digit SMS-code sent to the user

getInstance

java-static fun getInstance(): PhoneAuthProvider

Initializes a new PhoneAuthProvider using the default FirebaseAuth instance.

getInstance

java-static fun getInstance(firebaseAuth: FirebaseAuth): PhoneAuthProvider

Static method to initialize a new PhoneAuthProvider for the specified Auth instance.

verifyPhoneNumber

java-static fun verifyPhoneNumber(options: PhoneAuthOptions): Unit

Starts the phone verification process with the settings defined in PhoneAuthOptions.

verifyPhoneNumber

fun verifyPhoneNumber(
    phoneNumber: String,
    timeout: Long,
    unit: TimeUnit,
    activity: Activity,
    callbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks
): Unit

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 complete AuthCredential that can be used to log in the user.

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

Make sure to test all scenarios below:

  • You directly get back an AuthCredential 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 receive onVerificationFailed.
Parameters
phoneNumber: String

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 ('+').

timeout: Long

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 cause onCodeAutoRetrievalTimeOut to be called immediately. If you specified a positive value less than 30 seconds, library will default to 30 seconds.

unit: TimeUnit

the TimeUnit for the timeout

activity: Activity

the Activity to which the callbacks are scoped.

callbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks

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 via setAutoRetrievedSmsCodeForPhoneNumber and in the Firebase console, onCodeAutoRetrievalTimeOut will never be triggered.

verifyPhoneNumber

fun verifyPhoneNumber(
    phoneNumber: String,
    timeout: Long,
    unit: TimeUnit,
    activity: Activity,
    callbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks,
    forceResendingToken: PhoneAuthProvider.ForceResendingToken?
): Unit

See verifyPhoneNumber for details. This overload allows specifying a .

Parameters
phoneNumber: String

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 ('+').

timeout: Long

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 cause onCodeAutoRetrievalTimeOut to be called immediately. If you specified a positive value less than 30 seconds, library will default to 30 seconds.

unit: TimeUnit

the TimeUnit for the timeout

activity: Activity

the Activity to which the callbacks are scoped.

callbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks

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 via setAutoRetrievedSmsCodeForPhoneNumber and in the Firebase console, onCodeAutoRetrievalTimeOut will never be triggered.

forceResendingToken: PhoneAuthProvider.ForceResendingToken?

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