com.google.firebase.auth.AuthResult Java Examples

The following examples show how to use com.google.firebase.auth.AuthResult. 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: BaseAuthActivity.java    From MangoBloggerAndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
        Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {
                            hideProgressDialog();
                            // Sign in success, update UI with the signed-in user's information
                            Log.d(TAG, "signInWithCredential:success");
//                            FirebaseUser user = mAuth.getCurrentUser();
                            startApp();
                        } else {
                            hideProgressDialog();
                            // If sign in fails, display a message to the user.
                            Log.w(TAG, "signInWithCredential:failure", task.getException());
                            Toast.makeText(BaseAuthActivity.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        }

                        // ...
                    }
                });
    }
 
Example #2
Source File: FirestackAuth.java    From react-native-firestack with MIT License 6 votes vote down vote up
@ReactMethod
public void signInAnonymously(final Callback callback) {
    mAuth = FirebaseAuth.getInstance();

    mAuth.signInAnonymously()
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful());

                    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);
            }
          });
}
 
Example #3
Source File: RxFirebaseUserTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void linkWithCredential()  {

    TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>();
    RxFirebaseUser.linkWithCredential(mockUser, credential)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(authResult);
    testOnCompleteListener.getValue().onComplete(mockAuthResultTask);

    verify(mockUser).linkWithCredential(credential);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(authResult));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example #4
Source File: GeoFireTestingRule.java    From geofire-android with Apache License 2.0 6 votes vote down vote up
public void before(Context context) throws Exception {
    if (FirebaseApp.getApps(context).isEmpty()) {
        FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
                .setApplicationId("1:1010498001935:android:f17a2f247ad8e8bc")
                .setApiKey("AIzaSyBys-YxxE7kON5PxZc5aY6JwVvreyx_owc")
                .setDatabaseUrl(databaseUrl)
                .build();
        FirebaseApp.initializeApp(context, firebaseOptions);
        FirebaseDatabase.getInstance().setLogLevel(Logger.Level.DEBUG);
    }

    if (FirebaseAuth.getInstance().getCurrentUser() == null) {
        Task<AuthResult> signInTask = TaskUtils.waitForTask(FirebaseAuth.getInstance().signInAnonymously());
        if (signInTask.isSuccessful()) {
            Log.d(TAG, "Signed in as " + signInTask.getResult().getUser());
        } else {
            throw new Exception("Failed to sign in: " + signInTask.getException());
        }
    }

    this.databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl(databaseUrl);
}
 
Example #5
Source File: LoginActivity.java    From NaviBee with GNU General Public License v3.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
//        Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        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");
                            checkSignIn();
                        } else {
                            // If sign in fails, display a message to the user.
                            Toast.makeText(LoginActivity.this, "Sign in fails", Toast.LENGTH_LONG).show();
                        }

                    }
                });
    }
 
Example #6
Source File: SigninActivity.java    From wmn-safety with MIT License 6 votes vote down vote up
private void firebaseAuthWithGoogle(final GoogleSignInAccount account) {
    AuthCredential mCredential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
    mFirebaseAuth.signInWithCredential(mCredential)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        String email = account.getEmail();
                        String name = account.getDisplayName();
                        String userID = mFirebaseAuth.getCurrentUser().getUid();
                        boolean newUser = task.getResult().getAdditionalUserInfo().isNewUser();
                        addNewUser(email, name, "", userID, newUser);
                    } else {
                        Log.w(TAG, task.getException().toString());
                        Toast.makeText(SigninActivity.this, task.getException().toString(), Toast.LENGTH_SHORT)
                                .show();
                    }
                }
            });
}
 
