简体   繁体   中英

Mobile OTP Verification without signing in using Firebase Phone Auth

I am currently making an android app where I need to verify if the user is entering correct mobile number using the OTP. The user is already signed in the application using his email and password. Now I need to verify the mobile number the user enters without using the signInWithCrendntial() method of firebase phone auth. How do i go about it ?

My mCallbacks is

                @Override
                public void onVerificationCompleted(PhoneAuthCredential credential) {
                    Toast.makeText(getApplicationContext(), "Verification Complete", Toast.LENGTH_SHORT).show();

                    showMessage("Success!!","OTP verified!" + credential);
                    cred = credential;
                    //btn_add_guest.setEnabled(true);

                }

                @Override
                public void onVerificationFailed(FirebaseException e) {
                    Toast.makeText(getApplicationContext(), "Verification Failed", Toast.LENGTH_SHORT).show();
                    Log.i(TAG,"Error is "+e.getMessage());
                }

                @Override
                public void onCodeSent(String verificationId,
                                       PhoneAuthProvider.ForceResendingToken token) {
                    Toast.makeText(getApplicationContext(), "Code Sent", Toast.LENGTH_SHORT).show();
                    mVerificationId = verificationId;
                    mResendToken = token;

                    Log.i(TAG,"VERFICATION ID IS"+mVerificationId);
                    Log.i(TAG,"RESEND TOKEN"+mResendToken);
                    btn_add_guest.setEnabled(false);
                }
            };

I m calling this method on button Pressed where put_otp is textView where user enters the OTP.

verifyPhoneNumberWithCode(mVerificationId,put_otp.getText().toString());
                    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, put_otp.getText().toString());
                    Log.i(TAG,credential.getProvider());

private void verifyPhoneNumberWithCode(String verificationId, String code) {

        Log.i(TAG,"RESEND TOKEN IN METHOD IS"+mResendToken);    if(code.equals(mResendToken)&&verificationId.equals(mVerificationId)){
            Toast.makeText(AddGuestActivity.this, "Verification Success", Toast.LENGTH_SHORT).show();

            btn_add_guest.setEnabled(true);
        }
        else
            Toast.makeText(this,"Please provide correct OTP",Toast.LENGTH_SHORT).show();
    }

您可以将电子邮件/通行证帐户与电话帐户相关联https://firebase.google.com/docs/auth/android/account-linking?authuser=0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM