public void handleAccessToken(AccessToken token) { Utils.d("FB:Handle:AccessToken: " + token.getToken()); // showProgressDialog(); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Utils.d("FB:signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Utils.w("FB:signInWithCredential" + task.getException().toString()); } // hideProgressDialog(); } }); }
public static AuthCredential getCredential(final JSONObject credential) throws Exception { final String providerId = credential.getString("provider"); AuthCredential authCredential; if (providerId.equals(EmailAuthProvider.PROVIDER_ID)) { authCredential = getEmailAuthCredential(credential); } else if (providerId.equals(FacebookAuthProvider.PROVIDER_ID)) { authCredential = getFacebookAuthCredential(credential); } else if (providerId.equals(GithubAuthProvider.PROVIDER_ID)) { authCredential = getGithubAuthCredential(credential); } else if (providerId.equals(GoogleAuthProvider.PROVIDER_ID)) { authCredential = getGoogleAuthCredential(credential); } else if (providerId.equals(TwitterAuthProvider.PROVIDER_ID)) { authCredential = getTwitterAuthCredential(credential); } else { throw new Exception("Unknown provider ID: " + providerId); } return authCredential; }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); 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"); updateUI(mAuth.getCurrentUser()); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(MainActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // ... } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); fireBaseAuth.signInWithCredential(credential) .addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(getApplicationContext(), "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(MainActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
private void handleFacebookAccessToken(AccessToken token) { LogUtil.logDebug(TAG, "handleFacebookAccessToken:" + token); showProgress(); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { LogUtil.logDebug(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { handleAuthError(task); } } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.e(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); 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.e(TAG, "signInWithCredential:success"); FirebaseUser user = mAuth.getCurrentUser(); updateUser(user); updateUi(); } else { // If sign in fails, display a message to the user. Log.e(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(RegisterActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // ... } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); // [START_EXCLUDE silent] // showProgressDialog(); // [END_EXCLUDE] AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(getContext(), "Authentication failed.", Toast.LENGTH_SHORT).show(); } // [START_EXCLUDE] // hideProgressDialog(); dismiss(); // [END_EXCLUDE] } }); }
private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); auth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { Toast.makeText(LoginTempActivity.this, R.string.error_auth, Toast.LENGTH_SHORT).show(); showMainScreen(); }else{ FirebaseUser firebaseUser = task.getResult().getUser(); User user = new User(); user.setDisplayName(firebaseUser.getDisplayName()); user.setEmail(firebaseUser.getEmail()); user.setId(firebaseUser.getUid()); if(firebaseUser.getPhotoUrl() != null){ user.setProfileImageURL(firebaseUser.getPhotoUrl().toString()); } user.setToken(user.getToken()); repository.saveUser(user); showMainScreen(); } } }); }
private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); auth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { Toast.makeText(LoginActivity.this, R.string.error_auth, Toast.LENGTH_SHORT).show(); showMainScreen(); }else{ FirebaseUser firebaseUser = task.getResult().getUser(); User user = new User(); user.setDisplayName(firebaseUser.getDisplayName()); user.setEmail(firebaseUser.getEmail()); user.setId(firebaseUser.getUid()); if(firebaseUser.getPhotoUrl() != null){ user.setProfileImageURL(firebaseUser.getPhotoUrl().toString()); } user.setToken(user.getToken()); repository.saveUser(user); showMainScreen(); } } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d("hfat", "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); auth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d("hfat - o", "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w("hfat - o is", "signInWithCredential", task.getException()); Toast.makeText(RegisterActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // ... } }); }
@Override public void onSuccess(LoginResult loginResult) { Timber.d("facebook:onSuccess:permissions" + loginResult.getRecentlyGrantedPermissions()); AuthCredential credential = FacebookAuthProvider.getCredential(loginResult.getAccessToken().getToken()); firebaseAuth.signInWithCredential(credential) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { Timber.d("onComplete:failed:" + task.getException()); return; } Timber.d("onComplete:success:" + task.isSuccessful()); sessionManager.saveUserInfo(); setupLoginState(); } }); }
@Override protected Void doInBackground(Void... voids) { final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if(user != null) { for(UserInfo info : user.getProviderData()) { switch(info.getProviderId()) { case GoogleAuthProvider.PROVIDER_ID: logoutGoogle(); break; case FacebookAuthProvider.PROVIDER_ID: logoutFacebook(); break; case TwitterAuthProvider.PROVIDER_ID: logoutTwitter(); break; } } FirebaseAuth.getInstance().signOut(); } return null; }
@ReactMethod public void facebookLogin(String Token, final Callback callback) { mAuth = FirebaseAuth.getInstance(); AuthCredential credential = FacebookAuthProvider.getCredential(Token); mAuth.signInWithCredential(credential) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { FirestackAuthModule.this.user = task.getResult().getUser(); userCallback(FirestackAuthModule.this.user, callback); }else{ // userErrorCallback(task, callback); } } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception ex) { userExceptionCallback(ex, callback); } }); }
private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); FirebaseClient.getInstance().getAuth().signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d("MAPP", "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w("MAPP", "signInWithCredential", task.getException()); Toast.makeText(LoginActivity.this, R.string.authentication_failed, Toast.LENGTH_SHORT).show(); } else { isAuthenticated = true; Toast.makeText(LoginActivity.this, R.string.sign_in_successfully, Toast.LENGTH_SHORT).show(); } } }); }
void handleFacebookAccessToken(AccessToken token) { mView.showProgress(); Timber.d("handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener((Activity) mContext, task -> { mView.hideProgress(); Timber.d("signInWithCredential:onComplete:" + task.isSuccessful()); if (!task.isSuccessful()) { Timber.w("signInWithFbCredential", task.getException()); mEventBus.post(new LoginEvent(false, "Fb Auth Failed : " + task.getException().getMessage())); } else { Timber.w("signInWithFbCredential", "success with email " + task.getResult().getUser().getEmail()); mEventBus.post(new LoginEvent(true, "Fb Auth Success")); } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(SignInLoadActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // ... } }); }
/** * Translate a Firebase Auth provider ID (such as {@link GoogleAuthProvider#PROVIDER_ID}) to a * Credentials API account type (such as {@link IdentityProviders#GOOGLE}). */ public static String providerIdToAccountType(@AuthUI.SupportedProvider @NonNull String providerId) { switch (providerId) { case GoogleAuthProvider.PROVIDER_ID: return IdentityProviders.GOOGLE; case FacebookAuthProvider.PROVIDER_ID: return IdentityProviders.FACEBOOK; case TwitterAuthProvider.PROVIDER_ID: return IdentityProviders.TWITTER; case PhoneAuthProvider.PROVIDER_ID: return PHONE_IDENTITY; // The account type for email/password creds is null case EmailAuthProvider.PROVIDER_ID: default: return null; } }
@Test @Config(shadows = {AuthHelperShadow.class, AuthHelperShadow.class}) public void testFacebookLoginFlow() { // initialize mocks reset(AuthHelperShadow.getSaveSmartLockInstance(null)); when(AuthHelperShadow.getCurrentUser().getProviders()) .thenReturn(Arrays.asList(FacebookAuthProvider.PROVIDER_ID)); when(AuthHelperShadow.getFirebaseAuth().signInWithCredential((AuthCredential) any())) .thenReturn(new AutoCompleteTask<>(FakeAuthResult.INSTANCE, true, null)); List<String> providers = Arrays.asList(AuthUI.FACEBOOK_PROVIDER); AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers); Button facebookButton = authMethodPickerActivity.findViewById(R.id.facebook_button); assertNotNull(facebookButton); facebookButton.performClick(); verifySmartLockSave(AuthUI.FACEBOOK_PROVIDER, TestConstants.EMAIL, null); }
private void handleFacebookAccessToken(AccessToken accessToken) { showProgressDialog(); AuthCredential credential = FacebookAuthProvider.getCredential(accessToken.getToken()); mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { Toast.makeText(getApplicationContext(), R.string.firebase_error_login, Toast.LENGTH_LONG).show(); } hideProgressDialog(); } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d("Facebook", "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); firebaseAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d("Facebook", "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w("Facebook", "signInWithCredential", task.getException()); } prepare(); /* 신규인지 확인 */ if (isNetworkConnected()) { checkNewUser(); } onMainActivity(); } }); }
private void handleFacebookAccessToken(AccessToken token) { FirebaseAuth auth = FirebaseAuth.getInstance(); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); auth.signInWithCredential(credential) .addOnCompleteListener(mActivity, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { mFaceCallback.cancelLoginFace(); }else{ mFaceCallback.getInfoFace(); } } }); }
private void firebaseAuthWithFacebook(AccessToken token) { Timber.e("firebaseAuthWithFacebook:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, mAuthCompleteListener); }
private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { getUserInfo(); } else { // If sign in fails, display a message to the user. Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
private void handleFacebookAccessToken(final AccessToken token) { MyLg.d("KOI", "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { MyLg.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); } }); }
private static void logoutByProvider(String providerId, GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) { switch (providerId) { case GoogleAuthProvider.PROVIDER_ID: logoutGoogle(mGoogleApiClient, fragmentActivity); break; case FacebookAuthProvider.PROVIDER_ID: logoutFacebook(fragmentActivity.getApplicationContext()); break; } }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); if (mAuth.getCurrentUser() == null) { mAuth.signInWithCredential(credential) .addOnCompleteListener(LoginActivity.this, new LoginCallback(LoginActivity.this, false, "connect_to_facebook")); } else { mAuth.getCurrentUser() .linkWithCredential(credential) .addOnCompleteListener(LoginActivity.this, new LoginCallback(LoginActivity.this, true, "connect_to_facebook")); } }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); if (mAuth.getCurrentUser() == null) { mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new LoginCallback(this, false, "connect_to_facebook")); } else { mAuth.getCurrentUser() .linkWithCredential(credential) .addOnCompleteListener(this, new LoginCallback(this, true, "connect_to_facebook")); } }
private void handleFacebookAccessToken(AccessToken token) { Timber.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); firebaseAuth.signInWithCredential(credential).addOnCompleteListener(task -> { authListener.onSignIn(); }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); // [START_EXCLUDE silent] // showProgressDialog(); // [END_EXCLUDE] AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(AuthActivity.this, "Authentication failed.", Toast.LENGTH_SHORT) .show(); } // [START_EXCLUDE] // hideProgressDialog(); startActivity(new Intent(AuthActivity.this, TimelineActivity.class)); finish(); // [END_EXCLUDE] } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); // [START_EXCLUDE silent] showProgressDialog(); // [END_EXCLUDE] AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); 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 = mAuth.getCurrentUser(); updateUI(user); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(FacebookLoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); updateUI(null); } // [START_EXCLUDE] hideProgressDialog(); // [END_EXCLUDE] } }); }
private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); ssFirebaseAuth.signInWithCredential(credential) .addOnCompleteListener((SSLoginActivity)context, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { loginFailed(task.getException().getMessage()); } } }); }
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); // [START_EXCLUDE silent] showProgressDialog(); // [END_EXCLUDE] AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(FacebookLoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // [START_EXCLUDE] hideProgressDialog(); // [END_EXCLUDE] } }); }
private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); firebaseAuth.signInWithCredential(credential).addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d("TAG", "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w("TAG", "signInWithCredential", task.getException()); Toast.makeText(getActivity(), R.string.error_registration, Toast.LENGTH_SHORT).show(); getActivity().finish(); } else { registerUserInDatabase(); if (listener != null) { Bundle bundle = new Bundle(); listener.onFragmentInteraction(Constants.SIGN_UP_FRAGMENT, bundle); } else { getActivity().finish(); } } } }); }
private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); auth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { signInStatusMessage("Facebook authentication failed."); signOut(); } } }); }
@ReactMethod public void reauthenticateWithCredentialForProvider(final String provider, final String authToken, final String authSecret, final Callback callback) { AuthCredential credential; if (provider.equals("facebook")) { credential = FacebookAuthProvider.getCredential(authToken); } else if (provider.equals("google")) { credential = GoogleAuthProvider.getCredential(authToken, null); } else if (provider.equals("twitter")) { credential = TwitterAuthProvider.getCredential(authToken, authSecret); } else { // TODO: FirestackUtils.todoNote(TAG, "reauthenticateWithCredentialForProvider", callback); // AuthCredential credential; // Log.d(TAG, "reauthenticateWithCredentialForProvider called with: " + provider); return; } FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user != null) { user.reauthenticate(credential) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "User re-authenticated with " + provider); FirebaseUser u = FirebaseAuth.getInstance().getCurrentUser(); userCallback(u, callback); } else { // userErrorCallback(task, callback); } } }); } else { WritableMap err = Arguments.createMap(); err.putInt("errorCode", NO_CURRENT_USER); err.putString("errorMessage", "No current user"); callback.invoke(err); } }
private void onSuccess(LoginResult loginResult, @Nullable String email, String name, Uri photoUri) { gcCallbackManager(); mCallbackObject.onSuccess(new IdpResponse.Builder( new User.Builder(FacebookAuthProvider.PROVIDER_ID, email) .setName(name) .setPhotoUri(photoUri) .build()) .setToken(loginResult.getAccessToken().getToken()) .build()); }