Search in sources :

Example 6 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.

the class AuthMethodPickerActivityTest method testTwitterLoginFlowStarts.

@Test
@Config(shadows = { ActivityHelperShadow.class })
public void testTwitterLoginFlowStarts() {
    List<String> providers = Arrays.asList(AuthUI.TWITTER_PROVIDER);
    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(TwitterAuthProvider.PROVIDER_ID));
    when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    Button twitterButton = (Button) authMethodPickerActivity.findViewById(R.id.twitter_button);
    assertNotNull(twitterButton);
    twitterButton.performClick();
    ShadowActivity.IntentForResult nextIntent = Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
    assertTrue(nextIntent.intent.getComponent().getClassName().contains("com.twitter.sdk"));
}
Also used : Button(android.widget.Button) ShadowActivity(org.robolectric.shadows.ShadowActivity) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Example 7 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.

the class CredentialSignInHandlerTest method testSignInSucceeded.

@Test
public void testSignInSucceeded() {
    AppCompatBase mockActivity = mock(AppCompatBase.class);
    ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    IdpResponse idpResponse = new IdpResponse(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL);
    SaveSmartLock smartLock = mock(SaveSmartLock.class);
    CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(mockActivity, mockActivityHelper, smartLock, RC_ACCOUNT_LINK, idpResponse);
    Task signInTask = Tasks.forResult(new FakeAuthResult(mockFirebaseUser));
    when(mockActivityHelper.getFlowParams()).thenReturn(TestHelper.getFlowParameters(Collections.<String>emptyList()));
    credentialSignInHandler.onComplete(signInTask);
    ArgumentCaptor<SaveSmartLock> smartLockCaptor = ArgumentCaptor.forClass(SaveSmartLock.class);
    ArgumentCaptor<Activity> activityCaptor = ArgumentCaptor.forClass(Activity.class);
    ArgumentCaptor<FirebaseUser> firebaseUserCaptor = ArgumentCaptor.forClass(FirebaseUser.class);
    ArgumentCaptor<IdpResponse> idpResponseCaptor = ArgumentCaptor.forClass(IdpResponse.class);
    verify(mockActivityHelper).saveCredentialsOrFinish(smartLockCaptor.capture(), activityCaptor.capture(), firebaseUserCaptor.capture(), idpResponseCaptor.capture());
    assertEquals(smartLock, smartLockCaptor.getValue());
    assertEquals(mockActivity, activityCaptor.getValue());
    assertEquals(mockFirebaseUser, firebaseUserCaptor.getValue());
    assertEquals(idpResponse.getProviderType(), idpResponseCaptor.getValue().getProviderType());
    assertEquals(idpResponse.getEmail(), idpResponseCaptor.getValue().getEmail());
    assertEquals(idpResponse.getIdpToken(), idpResponseCaptor.getValue().getIdpToken());
    assertEquals(idpResponse.getIdpSecret(), idpResponseCaptor.getValue().getIdpSecret());
}
Also used : Task(com.google.android.gms.tasks.Task) AutoCompleteTask(com.firebase.ui.auth.testhelpers.AutoCompleteTask) AppCompatBase(com.firebase.ui.auth.ui.AppCompatBase) Activity(android.app.Activity) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) ActivityHelper(com.firebase.ui.auth.ui.ActivityHelper) SaveSmartLock(com.firebase.ui.auth.util.signincontainer.SaveSmartLock) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 8 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.

the class TestHelper method makeMockFirebaseUser.

public static FirebaseUser makeMockFirebaseUser() {
    FirebaseUser mockFirebaseUser = mock(FirebaseUser.class);
    when(mockFirebaseUser.getEmail()).thenReturn(TestConstants.EMAIL);
    when(mockFirebaseUser.getDisplayName()).thenReturn(TestConstants.NAME);
    when(mockFirebaseUser.getPhotoUrl()).thenReturn(TestConstants.PHOTO_URI);
    return mockFirebaseUser;
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 9 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project quickstart-android by firebase.

the class TwitterLoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Configure Twitter SDK
    TwitterAuthConfig authConfig = new TwitterAuthConfig(getString(R.string.twitter_consumer_key), getString(R.string.twitter_consumer_secret));
    Fabric.with(this, new Twitter(authConfig));
    // Inflate layout (must be done after Twitter is configured)
    setContentView(R.layout.activity_twitter);
    // Views
    mStatusTextView = (TextView) findViewById(R.id.status);
    mDetailTextView = (TextView) findViewById(R.id.detail);
    findViewById(R.id.button_twitter_signout).setOnClickListener(this);
    // [START initialize_auth]
    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();
    // [END initialize_auth]
    // [START auth_state_listener]
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            // [START_EXCLUDE]
            updateUI(user);
        // [END_EXCLUDE]
        }
    };
    // [END auth_state_listener]
    // [START initialize_twitter_login]
    mLoginButton = (TwitterLoginButton) findViewById(R.id.button_twitter_login);
    mLoginButton.setCallback(new Callback<TwitterSession>() {

        @Override
        public void success(Result<TwitterSession> result) {
            Log.d(TAG, "twitterLogin:success" + result);
            handleTwitterSession(result.data);
        }

        @Override
        public void failure(TwitterException exception) {
            Log.w(TAG, "twitterLogin:failure", exception);
            updateUI(null);
        }
    });
// [END initialize_twitter_login]
}
Also used : TwitterSession(com.twitter.sdk.android.core.TwitterSession) Twitter(com.twitter.sdk.android.Twitter) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig) FirebaseUser(com.google.firebase.auth.FirebaseUser) TwitterException(com.twitter.sdk.android.core.TwitterException) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 10 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project SocialRec by Jkuras.

the class SignIn_SignUp method onStart.

// [START on_start_check_user]
@Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
    updateUI(currentUser);
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Aggregations

FirebaseUser (com.google.firebase.auth.FirebaseUser)26 AuthResult (com.google.firebase.auth.AuthResult)7 Button (android.widget.Button)6 FakeAuthResult (com.firebase.ui.auth.testhelpers.FakeAuthResult)6 BuildConfig (com.firebase.ui.auth.BuildConfig)5 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)5 Test (org.junit.Test)5 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)4 Config (org.robolectric.annotation.Config)4 NonNull (android.support.annotation.NonNull)3 EditText (android.widget.EditText)3 ActivityHelperShadow (com.firebase.ui.auth.testhelpers.ActivityHelperShadow)3 TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)3 Task (com.google.android.gms.tasks.Task)3 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)3 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Bitmap (android.graphics.Bitmap)2 IdpResponse (com.firebase.ui.auth.IdpResponse)2 FirebaseAuthWeakPasswordException (com.google.firebase.auth.FirebaseAuthWeakPasswordException)2