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"));
}
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());
}
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;
}
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]
}
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);
}
Aggregations