Example #7
Source File: RxFirebaseAuthTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void signInWithCustomToken()  {

    TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>();
    RxFirebaseAuth.signInWithCustomToken(mockAuth, "token")
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(mockAuthResult);
    testOnCompleteListener.getValue().onComplete(mockAuthTask);

    verify(mockAuth).signInWithCustomToken(eq("token"));

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(mockAuthResult));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example #8
Source File: ChatSignUpActivity.java    From chat21-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
private void createUserOnFirebaseAuthentication(final String email,
                                                    final String password,
                                                    final OnUserCreatedOnFirebaseCallback onUserCreatedOnFirebaseCallback) {
        mAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(ChatSignUpActivity.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
//                        Toast.makeText(ChatSignUpActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
                        progressBar.setVisibility(View.GONE);
                        // 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()) {
                            onUserCreatedOnFirebaseCallback.onUserCreatedError(task.getException());
                        } else {
                            // user created with success
                            FirebaseUser firebaseUser = mAuth.getCurrentUser(); // retrieve the created user
                            onUserCreatedOnFirebaseCallback.onUserCreatedSuccess(firebaseUser.getUid());
                        }
                    }
                });
    }
 
Example #9
Source File: SplashActivity.java    From kute with Apache License 2.0 6 votes vote down vote up
public void doRegister(String uname,String pwd){
    Log.e(TAG,uname+" "+pwd);
    mAuth.createUserWithEmailAndPassword(uname, pwd)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "createUserWithEmail: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()) {
                        Toast.makeText(getApplicationContext(), "Registration failed",
                                Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(getApplicationContext(), "You have successfully Registered",
                                Toast.LENGTH_SHORT).show();
                    }

                    // ...
                }
            });
}
 
Example #10
Source File: ProfileActivity.java    From friendlypix-android with Apache License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    showProgressDialog(getString(R.string.profile_progress_message));
    mAuth.signInWithCredential(credential)
            .addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult result) {
                    handleFirebaseAuthResult(result);
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    FirebaseCrash.logcat(Log.ERROR, TAG, "auth:onFailure:" + e.getMessage());
                    handleFirebaseAuthResult(null);
                }
            });
}
 
Example #11
Source File: WelcomeActivity.java    From friendlypix-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    int id = v.getId();
    switch (id) {
        case R.id.explore_button:
            mAuth.signInAnonymously().addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult authResult) {
                    Intent feedsIntent = new Intent(WelcomeActivity.this, FeedsActivity.class);
                    startActivity(feedsIntent);
                }
            }).addOnFailureListener( new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(WelcomeActivity.this, "Unable to sign in anonymously.",
                            Toast.LENGTH_SHORT).show();
                        Log.e(TAG, e.getMessage());
                }
            });
            break;
        case R.id.sign_in_button:
            Intent signInIntent = new Intent(this, ProfileActivity.class);
            startActivity(signInIntent);
            break;
    }
}
 
Example #12
Source File: FirestackAuth.java    From react-native-firestack with MIT License 6 votes vote down vote up
@ReactMethod
public void signInWithEmail(final String email, final String password, final Callback callback) {
    mAuth = FirebaseAuth.getInstance();

    mAuth.signInWithEmailAndPassword(email, password)
      .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) {
            Log.e(TAG, "An exception occurred: " + ex.getMessage());
            userExceptionCallback(ex, callback);
          }
        });
}
 
Example #13
Source File: SignInActivity.java    From codelab-friendlychat-android with Apache License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mFirebaseAuth.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(SignInActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    } else {
                        startActivity(new Intent(SignInActivity.this, MainActivity.class));
                        finish();
                    }
                }
            });
}
 
Example #14
Source File: SignInBaseActivity.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    MyLg.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()+" "+acct.getPhotoUrl());
    showProgressDialog();

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    MyLg.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()) {
                        MyLg.w(TAG, "signInWithCredential");
                        Toas.show(context, "Authentication failed.");
                    }
                    hideProgressDialog();
                }
            });
}
 
Example #15
Source File: SaveReports.java    From Crimson with Apache License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {

        Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

        showProgressDialog();

        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                        if (!task.isSuccessful()) {
                            Log.w(TAG, "signInWithCredential", task.getException());
                            Toast.makeText(SaveReports.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        }
                        hideProgressDialog();
                    }
                });
    }
 
