Search in sources :

Example 1 with PhoneAuthOptions

use of com.google.firebase.auth.PhoneAuthOptions in project quickstart-android by firebase.

the class PhoneAuthFragment method startPhoneNumberVerification.

private void startPhoneNumberVerification(String phoneNumber) {
    PhoneAuthOptions options = PhoneAuthOptions.newBuilder(mAuth).setPhoneNumber(// Phone number to verify
    phoneNumber).setTimeout(60L, // Timeout and unit
    TimeUnit.SECONDS).setActivity(// Activity (for callback binding)
    requireActivity()).setCallbacks(// OnVerificationStateChangedCallbacks
    mCallbacks).build();
    PhoneAuthProvider.verifyPhoneNumber(options);
    mVerificationInProgress = true;
}
Also used : PhoneAuthOptions(com.google.firebase.auth.PhoneAuthOptions)

Example 2 with PhoneAuthOptions

use of com.google.firebase.auth.PhoneAuthOptions in project quickstart-android by firebase.

the class PhoneAuthFragment method resendVerificationCode.

private void resendVerificationCode(String phoneNumber, PhoneAuthProvider.ForceResendingToken token) {
    PhoneAuthOptions options = PhoneAuthOptions.newBuilder(mAuth).setPhoneNumber(// Phone number to verify
    phoneNumber).setTimeout(60L, // Timeout and unit
    TimeUnit.SECONDS).setActivity(// Activity (for callback binding)
    requireActivity()).setCallbacks(// OnVerificationStateChangedCallbacks
    mCallbacks).setForceResendingToken(// ForceResendingToken from callbacks
    token).build();
    PhoneAuthProvider.verifyPhoneNumber(options);
}
Also used : PhoneAuthOptions(com.google.firebase.auth.PhoneAuthOptions)

Example 3 with PhoneAuthOptions

use of com.google.firebase.auth.PhoneAuthOptions in project quickstart-android by firebase.

the class MultiFactorEnrollFragment method onClickVerifyPhoneNumber.

private void onClickVerifyPhoneNumber() {
    String phoneNumber = mBinding.fieldPhoneNumber.getText().toString();
    OnVerificationStateChangedCallbacks callbacks = new OnVerificationStateChangedCallbacks() {

        @Override
        public void onVerificationCompleted(PhoneAuthCredential credential) {
            // This should never be triggered.
            throw new RuntimeException("onVerificationCompleted() triggered with instant-validation and auto-retrieval disabled.");
        }

        @Override
        public void onCodeSent(final String verificationId, PhoneAuthProvider.ForceResendingToken token) {
            Log.d(TAG, "onCodeSent:" + verificationId);
            Toast.makeText(getContext(), "SMS code has been sent", Toast.LENGTH_SHORT).show();
            mCodeVerificationId = verificationId;
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {
            Log.w(TAG, "onVerificationFailed ", e);
            Toast.makeText(getContext(), "Verification failed: " + e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    };
    FirebaseAuth.getInstance().getCurrentUser().getMultiFactor().getSession().addOnCompleteListener(new OnCompleteListener<MultiFactorSession>() {

        @Override
        public void onComplete(@NonNull Task<MultiFactorSession> task) {
            if (task.isSuccessful()) {
                PhoneAuthOptions phoneAuthOptions = PhoneAuthOptions.newBuilder().setPhoneNumber(phoneNumber).setTimeout(0L, TimeUnit.SECONDS).setMultiFactorSession(task.getResult()).setCallbacks(callbacks).requireSmsValidation(true).build();
                PhoneAuthProvider.verifyPhoneNumber(phoneAuthOptions);
            } else {
                Toast.makeText(getContext(), "Failed to get session: " + task.getException(), Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : FirebaseException(com.google.firebase.FirebaseException) OnVerificationStateChangedCallbacks(com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks) MultiFactorSession(com.google.firebase.auth.MultiFactorSession) PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential) PhoneAuthOptions(com.google.firebase.auth.PhoneAuthOptions)

Aggregations

PhoneAuthOptions (com.google.firebase.auth.PhoneAuthOptions)3 FirebaseException (com.google.firebase.FirebaseException)1 MultiFactorSession (com.google.firebase.auth.MultiFactorSession)1 PhoneAuthCredential (com.google.firebase.auth.PhoneAuthCredential)1 OnVerificationStateChangedCallbacks (com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks)1