PhoneAuthProvider
public class PhoneAuthProvider
Represents the phone number authentication mechanism. Use this class to obtain s.
Summary
Nested types |
|---|
public class PhoneAuthProvider.ForceResendingToken implements ParcelableA 'token' that can be used to force re-sending an SMS verification code. |
public abstract class PhoneAuthProvider.OnVerificationStateChangedCallbacksRegistered callbacks for the different phone auth events. |
Constants |
|
|---|---|
static final String |
PHONE_SIGN_IN_METHOD = "phone"Unique string identifier for Phone sign-in method. |
static final String |
PROVIDER_ID = "phone"Unique string identifier for this provider type. |
Public methods |
|
|---|---|
static @NonNull PhoneAuthCredential |
getCredential(@NonNull String verificationId, @NonNull String smsCode)Returns a new instance of |
static @NonNull PhoneAuthProvider |
This method is deprecated. Instead, use |
static @NonNull PhoneAuthProvider |
This method is deprecated. Instead, use |
static void |
verifyPhoneNumber(@NonNull PhoneAuthOptions options)Starts the phone verification process with the settings defined in |
void |
This method is deprecated. Instead, use |
void |
This method is deprecated. Instead, use |
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 @NonNull PhoneAuthCredential getCredential(@NonNull String verificationId, @NonNull String smsCode)
Returns a new instance of AuthCredential that is associated with a phone number. Used when calling signInWithCredential or linkWithCredential.
| Parameters | |
|---|---|
@NonNull String verificationId |
a valid |
@NonNull String smsCode |
the 6 digit SMS-code sent to the user |
getInstance
public static @NonNull PhoneAuthProvidergetInstance()
Initializes a new PhoneAuthProvider using the default FirebaseAuth instance.
getInstance
public static @NonNull PhoneAuthProvidergetInstance(@NonNull FirebaseAuth firebaseAuth)
Static method to initialize a new PhoneAuthProvider for the specified Auth instance.
verifyPhoneNumber
public static void verifyPhoneNumber(@NonNull PhoneAuthOptions options)
Starts the phone verification process with the settings defined in PhoneAuthOptions.
verifyPhoneNumber
public voidverifyPhoneNumber(
@NonNull String phoneNumber,
long timeout,
@NonNull TimeUnit unit,
@NonNull Activity activity,
@NonNull PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks
)
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
AuthCredentialif 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 | |
|---|---|
@NonNull String 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 cause |
@NonNull TimeUnit unit |
the |
@NonNull Activity activity |
the Activity to which the callbacks are scoped. |
@NonNull PhoneAuthProvider.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 via |
verifyPhoneNumber
public voidverifyPhoneNumber(
@NonNull String phoneNumber,
long timeout,
@NonNull TimeUnit unit,
@NonNull Activity activity,
@NonNull PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks,
@Nullable PhoneAuthProvider.ForceResendingToken forceResendingToken
)
See verifyPhoneNumber for details. This overload allows specifying a .
| Parameters | |
|---|---|
@NonNull String 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 cause |
@NonNull TimeUnit unit |
the |
@NonNull Activity activity |
the Activity to which the callbacks are scoped. |
@NonNull PhoneAuthProvider.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 via |
@Nullable PhoneAuthProvider.ForceResendingToken forceResendingToken |
the ForceResendingToken obtained from |