Example #16
Source File: Loginactivity.java    From LuxVilla with Apache License 2.0 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    firebaseAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    // 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()) {
                        Snackbar.make(linearLayout,"Ocorreu um erro ao conectar", Snackbar.LENGTH_LONG).show();
                    } else {
                        startActivity(new Intent(Loginactivity.this, MainActivity.class));
                        finish();
                    }
                }
            });
}
 
Example #17
Source File: FirestackAuth.java    From react-native-firestack with MIT License 6 votes vote down vote up
@ReactMethod
public void googleLogin(String IdToken, final Callback callback) {
    mAuth = FirebaseAuth.getInstance();

    AuthCredential credential = GoogleAuthProvider.getCredential(IdToken, null);
    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);
          }
        });
}
 
Example #18
Source File: LoginInteractor.java    From firebase-chat with MIT License 6 votes vote down vote up
@Override
public void performFirebaseLogin(final Activity activity, final String email, String password) {
    FirebaseAuth.getInstance()
            .signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "performFirebaseLogin: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()) {
                        mOnLoginListener.onSuccess(task.getResult().toString());
                        updateFirebaseToken(task.getResult().getUser().getUid(),
                                new SharedPrefUtil(activity.getApplicationContext()).getString(Constants.ARG_FIREBASE_TOKEN, null));
                    } else {
                        mOnLoginListener.onFailure(task.getException().getMessage());
                    }
                }
            });
}
 
Example #19
Source File: LoginInteractor.java    From FirebaseMessagingApp with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void performFirebaseLogin(final Activity activity, final String email, String password) {
    FirebaseAuth.getInstance()
            .signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "performFirebaseLogin: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()) {
                        mOnLoginListener.onSuccess(task.getResult().toString());
                        updateFirebaseToken(task.getResult().getUser().getUid(),
                                new SharedPrefUtil(activity.getApplicationContext()).getString(Constants.ARG_FIREBASE_TOKEN, null));
                    } else {
                        mOnLoginListener.onFailure(task.getException().getMessage());
                    }
                }
            });
}
 
Example #20
Source File: RegisterInteractor.java    From FirebaseMessagingApp with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void performFirebaseRegistration(Activity activity, final String email, String password) {
    FirebaseAuth.getInstance()
            .createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.e(TAG, "performFirebaseRegistration: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()) {
                        mOnRegistrationListener.onFailure(task.getException().getMessage());
                    } else {
                        // Add the user to users table.
                        /*DatabaseReference database= FirebaseDatabase.getInstance().getReference();
                        User user = new User(task.getResult().getUser().getUid(), email);
                        database.child("users").push().setValue(user);*/

                        mOnRegistrationListener.onSuccess(task.getResult().getUser());
                    }
                }
            });
}
 
Example #21
Source File: RxFirebaseAuthTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void signInAnonymously_Failed()  {

    TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>();
    RxFirebaseAuth.signInAnonymously(mockAuth)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    Exception e = new Exception("something bad happened");
    testOnFailureListener.getValue().onFailure(e);

    verify(mockAuth).signInAnonymously();

    testSubscriber.assertError(e);
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example #22
Source File: RxFirebaseAuthTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void signInWithEmailAndPassword()  {

    TestSubscriber<AuthResult> testSubscriber = new TestSubscriber<>();
    RxFirebaseAuth.signInWithEmailAndPassword(mockAuth, "email", "password")
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(mockAuthResult);
    testOnCompleteListener.getValue().onComplete(mockAuthTask);

    verify(mockAuth).signInWithEmailAndPassword(eq("email"), eq("password"));

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(mockAuthResult));
    testSubscriber.assertCompleted();
    testSubscriber.unsubscribe();
}
 
