com.firebase.ui.auth.ErrorCodes Java Examples
The following examples show how to use
com.firebase.ui.auth.ErrorCodes.
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: StartupActivity.java From Track-My-Location with GNU General Public License v3.0 | 6 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_LOGIN) { IdpResponse response = IdpResponse.fromResultIntent(data); if (resultCode == RESULT_OK) { goToMainActivity(); } else { if (response == null) { Toast.makeText(this, "Login Failed", Toast.LENGTH_SHORT).show(); } else if (response.getError().getErrorCode() == ErrorCodes.NO_NETWORK) { Toast.makeText(this, "No Network Connection", Toast.LENGTH_SHORT).show(); } } } }
Example #2
Source File: BaseAuthActivity.java From q-municate-android with Apache License 2.0 | 6 votes |
private void onReceiveFirebaseAuthResult(int resultCode, Intent data) { IdpResponse response = IdpResponse.fromResultIntent(data); // Successfully signed in if (resultCode == RESULT_OK) { firebaseAuthHelper.refreshInternalFirebaseToken(firebaseAuthCallback); } else { //Sign in failed if (response == null) { // User pressed back button Log.i(TAG, "BACK button pressed"); return; } if (response.getErrorCode() == ErrorCodes.NO_NETWORK || response.getErrorCode() == ErrorCodes.UNKNOWN_ERROR) { showSnackbar(R.string.dlg_internet_connection_error, Snackbar.LENGTH_INDEFINITE); } } }
Example #3
Source File: EmailLinkSignInHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("all") public void testStartSignIn_invalidLink_expectInvalidLinkError() { mHandler.getOperation().observeForever(mResponseObserver); when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(false); mHandler.startSignIn(); verify(mMockAuth).isSignInWithEmailLink(any(String.class)); ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class); InOrder inOrder = inOrder(mResponseObserver); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); inOrder.verify(mResponseObserver).onChanged(captor.capture()); FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException(); assertThat(exception).isNotNull(); assertThat(exception.getErrorCode()).isEqualTo(ErrorCodes .INVALID_EMAIL_LINK_ERROR); }
Example #4
Source File: EmailLinkSignInHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("all") public void testStartSignIn_differentDeviceLinkWithNoSessionId_expectInvalidLinkError() { initializeHandlerWithSessionInfo(null, null, null, true); mHandler.getOperation().observeForever(mResponseObserver); when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true); mHandler.startSignIn(); verify(mMockAuth).isSignInWithEmailLink(any(String.class)); ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class); InOrder inOrder = inOrder(mResponseObserver); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); inOrder.verify(mResponseObserver).onChanged(captor.capture()); FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException(); assertThat(exception).isNotNull(); assertThat(exception.getErrorCode()).isEqualTo(ErrorCodes.INVALID_EMAIL_LINK_ERROR); }
Example #5
Source File: EmailLinkSignInHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("all") public void testStartSignIn_differentDeviceLinkWithForceSameDeviceTrue_expectWrongDeviceError() { String differentSessionId = SessionUtils.generateRandomAlphaNumericString(10); initializeHandlerWithSessionInfo(differentSessionId, null, null, true); mHandler.getOperation().observeForever(mResponseObserver); when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true); mHandler.startSignIn(); verify(mMockAuth).isSignInWithEmailLink(any(String.class)); ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class); InOrder inOrder = inOrder(mResponseObserver); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); inOrder.verify(mResponseObserver).onChanged(captor.capture()); FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException(); assertThat(exception).isNotNull(); assertThat(exception.getErrorCode()).isEqualTo(ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR); }
Example #6
Source File: SocialProviderResponseHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@Test public void testSignInIdp_disabled() { mHandler.getOperation().observeForever(mResultObserver); when(mMockAuth.signInWithCredential(any(AuthCredential.class))) .thenReturn(AutoCompleteTask.<AuthResult>forFailure( new FirebaseAuthException("ERROR_USER_DISABLED", "disabled"))); IdpResponse response = new IdpResponse.Builder(new User.Builder( GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()) .setToken(TestConstants.TOKEN) .build(); mHandler.startSignIn(response); verify(mResultObserver).onChanged( argThat(ResourceMatchers.<IdpResponse>isFailureWithCode(ErrorCodes.ERROR_USER_DISABLED))); }
Example #7
Source File: SocialProviderResponseHandler.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
private void handleGenericIdpLinkingFlow(@NonNull final IdpResponse idpResponse) { ProviderUtils.fetchSortedProviders(getAuth(), getArguments(), idpResponse.getEmail()) .addOnSuccessListener(new OnSuccessListener<List<String>>() { @Override public void onSuccess(@NonNull List<String> providers) { if (providers.isEmpty()) { setResult(Resource.<IdpResponse>forFailure( new FirebaseUiException(ErrorCodes.DEVELOPER_ERROR, "No supported providers."))); return; } startWelcomeBackFlowForLinking(providers.get(0), idpResponse); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { setResult(Resource.<IdpResponse>forFailure(e)); } }); }
Example #8
Source File: SocialProviderResponseHandler.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (requestCode == RequestCodes.ACCOUNT_LINK_FLOW) { IdpResponse response = IdpResponse.fromResultIntent(data); if (resultCode == Activity.RESULT_OK) { setResult(Resource.forSuccess(response)); } else { Exception e; if (response == null) { e = new FirebaseUiException( ErrorCodes.UNKNOWN_ERROR, "Link canceled by user."); } else { e = response.getError(); } setResult(Resource.<IdpResponse>forFailure(e)); } } }
Example #9
Source File: EmailLinkSignInHandler.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
private void determineDifferentDeviceErrorFlowAndFinish(@NonNull String oobCode, @Nullable final String providerId) { getAuth().checkActionCode(oobCode).addOnCompleteListener( new OnCompleteListener<ActionCodeResult>() { @Override public void onComplete(@NonNull Task<ActionCodeResult> task) { if (task.isSuccessful()) { if (!TextUtils.isEmpty(providerId)) { setResult(Resource.<IdpResponse>forFailure( new FirebaseUiException( ErrorCodes.EMAIL_LINK_CROSS_DEVICE_LINKING_ERROR))); return; } // The email link is valid, we can ask the user for their email setResult(Resource.<IdpResponse>forFailure( new FirebaseUiException( ErrorCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_ERROR))); } else { setResult(Resource.<IdpResponse>forFailure( new FirebaseUiException(ErrorCodes.INVALID_EMAIL_LINK_ERROR))); } } }); }
Example #10
Source File: MainActivity.java From quickstart-android with Apache License 2.0 | 6 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { IdpResponse response = IdpResponse.fromResultIntent(data); mViewModel.setIsSigningIn(false); if (resultCode != RESULT_OK) { if (response == null) { // User pressed the back button. finish(); } else if (response.getError() != null && response.getError().getErrorCode() == ErrorCodes.NO_NETWORK) { showSignInErrorDialog(R.string.message_no_network); } else { showSignInErrorDialog(R.string.message_unknown); } } } }
Example #11
Source File: AnonymousUpgradeActivity.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_anonymous_upgrade); ButterKnife.bind(this); updateUI(); // Got here from AuthUIActivity, and we need to deal with a merge conflict // Occurs after catching an email link IdpResponse response = IdpResponse.fromResultIntent(getIntent()); if (response != null) { handleSignInResult(RC_SIGN_IN, ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT, getIntent()); } }
Example #12
Source File: AnonymousUpgradeActivity.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
private void handleSignInResult(int requestCode, int resultCode, Intent data) { if (requestCode == RC_SIGN_IN) { IdpResponse response = IdpResponse.fromResultIntent(data); if (response == null) { // User pressed back button return; } if (resultCode == RESULT_OK) { setStatus("Signed in as " + getUserIdentifier(FirebaseAuth.getInstance() .getCurrentUser())); } else if (response.getError().getErrorCode() == ErrorCodes .ANONYMOUS_UPGRADE_MERGE_CONFLICT) { setStatus("Merge conflict: user already exists."); mResolveMergeButton.setEnabled(true); mPendingCredential = response.getCredentialForLinking(); } else { Toast.makeText(this, "Auth error, see logs", Toast.LENGTH_SHORT).show(); Log.w(TAG, "Error: " + response.getError().getMessage(), response.getError()); } updateUI(); } }
Example #13
Source File: EmailLinkSignInHandler.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
private void finishSignIn(@NonNull String email, @Nullable IdpResponse response) { if (TextUtils.isEmpty(email)) { setResult(Resource.<IdpResponse>forFailure( new FirebaseUiException(ErrorCodes.EMAIL_MISMATCH_ERROR))); return; } final AuthOperationManager authOperationManager = AuthOperationManager.getInstance(); final EmailLinkPersistenceManager persistenceManager = EmailLinkPersistenceManager .getInstance(); String link = getArguments().emailLink; if (response == null) { handleNormalFlow(authOperationManager, persistenceManager, email, link); } else { handleLinkingFlow(authOperationManager, persistenceManager, response, link); } }
Example #14
Source File: SignInKickstarter.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { switch (requestCode) { case RequestCodes.CRED_HINT: if (resultCode == Activity.RESULT_OK) { handleCredential((Credential) data.getParcelableExtra(Credential.EXTRA_KEY)); } else { startAuthMethodChoice(); } break; case RequestCodes.EMAIL_FLOW: case RequestCodes.AUTH_PICKER_FLOW: case RequestCodes.PHONE_FLOW: case RequestCodes.PROVIDER_FLOW: if (resultCode == RequestCodes.EMAIL_LINK_WRONG_DEVICE_FLOW || resultCode == RequestCodes.EMAIL_LINK_INVALID_LINK_FLOW) { startAuthMethodChoice(); return; } IdpResponse response = IdpResponse.fromResultIntent(data); if (response == null) { setResult(Resource.<IdpResponse>forFailure(new UserCancellationException())); } else if (response.isSuccessful()) { setResult(Resource.forSuccess(response)); } else if (response.getError().getErrorCode() == ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT) { handleMergeFailure(response); } else { setResult(Resource.<IdpResponse>forFailure(response.getError())); } } }
Example #15
Source File: LoginActivity.java From cannonball-android with Apache License 2.0 | 5 votes |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "GOT AN ACTIVITY RESULT"); if (requestCode == RC_SIGN_IN) { Log.d(TAG, "IT WAS A SIGN IN RESULT"); IdpResponse response = IdpResponse.fromResultIntent(data); // Successfully signed in if (resultCode == RESULT_OK) { logAuthEvent("phone"); startThemeChooser(); finish(); } else { // Sign in failed if (response == null) { // User pressed back button showError("Sign in cancelled"); return; } if (response.getError().getErrorCode() == ErrorCodes.NO_NETWORK) { showError("Sign in cancelled"); return; } showError("Unknown Error"); Log.e(TAG, "Sign-in error: ", response.getError()); } } }
Example #16
Source File: EmailLinkSignInHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("all") public void testStartSignIn_differentDeviceLinkWithAnonymousUpgradeEnabled_expectInvalidLinkError() { String differentSessionId = SessionUtils.generateRandomAlphaNumericString(10); String anonUserId = SessionUtils.generateRandomAlphaNumericString(10); initializeHandlerWithSessionInfo(differentSessionId, anonUserId, null, false); mHandler.getOperation().observeForever(mResponseObserver); when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true); mHandler.startSignIn(); verify(mMockAuth).isSignInWithEmailLink(any(String.class)); ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class); InOrder inOrder = inOrder(mResponseObserver); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); inOrder.verify(mResponseObserver).onChanged(captor.capture()); FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException(); assertThat(exception).isNotNull(); assertThat(exception.getErrorCode()) .isEqualTo(ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR); }
Example #17
Source File: EmailLinkSignInHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("all") public void testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectInvalidLinkError() { String differentSessionId = SessionUtils.generateRandomAlphaNumericString(10); initializeHandlerWithSessionInfo(differentSessionId, null, null, false); mHandler.getOperation().observeForever(mResponseObserver); when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true); when(mMockAuth.checkActionCode(any(String.class))) .thenReturn(AutoCompleteTask.<ActionCodeResult>forFailure(new Exception("foo"))); mHandler.startSignIn(); verify(mMockAuth).isSignInWithEmailLink(any(String.class)); verify(mMockAuth).checkActionCode(any(String.class)); ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class); InOrder inOrder = inOrder(mResponseObserver); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); inOrder.verify(mResponseObserver).onChanged(captor.capture()); FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException(); assertThat(exception).isNotNull(); assertThat(exception.getErrorCode()) .isEqualTo(ErrorCodes.INVALID_EMAIL_LINK_ERROR); }
Example #18
Source File: EmailLinkSignInHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("all") public void testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectPromptForEmailError() { String differentSessionId = SessionUtils.generateRandomAlphaNumericString(10); initializeHandlerWithSessionInfo(differentSessionId, null, null, false); mHandler.getOperation().observeForever(mResponseObserver); when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true); when(mMockAuth.checkActionCode(any(String.class))).thenReturn(AutoCompleteTask.forSuccess (mMockActionCodeResult)); mHandler.startSignIn(); verify(mMockAuth).isSignInWithEmailLink(any(String.class)); verify(mMockAuth).checkActionCode(any(String.class)); ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class); InOrder inOrder = inOrder(mResponseObserver); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); inOrder.verify(mResponseObserver).onChanged(captor.capture()); FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException(); assertThat(exception).isNotNull(); assertThat(exception.getErrorCode()) .isEqualTo(ErrorCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_ERROR); }
Example #19
Source File: LoginActivity.java From Stayfit with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { IdpResponse response = IdpResponse.fromResultIntent(data); if (resultCode == Activity.RESULT_OK) { Log.d(this.getClass().getName(), "This user signed in with " + response.getProviderType()); startUpTasks(); updateInfo(); } else { // Sign in failed if (response == null) { // User pressed back button Toast.makeText(this, "Signin cancelled", Toast.LENGTH_SHORT).show(); return; } if (response.getError().getErrorCode() == ErrorCodes.NO_NETWORK) { Toast.makeText(this, "Check network connection and try again", Toast.LENGTH_LONG).show(); return; } Toast.makeText(this, "Unexpected Error, we are trying to resolve the issue. Please check back soon", Toast.LENGTH_LONG).show(); Log.e(TAG, "Sign-in error: ", response.getError()); } } }
Example #20
Source File: HelperActivityBase.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Forward the results of Smart Lock saving if (requestCode == RequestCodes.CRED_SAVE_FLOW || resultCode == ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT) { finish(resultCode, data); } }
Example #21
Source File: EmailLinkCatcherActivity.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
private AlertDialog buildAlertDialog(final int errorCode) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); String titleText; String messageText; if (errorCode == ErrorCodes.EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR) { titleText = getString(R.string.fui_email_link_different_anonymous_user_header); messageText = getString(R.string.fui_email_link_different_anonymous_user_message); } else if (errorCode == ErrorCodes.INVALID_EMAIL_LINK_ERROR) { titleText = getString(R.string.fui_email_link_invalid_link_header); messageText = getString(R.string.fui_email_link_invalid_link_message); } else { // Default value - ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR titleText = getString(R.string.fui_email_link_wrong_device_header); messageText = getString(R.string.fui_email_link_wrong_device_message); } return alertDialog.setTitle(titleText) .setMessage(messageText) .setPositiveButton(R.string.fui_email_link_dismiss_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(errorCode, null); } }) .create(); }
Example #22
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 #23
Source File: EmailSignInHandler.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (resultCode == ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT) { // The activity deals with this case. This conflict is handled by the developer. } else if (requestCode == RequestCodes.EMAIL_FLOW) { IdpResponse response = IdpResponse.fromResultIntent(data); if (response == null) { setResult(Resource.<IdpResponse>forFailure(new UserCancellationException())); } else { setResult(Resource.forSuccess(response)); } } }
Example #24
Source File: GoogleSignInHandler.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (requestCode != RequestCodes.GOOGLE_PROVIDER) { return; } try { GoogleSignInAccount account = GoogleSignIn.getSignedInAccountFromIntent(data) .getResult(ApiException.class); setResult(Resource.forSuccess(createIdpResponse(account))); } catch (ApiException e) { if (e.getStatusCode() == CommonStatusCodes.INVALID_ACCOUNT) { // If we get INVALID_ACCOUNT, it means the pre-set account was not available on the // device so set the email to null and launch the sign-in picker. mEmail = null; start(); } else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CURRENTLY_IN_PROGRESS) { // Hack for https://github.com/googlesamples/google-services/issues/345 // Google remembers the account so the picker doesn't appear twice for the user. start(); } else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) { setResult(Resource.<IdpResponse>forFailure(new UserCancellationException())); } else { if (e.getStatusCode() == CommonStatusCodes.DEVELOPER_ERROR) { Log.w(TAG, "Developer error: this application is misconfigured. " + "Check your SHA1 and package name in the Firebase console."); } setResult(Resource.<IdpResponse>forFailure(new FirebaseUiException( ErrorCodes.PROVIDER_ERROR, "Code: " + e.getStatusCode() + ", message: " + e.getMessage()))); } } }
Example #25
Source File: GenericIdpSignInHandler.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
protected void handleMergeFailure(@NonNull AuthCredential credential) { IdpResponse failureResponse = new IdpResponse.Builder() .setPendingCredential(credential).build(); setResult(Resource.<IdpResponse>forFailure(new FirebaseAuthAnonymousUpgradeException( ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT, failureResponse))); }
Example #26
Source File: AuthUiActivity.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
private void handleSignInResponse(int resultCode, @Nullable Intent data) { IdpResponse response = IdpResponse.fromResultIntent(data); // Successfully signed in if (resultCode == RESULT_OK) { startSignedInActivity(response); finish(); } else { // Sign in failed if (response == null) { // User pressed back button showSnackbar(R.string.sign_in_cancelled); return; } if (response.getError().getErrorCode() == ErrorCodes.NO_NETWORK) { showSnackbar(R.string.no_internet_connection); return; } if (response.getError().getErrorCode() == ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT) { Intent intent = new Intent(this, AnonymousUpgradeActivity.class).putExtra (ExtraConstants.IDP_RESPONSE, response); startActivity(intent); } if (response.getError().getErrorCode() == ErrorCodes.ERROR_USER_DISABLED) { showSnackbar(R.string.account_disabled); return; } showSnackbar(R.string.unknown_error); Log.e(TAG, "Sign-in error: ", response.getError()); } }
Example #27
Source File: SmartLockHandler.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
/** Initialize saving a credential. */ public void saveCredentials(@Nullable Credential credential) { if (!getArguments().enableCredentials) { setResult(Resource.forSuccess(mResponse)); return; } setResult(Resource.<IdpResponse>forLoading()); if (credential == null) { setResult(Resource.<IdpResponse>forFailure(new FirebaseUiException( ErrorCodes.UNKNOWN_ERROR, "Failed to build credential."))); return; } deleteUnusedCredentials(); getCredentialsClient().save(credential) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { setResult(Resource.forSuccess(mResponse)); } else if (task.getException() instanceof ResolvableApiException) { ResolvableApiException rae = (ResolvableApiException) task.getException(); setResult(Resource.<IdpResponse>forFailure( new PendingIntentRequiredException( rae.getResolution(), RequestCodes.CRED_SAVE))); } else { Log.w(TAG, "Non-resolvable exception: " + task.getException()); setResult(Resource.<IdpResponse>forFailure(new FirebaseUiException( ErrorCodes.UNKNOWN_ERROR, "Error when saving credential.", task.getException()))); } } }); }
Example #28
Source File: SmartLockHandler.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
/** * Forward the result of a resolution from the Activity to the ViewModel. */ public void onActivityResult(int requestCode, int resultCode) { if (requestCode == RequestCodes.CRED_SAVE) { if (resultCode == Activity.RESULT_OK) { setResult(Resource.forSuccess(mResponse)); } else { Log.e(TAG, "SAVE: Canceled by user."); FirebaseUiException exception = new FirebaseUiException( ErrorCodes.UNKNOWN_ERROR, "Save canceled by user."); setResult(Resource.<IdpResponse>forFailure(exception)); } } }
Example #29
Source File: FacebookSignInHandler.java From FirebaseUI-Android with Apache License 2.0 | 4 votes |
@Override public void onError(FacebookException e) { setResult(Resource.<IdpResponse>forFailure(new FirebaseUiException( ErrorCodes.PROVIDER_ERROR, e))); }
Example #30
Source File: GenericIdpSignInHandler.java From FirebaseUI-Android with Apache License 2.0 | 4 votes |
private void handleAnonymousUpgradeFlow(final FirebaseAuth auth, final HelperActivityBase activity, final OAuthProvider provider, final FlowParameters flowParameters) { auth.getCurrentUser() .startActivityForLinkWithProvider(activity, provider) .addOnSuccessListener( new OnSuccessListener<AuthResult>() { @Override public void onSuccess(@NonNull AuthResult authResult) { handleSuccess(provider.getProviderId(), authResult.getUser(), (OAuthCredential) authResult.getCredential()); } }) .addOnFailureListener( new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { if (!(e instanceof FirebaseAuthUserCollisionException)) { setResult(Resource.<IdpResponse>forFailure(e)); return; } FirebaseAuthUserCollisionException collisionException = (FirebaseAuthUserCollisionException) e; final AuthCredential credential = collisionException.getUpdatedCredential(); final String email = collisionException.getEmail(); // Case 1: Anonymous user trying to link with an existing user // Case 2: Anonymous user trying to link with a provider keyed // by an email that already belongs to an existing account // (linking flow) ProviderUtils.fetchSortedProviders(auth, flowParameters, email) .addOnSuccessListener(new OnSuccessListener<List<String>>() { @Override public void onSuccess(List<String> providers) { if (providers.isEmpty()) { String errorMessage = "Unable to complete the linkingflow -" + " the user is using " + "unsupported providers."; setResult(Resource.<IdpResponse>forFailure( new FirebaseUiException( ErrorCodes.DEVELOPER_ERROR, errorMessage))); return; } if (providers.contains(provider.getProviderId())) { // Case 1 handleMergeFailure(credential); } else { // Case 2 - linking flow to be handled by // SocialProviderResponseHandler setResult(Resource.<IdpResponse>forFailure( new FirebaseUiUserCollisionException( ErrorCodes.ERROR_GENERIC_IDP_RECOVERABLE_ERROR, "Recoverable error.", provider.getProviderId(), email, credential))); } } }); } }); }