use of com.google.firebase.auth.AuthResult 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.AuthResult in project quickstart-android by firebase.
the class AnonymousAuthActivity method linkAccount.
private void linkAccount() {
// Make sure form is valid
if (!validateLinkForm()) {
return;
}
// Get email and password from form
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
// Create EmailAuthCredential with email and password
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
// Link the anonymous user to the email credential
showProgressDialog();
// [START link_credential]
mAuth.getCurrentUser().linkWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "linkWithCredential:onComplete:" + task.isSuccessful());
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
// [END link_credential]
}
use of com.google.firebase.auth.AuthResult in project RSAndroidApp by RailwayStations.
the class SignInActivity method firebaseAuthWithGoogle.
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + 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());
// 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 {
((BaseApplication) getApplication()).saveSubscribtionStatus(true);
startActivity(new Intent(SignInActivity.this, AuthActivity.class));
finish();
}
}
});
}
use of com.google.firebase.auth.AuthResult in project quickstart-android by firebase.
the class FacebookLoginActivity method handleFacebookAccessToken.
// [END on_activity_result]
// [START auth_with_facebook]
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());
// 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]
}
});
}
use of com.google.firebase.auth.AuthResult in project quickstart-android by firebase.
the class MainActivity method signInAnonymously.
private void signInAnonymously() {
// Sign in anonymously. Authentication is required to read or write from Firebase Storage.
showProgressDialog(getString(R.string.progress_auth));
mAuth.signInAnonymously().addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
Log.d(TAG, "signInAnonymously:SUCCESS");
hideProgressDialog();
updateUI(authResult.getUser());
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(TAG, "signInAnonymously:FAILURE", exception);
hideProgressDialog();
updateUI(null);
}
});
}
Aggregations