Example #23
Source File: ReferralActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void rewardUser(AuthCredential credential) {
    // [START ddl_referral_reward_user]
    FirebaseAuth.getInstance().getCurrentUser()
            .linkWithCredential(credential)
            .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult authResult) {
                    // Complete any post sign-up tasks here.

                    // Trigger the sign-up reward function by creating the
                    // "last_signin_at" field. (If this is a value you want to track,
                    // you would also update this field in the success listeners of
                    // your Firebase Authentication signIn calls.)
                    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                    DatabaseReference userRecord =
                            FirebaseDatabase.getInstance().getReference()
                                    .child("users")
                                    .child(user.getUid());
                    userRecord.child("last_signin_at").setValue(ServerValue.TIMESTAMP);
                }
            });
    // [END ddl_referral_reward_user]
}
 
Example #24
Source File: MainActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void authWithGithub() {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();

    // [START auth_with_github]
    String token = "<GITHUB-ACCESS-TOKEN>";
    AuthCredential credential = GithubAuthProvider.getCredential(token);
    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();
                    }

                    // ...
                }
            });
    // [END auth_with_github]
}
 
Example #25
Source File: MainActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void unlink(String providerId) {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();

    // [START auth_unlink]
    mAuth.getCurrentUser().unlink(providerId)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Auth provider unlinked from account
                        // ...
                    }
                }
            });
    // [END auth_unlink]
}
 
Example #26
Source File: GenericIdpActivity.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
    updateUI(currentUser);

    // Look for a pending auth result
    Task<AuthResult> pending = mAuth.getPendingAuthResult();
    if (pending != null) {
        pending.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
            @Override
            public void onSuccess(AuthResult authResult) {
                Log.d(TAG, "checkPending:onSuccess:" + authResult);
                updateUI(authResult.getUser());
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "checkPending:onFailure", e);
            }
        });
    } else {
        Log.d(TAG, "checkPending: null");
    }
}
 
Example #27
Source File: MainActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
private void onDeleteAllClicked() {
    FirebaseAuth.getInstance()
            .signInAnonymously()
            .addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult authResult) {
                    Log.d(TAG, "auth:onSuccess");

                    // Delete
                    DocSnippets docSnippets = new DocSnippets(mFirestore);
                    docSnippets.deleteAll();
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.d(TAG, "auth:onFailure", e);
                }
            });
}
 
Example #28
Source File: SocialProviderResponseHandlerTest.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
@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 #29
Source File: SignInActivity.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
private void signIn() {
    Log.d(TAG, "signIn");
    if (!validateForm()) {
        return;
    }

    showProgressBar();
    String email = binding.fieldEmail.getText().toString();
    String password = binding.fieldPassword.getText().toString();

    mAuth.signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signIn:onComplete:" + task.isSuccessful());
                    hideProgressBar();

                    if (task.isSuccessful()) {
                        onAuthSuccess(task.getResult().getUser());
                    } else {
                        Toast.makeText(SignInActivity.this, "Sign In Failed",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });
}
 
Example #30
Source File: FireSignin.java    From Learning-Resources with MIT License 6 votes vote down vote up
private void firebaseAuthWithFacebook(AccessToken accessToken) {

        mPrgrsbrMain.setVisibility(View.VISIBLE);

        LogManager.printLog(LOGTYPE_INFO, "signInWithFacebookToken: " + accessToken);

        AuthCredential credential = FacebookAuthProvider.getCredential(accessToken.getToken());
        mFireAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        LogManager.printLog(LOGTYPE_DEBUG, "signInWithCredential:onComplete:" + task.isSuccessful());

                        if (!task.isSuccessful()) {

                            mPrgrsbrMain.setVisibility(View.GONE);
                            Log.w(LOG_TAG, "signInWithCredential", task.getException());
                            Snackbar.make(mCrdntrlyot, "Authentication failed.\n" + task.getException().getMessage(),
                                    Snackbar.LENGTH_LONG).show();
                        } else
                            successLoginGetData(task);
                    }
                });
    }