Java Code Examples for com.google.firebase.auth.AuthResult

The following examples show how to use com.google.firebase.auth.AuthResult. These examples are extracted from open source projects. 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 Project: LuxVilla   Source File: Loginactivity.java    License: 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 2
Source Project: geofire-android   Source File: GeoFireTestingRule.java    License: 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 3
Source Project: RxFirebase   Source File: RxFirebaseUserTests.java    License: 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
private void handleAnonymousUpgradeLinkingFlow(final HelperActivityBase activity,
                                               final OAuthProvider provider,
                                               final FlowParameters flowParameters) {
    AuthOperationManager.getInstance().safeGenericIdpSignIn(activity, provider, flowParameters)
            .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult authResult) {
                    // Pass the credential so we can sign-in on the after the merge
                    // conflict is resolved.
                    handleSuccess(provider.getProviderId(),
                            authResult.getUser(), (OAuthCredential) authResult.getCredential(),
                            /* setPendingCredential= */true);
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    setResult(Resource.<IdpResponse>forFailure(e));
                }
            });

}
 
Example 5
Source Project: wmn-safety   Source File: SigninActivity.java    License: MIT License 6 votes vote down vote up
private void loginWithFirebaseEmailPassword(String email, String password) {
    mHelpers.showProgressDialog(getString(R.string.loading_msg));
    mFirebaseAuth.signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    mHelpers.hideProgressDialog();
                    if (task.isSuccessful()) {
                        mHelpers.showToast(getString(R.string.login_success));
                        onSignInSuccess();
                    } else {
                        Log.w("Sign in failed", task.getException().toString());
                        mHelpers.showAlertDialog(getString(R.string.error_message), task.getException().getMessage()).show();
                    }
                }
            });
}
 
Example 6
Source Project: wmn-safety   Source File: SigninActivity.java    License: 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 Project: NaviBee   Source File: LoginActivity.java    License: 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 8
Source Project: budgetto   Source File: SignInActivity.java    License: MIT License 6 votes vote down vote up
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    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()) {
                        FirebaseUser user = mAuth.getCurrentUser();
                        updateUI(user);
                    } else {
                        loginError("Firebase auth failed.");
                        hideProgressView();
                    }
                }
            });
}
 
Example 9
Source Project: logregform-android   Source File: RegistrationActivity.java    License: MIT License 6 votes vote down vote up
private void registerUser(final String inputName, final String inputPw, String inputEmail) {

        progressDialog.setMessage("Verificating...");
        progressDialog.show();


            firebaseAuth.createUserWithEmailAndPassword(inputEmail,inputPw).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if(task.isSuccessful()){
                        progressDialog.dismiss();
                        sendUserData(inputName, inputPw);
                        Toast.makeText(RegistrationActivity.this,"You've been registered successfully.",Toast.LENGTH_SHORT).show();
                        startActivity(new Intent(RegistrationActivity.this,MainActivity.class));
                    }
                    else{
                        progressDialog.dismiss();
                        Toast.makeText(RegistrationActivity.this,"Email already exists.",Toast.LENGTH_SHORT).show();
                    }
                }
            });

    }
 
Example 10
Source Project: logregform-android   Source File: LoginActivity.java    License: MIT License 6 votes vote down vote up
public void signUser(String email, String password){

        progressDialog.setMessage("Verificating...");
        progressDialog.show();

        firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if(task.isSuccessful()){
                    progressDialog.dismiss();
                    Toast.makeText(LoginActivity.this,"Login Successful",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(LoginActivity.this,MainActivity.class));
                }
                else{
                    progressDialog.dismiss();
                    Toast.makeText(LoginActivity.this,"Invalid email or password",Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
 
Example 11
Source Project: react-native-firestack   Source File: FirestackAuth.java    License: 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 12
Source Project: RxFirebase   Source File: RxFirebaseAuthTests.java    License: 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 13
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 14
Source Project: kute   Source File: SplashActivity.java    License: 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 15
Source Project: friendlypix-android   Source File: ProfileActivity.java    License: 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 16
Source Project: friendlypix-android   Source File: WelcomeActivity.java    License: 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 17
Source Project: react-native-firestack   Source File: FirestackAuth.java    License: 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 18
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 19
Source Project: Expert-Android-Programming   Source File: SignInBaseActivity.java    License: 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 20
Source Project: Crimson   Source File: SaveReports.java    License: 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 21
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 22
Source Project: react-native-firestack   Source File: FirestackAuth.java    License: 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 23
Source Project: firebase-chat   Source File: LoginInteractor.java    License: 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 24
@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 25
@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 26
Source Project: RxFirebase   Source File: RxFirebaseAuthTests.java    License: 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 27
Source Project: RxFirebase   Source File: RxFirebaseAuthTests.java    License: 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 28
Source Project: snippets-android   Source File: ReferralActivity.java    License: 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 29
Source Project: snippets-android   Source File: MainActivity.java    License: 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 30
Source Project: snippets-android   Source File: MainActivity.java    License: 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]
}