use of com.google.firebase.auth.FirebaseAuth in project FirebaseUI-Android by firebase.
the class AuthUiActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseAuth auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null) {
startActivity(SignedInActivity.createIntent(this, null));
finish();
}
setContentView(R.layout.auth_ui_layout);
ButterKnife.bind(this);
if (!isGoogleConfigured()) {
mUseGoogleProvider.setChecked(false);
mUseGoogleProvider.setEnabled(false);
mUseGoogleProvider.setText(R.string.google_label_missing_config);
setGoogleScopesEnabled(false);
} else {
setGoogleScopesEnabled(mUseGoogleProvider.isChecked());
mUseGoogleProvider.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
setGoogleScopesEnabled(checked);
}
});
}
if (!isFacebookConfigured()) {
mUseFacebookProvider.setChecked(false);
mUseFacebookProvider.setEnabled(false);
mUseFacebookProvider.setText(R.string.facebook_label_missing_config);
setFacebookScopesEnabled(false);
} else {
setFacebookScopesEnabled(mUseFacebookProvider.isChecked());
mUseFacebookProvider.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
setFacebookScopesEnabled(checked);
}
});
}
if (!isTwitterConfigured()) {
mUseTwitterProvider.setChecked(false);
mUseTwitterProvider.setEnabled(false);
mUseTwitterProvider.setText(R.string.twitter_label_missing_config);
}
if (!isGoogleConfigured() || !isFacebookConfigured() || !isTwitterConfigured()) {
showSnackbar(R.string.configuration_required);
}
}
use of com.google.firebase.auth.FirebaseAuth in project FirebaseUI-Android by firebase.
the class CredentialSignInHandlerTest method testSignInFailed_withFacebookAlreadyLinked.
@Test
public void testSignInFailed_withFacebookAlreadyLinked() {
AppCompatBase mockActivity = mock(AppCompatBase.class);
ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
FirebaseAuth mockFirebaseAuth = mock(FirebaseAuth.class);
IdpResponse idpResponse = new IdpResponse(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL);
CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(mockActivity, mockActivityHelper, null, RC_ACCOUNT_LINK, idpResponse);
FlowParameters mockFlowParams = mock(FlowParameters.class);
when(mockActivityHelper.getFirebaseAuth()).thenReturn(mockFirebaseAuth);
when(mockActivityHelper.getFlowParams()).thenReturn(mockFlowParams);
// pretend the account has Facebook linked already
when(mockFirebaseAuth.fetchProvidersForEmail(TestConstants.EMAIL)).thenReturn(new AutoCompleteTask<ProviderQueryResult>(new FakeProviderQueryResult(Arrays.asList(FacebookAuthProvider.PROVIDER_ID)), true, null));
// pretend there was already an account with this email
Task exceptionTask = Tasks.forException(new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));
credentialSignInHandler.onComplete(exceptionTask);
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
Intent capturedIntent = intentCaptor.getValue();
User capturedUser = User.getUser(capturedIntent);
assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue());
assertEquals(WelcomeBackIdpPrompt.class.getName(), capturedIntent.getComponent().getClassName());
assertEquals(TestConstants.EMAIL, capturedUser.getEmail());
assertEquals(FacebookAuthProvider.PROVIDER_ID, capturedUser.getProvider());
}
use of com.google.firebase.auth.FirebaseAuth 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.FirebaseAuth in project SocialRec by Jkuras.
the class StoreActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_store);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
public static final String TAG = "";
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
mfirebaseUser = firebaseAuth.getCurrentUser();
if (mfirebaseUser != null) {
// User is signed in
// when the user changes, change the database ref too
setStore();
// TODO: If user is signed in, add "hello, userName" or something to the toolbar
Log.d(TAG, "onAuthStateChanged:signed_in:" + mfirebaseUser.getUid());
} else {
// User is signed out
// if the user is signed out, set mUser to null to avoid reading or writing
// from the last users database
mStore = null;
}
}
};
// if the user does not change, but someone is signed in, set the User
setStore();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
use of com.google.firebase.auth.FirebaseAuth in project Grupp by tmoronta1208.
the class CreateProfileFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(com.example.c4q.capstone.R.layout.fragment_create_profile, container, false);
// saveBtn = rootView.findViewById(R.id.create_profile_save_button);
ageGroup = rootView.findViewById(R.id.radio_group_age);
budgetGroup = rootView.findViewById(R.id.radio_group_budget);
radiusGroup = rootView.findViewById(R.id.radio_group_radius);
firstName = rootView.findViewById(R.id.edit_profile_firstname);
lastName = rootView.findViewById(R.id.edit_profile_lastname);
zipCode = rootView.findViewById(R.id.edit_profile_zip_code);
rootRef = FirebaseDatabase.getInstance().getReference();
publicUserReference = rootRef.child(PUBLIC_USER);
privateUserReference = rootRef.child(PRIVATE_USER);
privateUserLocationReference = rootRef.child(PRIVATE_USER);
userIconReference = rootRef.child(USER_ICON);
mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();
currentUserID = currentUser.getUid();
currentUserEmail = currentUser.getEmail();
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
privateUser = dataSnapshot.child(currentUserID).getValue(PrivateUser.class);
privateUserLocation = dataSnapshot.child(currentUserID).getValue(PrivateUserLocation.class);
publicUser = dataSnapshot.child(currentUserID).getValue(PublicUser.class);
userIcon = dataSnapshot.child(currentUserID).getValue(UserIcon.class);
Log.d(TAG, "onDataChange: Added information to database: \n" + dataSnapshot.getValue());
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());
}
};
publicUserReference.addValueEventListener(valueEventListener);
privateUserReference.addValueEventListener(valueEventListener);
privateUserLocationReference.addValueEventListener(valueEventListener);
userIconReference.addValueEventListener(valueEventListener);
saveBtn = rootView.findViewById(R.id.create_profile_save_button);
radioGroupSelection();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (currentUser != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + currentUser.getUid());
// Toast.makeText(EditProfileActivity.this, "Successfully signed in with: " + currentUser.getEmail(), Toast.LENGTH_SHORT).show();
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
// Toast.makeText(EditProfileActivity.this, "Successfully signed out.", Toast.LENGTH_SHORT).show();
}
}
};
saveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveToDatabase();
}
});
return rootView;
}
Aggregations