Search in sources :

Example 1 with PhoneAuthCredential

use of com.google.firebase.auth.PhoneAuthCredential in project FirebaseAuth-Android by jirawatee.

the class PhoneAuthActivity method verifyPhoneNumberWithCode.

private void verifyPhoneNumberWithCode(String verificationId, String code) {
    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
    signInWithPhoneAuthCredential(credential);
}
Also used : PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential)

Example 2 with PhoneAuthCredential

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

the class PhoneAuthFragment method verifyPhoneNumberWithCode.

private void verifyPhoneNumberWithCode(String verificationId, String code) {
    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
    signInWithPhoneAuthCredential(credential);
}
Also used : PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential)

Example 3 with PhoneAuthCredential

use of com.google.firebase.auth.PhoneAuthCredential 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)

Example 4 with PhoneAuthCredential

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

the class MultiFactorEnrollFragment method onClickSignInWithPhoneNumber.

private void onClickSignInWithPhoneNumber() {
    String smsCode = mBinding.fieldVerificationCode.getText().toString();
    if (TextUtils.isEmpty(smsCode)) {
        return;
    }
    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mCodeVerificationId, smsCode);
    enrollWithPhoneAuthCredential(credential);
}
Also used : PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential)

Example 5 with PhoneAuthCredential

use of com.google.firebase.auth.PhoneAuthCredential in project FirebaseUI-Android by firebase.

the class PhoneNumberVerificationHandler method verifyPhoneNumber.

public void verifyPhoneNumber(@NonNull Activity activity, final String number, boolean force) {
    setResult(Resource.forLoading());
    PhoneAuthOptions.Builder optionsBuilder = PhoneAuthOptions.newBuilder(getAuth()).setPhoneNumber(number).setTimeout(AUTO_RETRIEVAL_TIMEOUT_SECONDS, TimeUnit.SECONDS).setActivity(activity).setCallbacks(new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

        @Override
        public void onVerificationCompleted(@NonNull PhoneAuthCredential credential) {
            setResult(Resource.forSuccess(new PhoneVerification(number, credential, true)));
        }

        @Override
        public void onVerificationFailed(@NonNull FirebaseException e) {
            setResult(Resource.forFailure(e));
        }

        @Override
        public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken token) {
            mVerificationId = verificationId;
            mForceResendingToken = token;
            setResult(Resource.forFailure(new PhoneNumberVerificationRequiredException(number)));
        }
    });
    if (force) {
        optionsBuilder.setForceResendingToken(mForceResendingToken);
    }
    PhoneAuthProvider.verifyPhoneNumber(optionsBuilder.build());
}
Also used : FirebaseException(com.google.firebase.FirebaseException) PhoneNumberVerificationRequiredException(com.firebase.ui.auth.data.model.PhoneNumberVerificationRequiredException) PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential) PhoneAuthOptions(com.google.firebase.auth.PhoneAuthOptions) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider)

Aggregations

PhoneAuthCredential (com.google.firebase.auth.PhoneAuthCredential)5 FirebaseException (com.google.firebase.FirebaseException)2 PhoneAuthOptions (com.google.firebase.auth.PhoneAuthOptions)2 PhoneNumberVerificationRequiredException (com.firebase.ui.auth.data.model.PhoneNumberVerificationRequiredException)1 MultiFactorSession (com.google.firebase.auth.MultiFactorSession)1 PhoneAuthProvider (com.google.firebase.auth.PhoneAuthProvider)1 OnVerificationStateChangedCallbacks (com.google.firebase.auth.PhoneAuthProvider.OnVerificationStateChangedCallbacks)1