Search in sources :

Example 1 with FirebaseAuth

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);
    }
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) CompoundButton(android.widget.CompoundButton) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 2 with FirebaseAuth

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());
}
Also used : Task(com.google.android.gms.tasks.Task) AutoCompleteTask(com.firebase.ui.auth.testhelpers.AutoCompleteTask) FirebaseUser(com.google.firebase.auth.FirebaseUser) User(com.firebase.ui.auth.ui.User) AppCompatBase(com.firebase.ui.auth.ui.AppCompatBase) Intent(android.content.Intent) FakeProviderQueryResult(com.firebase.ui.auth.testhelpers.FakeProviderQueryResult) ProviderQueryResult(com.google.firebase.auth.ProviderQueryResult) ActivityHelper(com.firebase.ui.auth.ui.ActivityHelper) FlowParameters(com.firebase.ui.auth.ui.FlowParameters) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) WelcomeBackIdpPrompt(com.firebase.ui.auth.ui.accountlink.WelcomeBackIdpPrompt) FakeProviderQueryResult(com.firebase.ui.auth.testhelpers.FakeProviderQueryResult) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Example 3 with FirebaseAuth

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]
}
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 4 with FirebaseAuth

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);
}
Also used : FirebaseAuth(com.google.firebase.auth.FirebaseAuth) Toolbar(android.support.v7.widget.Toolbar)

Example 5 with FirebaseAuth

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;
}
Also used : PrivateUser(com.example.c4q.capstone.database.privateuserdata.PrivateUser) PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) DatabaseError(com.google.firebase.database.DatabaseError) PrivateUserLocation(com.example.c4q.capstone.database.privateuserdata.PrivateUserLocation) UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Aggregations

FirebaseAuth (com.google.firebase.auth.FirebaseAuth)32 FirebaseUser (com.google.firebase.auth.FirebaseUser)20 Intent (android.content.Intent)11 DataSnapshot (com.google.firebase.database.DataSnapshot)8 DatabaseError (com.google.firebase.database.DatabaseError)8 View (android.view.View)7 ValueEventListener (com.google.firebase.database.ValueEventListener)7 AuthResult (com.google.firebase.auth.AuthResult)6 IdpResponse (com.firebase.ui.auth.IdpResponse)5 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)5 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)4 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 RestrictTo (androidx.annotation.RestrictTo)3 AuthCredential (com.google.firebase.auth.AuthCredential)3 Application (android.app.Application)2 Bundle (android.os.Bundle)2 TextView (android.widget.TextView)2 FacebookException (com.facebook.FacebookException)2 LoginResult (com.facebook.login.LoginResult)2