com.google.firebase.auth.FirebaseAuthInvalidCredentialsException Java Examples
The following examples show how to use
com.google.firebase.auth.FirebaseAuthInvalidCredentialsException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: verifyPatient2.java From Doctorave with MIT License | 6 votes |
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) { FirebaseAuth.getInstance().signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information FirebaseUser user = task.getResult().getUser(); // ... putInformationInFb(verifyPatient2.this); Intent intent1 = new Intent(verifyPatient2.this, hospitalActivity.class); intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); intent1.putExtra("phone", phone); startActivity(intent1); } else { // Sign in failed, display a message and update the UI if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) { // The verification code entered was invalid } } } }); }
Example #2
Source File: DefaultErrorResolver.java From demo-firebase-android with The Unlicense | 5 votes |
@Override @Nullable protected String baseResolve(Throwable t) { if (t instanceof HttpException) { HttpException exception = (HttpException) t; switch (exception.code()) { case Const.Http.BAD_REQUEST: return "Bad Request"; case Const.Http.UNAUTHORIZED: return "Unauthorized"; case Const.Http.FORBIDDEN: return "Forbidden"; case Const.Http.NOT_ACCEPTABLE: return "Not acceptable"; case Const.Http.UNPROCESSABLE_ENTITY: return "Unprocessable entity"; case Const.Http.SERVER_ERROR: return "Server error"; default: return null; } } else if (t instanceof FirebaseAuthInvalidUserException) { return "This Id is not registered"; } else if (t instanceof FirebaseAuthInvalidCredentialsException) { return "Password is wrong"; } else if (t instanceof FirebaseAuthWeakPasswordException) { return "Password is not strong enough"; } else if (t instanceof FirebaseAuthInvalidCredentialsException) { return "Id is malformed"; } else if (t instanceof FirebaseAuthUserCollisionException) { return "User with current Id already exists"; } else { return null; } }
Example #3
Source File: PhoneAuthActivity.java From quickstart-android with Apache License 2.0 | 5 votes |
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) { mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCredential:success"); FirebaseUser user = task.getResult().getUser(); // [START_EXCLUDE] updateUI(STATE_SIGNIN_SUCCESS, user); // [END_EXCLUDE] } else { // Sign in failed, display a message and update the UI Log.w(TAG, "signInWithCredential:failure", task.getException()); if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) { // The verification code entered was invalid // [START_EXCLUDE silent] mBinding.fieldVerificationCode.setError("Invalid code."); // [END_EXCLUDE] } // [START_EXCLUDE silent] // Update UI updateUI(STATE_SIGNIN_FAILED); // [END_EXCLUDE] } } }); }
Example #4
Source File: PasswordlessActivity.java From quickstart-android with Apache License 2.0 | 5 votes |
/** * Send an email sign-in link to the specified email. */ private void sendSignInLink(String email) { ActionCodeSettings settings = ActionCodeSettings.newBuilder() .setAndroidPackageName( getPackageName(), false, /* install if not available? */ null /* minimum app version */) .setHandleCodeInApp(true) .setUrl("https://auth.example.com/emailSignInLink") .build(); hideKeyboard(mBinding.fieldEmail); showProgressBar(); mAuth.sendSignInLinkToEmail(email, settings) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { hideProgressBar(); if (task.isSuccessful()) { Log.d(TAG, "Link sent"); showSnackbar("Sign-in link sent!"); mPendingEmail = email; mBinding.status.setText(R.string.status_email_sent); } else { Exception e = task.getException(); Log.w(TAG, "Could not send link", e); showSnackbar("Failed to send link."); if (e instanceof FirebaseAuthInvalidCredentialsException) { mBinding.fieldEmail.setError("Invalid email address."); } } } }); }
Example #5
Source File: SignInKickstarter.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
private void handleCredential(final Credential credential) { String id = credential.getId(); String password = credential.getPassword(); if (TextUtils.isEmpty(password)) { String identity = credential.getAccountType(); if (identity == null) { startAuthMethodChoice(); } else { redirectSignIn( ProviderUtils.accountTypeToProviderId(credential.getAccountType()), id); } } else { final IdpResponse response = new IdpResponse.Builder( new User.Builder(EmailAuthProvider.PROVIDER_ID, id).build()).build(); setResult(Resource.<IdpResponse>forLoading()); getAuth().signInWithEmailAndPassword(id, password) .addOnSuccessListener(new OnSuccessListener<AuthResult>() { @Override public void onSuccess(AuthResult result) { handleSuccess(response, result); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { if (e instanceof FirebaseAuthInvalidUserException || e instanceof FirebaseAuthInvalidCredentialsException) { // In this case the credential saved in SmartLock was not // a valid credential, we should delete it from SmartLock // before continuing. GoogleApiUtils.getCredentialsClient(getApplication()) .delete(credential); } startAuthMethodChoice(); } }); } }
Example #6
Source File: WelcomeBackPasswordPrompt.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@StringRes private int getErrorMessage(Exception exception) { if (exception instanceof FirebaseAuthInvalidCredentialsException) { return R.string.fui_error_invalid_password; } return R.string.fui_error_unknown; }
Example #7
Source File: EmailLinkCatcherActivity.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
private void initHandler() { mHandler = ViewModelProviders.of(this).get(EmailLinkSignInHandler.class); mHandler.init(getFlowParams()); mHandler.getOperation().observe(this, new ResourceObserver<IdpResponse>(this) { @Override protected void onSuccess(@NonNull IdpResponse response) { finish(RESULT_OK, response.toIntent()); } @Override protected void onFailure(@NonNull final Exception e) { if (e instanceof UserCancellationException) { finish(RESULT_CANCELED, null); } else if (e instanceof FirebaseAuthAnonymousUpgradeException) { IdpResponse res = ((FirebaseAuthAnonymousUpgradeException) e).getResponse(); finish(RESULT_CANCELED, new Intent().putExtra(ExtraConstants.IDP_RESPONSE, res)); } else if (e instanceof FirebaseUiException) { int errorCode = ((FirebaseUiException) e).getErrorCode(); if (errorCode == ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR || errorCode == ErrorCodes.INVALID_EMAIL_LINK_ERROR || errorCode == ErrorCodes.EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR) { buildAlertDialog(errorCode).show(); } else if (errorCode == ErrorCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_ERROR || errorCode == ErrorCodes.EMAIL_MISMATCH_ERROR) { startErrorRecoveryFlow(RequestCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_FLOW); } else if (errorCode == ErrorCodes.EMAIL_LINK_CROSS_DEVICE_LINKING_ERROR) { startErrorRecoveryFlow(RequestCodes.EMAIL_LINK_CROSS_DEVICE_LINKING_FLOW); } } else if (e instanceof FirebaseAuthInvalidCredentialsException) { startErrorRecoveryFlow(RequestCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_FLOW); } else { finish(RESULT_CANCELED, IdpResponse.getErrorIntent(e)); } } }); }
Example #8
Source File: PhoneProviderHandler.java From capacitor-firebase-auth with MIT License | 4 votes |
@Override public void init(final CapacitorFirebaseAuth plugin) { this.plugin = plugin; this.mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @Override public void onVerificationCompleted(PhoneAuthCredential credential) { Log.d(PHONE_TAG, "PhoneAuth:onVerificationCompleted:" + credential); mVerificationCode = credential.getSmsCode(); PluginCall call = plugin.getSavedCall(); // Notify listeners of Code Received event. JSObject jsEvent = new JSObject(); jsEvent.put("verificationId", mVerificationId); jsEvent.put("verificationCode", mVerificationCode); plugin.notifyListeners("cfaSignInPhoneOnCodeReceived", jsEvent); JSObject jsUser = new JSObject(); jsUser.put("callbackId", call.getCallbackId()); jsUser.put("providerId", credential.getProvider()); jsUser.put("verificationId", mVerificationId); jsUser.put("verificationCode", mVerificationCode); call.success(jsUser); } @Override public void onVerificationFailed(FirebaseException error) { Log.w(PHONE_TAG, "PhoneAuth:onVerificationFailed:" + error); if (error instanceof FirebaseAuthInvalidCredentialsException) { plugin.handleFailure("Invalid phone number.", error); } else if (error instanceof FirebaseTooManyRequestsException) { plugin.handleFailure("Quota exceeded.", error); } else { plugin.handleFailure("PhoneAuth Sign In failure.", error); } } public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken token) { // The SMS verification code has been sent to the provided phone number, we // now need to ask the user to enter the code and then construct a credential // by combining the code with a verification ID. Log.d(PHONE_TAG, "onCodeSent:" + verificationId); // Save verification ID and resending token so we can use them later mVerificationId = verificationId; mResendToken = token; // Notify listeners of Code Sent event. JSObject jsEvent = new JSObject(); jsEvent.put("verificationId", mVerificationId); plugin.notifyListeners("cfaSignInPhoneOnCodeSent", jsEvent); } }; }
Example #9
Source File: PhoneAuthActivity.java From quickstart-android with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mBinding = ActivityPhoneAuthBinding.inflate(getLayoutInflater()); setContentView(mBinding.getRoot()); // Restore instance state if (savedInstanceState != null) { onRestoreInstanceState(savedInstanceState); } // Assign click listeners mBinding.buttonStartVerification.setOnClickListener(this); mBinding.buttonVerifyPhone.setOnClickListener(this); mBinding.buttonResend.setOnClickListener(this); mBinding.signOutButton.setOnClickListener(this); // [START initialize_auth] // Initialize Firebase Auth mAuth = FirebaseAuth.getInstance(); // [END initialize_auth] // Initialize phone auth callbacks // [START phone_auth_callbacks] mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @Override public void onVerificationCompleted(PhoneAuthCredential credential) { // This callback will be invoked in two situations: // 1 - Instant verification. In some cases the phone number can be instantly // verified without needing to send or enter a verification code. // 2 - Auto-retrieval. On some devices Google Play services can automatically // detect the incoming verification SMS and perform verification without // user action. Log.d(TAG, "onVerificationCompleted:" + credential); // [START_EXCLUDE silent] mVerificationInProgress = false; // [END_EXCLUDE] // [START_EXCLUDE silent] // Update the UI and attempt sign in with the phone credential updateUI(STATE_VERIFY_SUCCESS, credential); // [END_EXCLUDE] signInWithPhoneAuthCredential(credential); } @Override public void onVerificationFailed(FirebaseException e) { // This callback is invoked in an invalid request for verification is made, // for instance if the the phone number format is not valid. Log.w(TAG, "onVerificationFailed", e); // [START_EXCLUDE silent] mVerificationInProgress = false; // [END_EXCLUDE] if (e instanceof FirebaseAuthInvalidCredentialsException) { // Invalid request // [START_EXCLUDE] mBinding.fieldPhoneNumber.setError("Invalid phone number."); // [END_EXCLUDE] } else if (e instanceof FirebaseTooManyRequestsException) { // The SMS quota for the project has been exceeded // [START_EXCLUDE] Snackbar.make(findViewById(android.R.id.content), "Quota exceeded.", Snackbar.LENGTH_SHORT).show(); // [END_EXCLUDE] } // Show a message and update the UI // [START_EXCLUDE] updateUI(STATE_VERIFY_FAILED); // [END_EXCLUDE] } @Override public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken token) { // The SMS verification code has been sent to the provided phone number, we // now need to ask the user to enter the code and then construct a credential // by combining the code with a verification ID. Log.d(TAG, "onCodeSent:" + verificationId); // Save verification ID and resending token so we can use them later mVerificationId = verificationId; mResendToken = token; // [START_EXCLUDE] // Update UI updateUI(STATE_CODE_SENT); // [END_EXCLUDE] } }; // [END phone_auth_callbacks] }