Java Code Examples for com.firebase.ui.auth.IdpResponse#fromResultIntent()

The following examples show how to use com.firebase.ui.auth.IdpResponse#fromResultIntent() . 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 vote down vote up
@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 vote down vote up
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: SocialProviderResponseHandler.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
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 4
Source File: AnonymousUpgradeActivity.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
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 5
Source File: AnonymousUpgradeActivity.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: MainActivity.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: FirebaseUIActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
@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 == RESULT_OK) {
            // Successfully signed in
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            // ...
        } else {
            // Sign in failed. If response is null the user canceled the
            // sign-in flow using the back button. Otherwise check
            // response.getError().getErrorCode() and handle the error.
            // ...
        }
    }
}
 
Example 8
Source File: FirebaseLoginActivity.java    From Nimbus with GNU General Public License v3.0 6 votes vote down vote up
@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 == RESULT_OK) {
            // Successfully signed in
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            Log.d("pno.: ", user.getPhoneNumber());
            Log.d("uid: ", user.getUid());
            saveUserLoginData(user.getPhoneNumber(), user.getUid());
        } else {
            // Sign in failed, check response for error code
            Toast.makeText(this, "Login Failed", Toast.LENGTH_SHORT).show();
        }
    }

}
 
Example 9
Source File: MainActivity.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            showSnackbar("Signed in.");
        } else {
            showSnackbar("Error signing in.");

            IdpResponse response = IdpResponse.fromResultIntent(data);
            Log.w(TAG, "signIn", response.getError());
        }
    }
}
 
Example 10
Source File: LoginActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: AuthUiActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
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 12
Source File: PhoneSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode == RequestCodes.PHONE_FLOW) {
        IdpResponse response = IdpResponse.fromResultIntent(data);
        if (response == null) {
            setResult(Resource.<IdpResponse>forFailure(new UserCancellationException()));
        } else {
            setResult(Resource.forSuccess(response));
        }
    }
}
 
Example 13
Source File: GenericIdpSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode == RequestCodes.GENERIC_IDP_SIGN_IN_FLOW) {
        IdpResponse response = IdpResponse.fromResultIntent(data);
        if (response == null) {
            setResult(Resource.<IdpResponse>forFailure(new UserCancellationException()));
        } else {
            setResult(Resource.forSuccess(response));
        }
    }
}
 
Example 14
Source File: SignInKickstarter.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
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: EmailSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: EmailLinkCatcherActivity.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RequestCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_FLOW
            || requestCode == RequestCodes.EMAIL_LINK_CROSS_DEVICE_LINKING_FLOW) {
        IdpResponse response = IdpResponse.fromResultIntent(data);
        // CheckActionCode is called before starting this flow, so we only get here
        // if the sign in link is valid - it can only fail by being cancelled.
        if (resultCode == RESULT_OK) {
            finish(RESULT_OK, response.toIntent());
        } else {
            finish(RESULT_CANCELED, null);
        }
    }
}
 
Example 17
Source File: WelcomeBackEmailLinkPrompt.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fui_welcome_back_email_link_prompt_layout);
    mIdpResponseForLinking = IdpResponse.fromResultIntent(getIntent());
    initializeViewObjects();
    setBodyText();
    setOnClickListeners();
    setPrivacyFooter();
}
 
Example 18
Source File: LoginActivity.java    From cannonball-android with Apache License 2.0 5 votes vote down vote up
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());
        }
    }
}