Search in sources :

Example 26 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project BloodHub by kazijehangir.

the class AppointmentsOrgFragment method fetchData.

// Getting data from database
public void fetchData() {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    db.orderByChild("orgid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            appointments.clear();
            keys.clear();
            for (DataSnapshot child : dataSnapshot.getChildren()) {
                Appointment appointment = child.getValue(Appointment.class);
                appointments.add(appointment);
                keys.add(child.getKey());
            }
            numAppointments.setText("Appointments: " + appointments.size());
            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return;
}
Also used : Appointment(com.jexapps.bloodhub.m_Model.Appointment) DatabaseError(com.google.firebase.database.DatabaseError) FirebaseUser(com.google.firebase.auth.FirebaseUser) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 27 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project BloodHub by kazijehangir.

the class MyRequestsFragment method fetchData.

// Getting data from database
public void fetchData() {
    requests = new ArrayList<BloodRequest>();
    keys = new ArrayList<String>();
    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            requests.clear();
            keys.clear();
            for (DataSnapshot child : dataSnapshot.getChildren()) {
                BloodRequest request = child.getValue(BloodRequest.class);
                requests.add(request);
                keys.add(child.getKey());
            }
            numRequests.setText("Total Requests: " + requests.size());
            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return;
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) FirebaseUser(com.google.firebase.auth.FirebaseUser) ValueEventListener(com.google.firebase.database.ValueEventListener) BloodRequest(com.jexapps.bloodhub.m_Model.BloodRequest) DataSnapshot(com.google.firebase.database.DataSnapshot) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 28 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project FirebaseAuth-Android by jirawatee.

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);
    mImageView = findViewById(R.id.logo);
    mTextViewProfile = findViewById(R.id.profile);
    findViewById(R.id.button_twitter_signout).setOnClickListener(this);
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            updateUI(user);
        }
    };
    // initialize_twitter_login
    mLoginButton = 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);
        }
    });
}
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 29 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project FirebaseAuth-Android by jirawatee.

the class FacebookLoginActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_facebook);
    mImageView = findViewById(R.id.logo);
    mTextViewProfile = findViewById(R.id.profile);
    findViewById(R.id.button_facebook_signout).setOnClickListener(this);
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            updateUI(user);
        }
    };
    // Initialize Facebook Login button
    mCallbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = findViewById(R.id.button_facebook_login);
    loginButton.setReadPermissions("email", "public_profile");
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "facebook:onCancel");
            updateUI(null);
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, "facebook:onError", error);
            updateUI(null);
        }
    });
}
Also used : FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) LoginButton(com.facebook.login.widget.LoginButton) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 30 with FirebaseAuth

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

the class AuthUI method delete.

/**
 * Delete the use from FirebaseAuth and delete any associated credentials from the Credentials
 * API. Returns a {@link Task} that succeeds if the Firebase Auth user deletion succeeds and
 * fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
 * silently.
 *
 * @param context the calling {@link Context}.
 */
@NonNull
public Task<Void> delete(@NonNull final Context context) {
    final FirebaseUser currentUser = mAuth.getCurrentUser();
    if (currentUser == null) {
        return Tasks.forException(new FirebaseAuthInvalidUserException(String.valueOf(CommonStatusCodes.SIGN_IN_REQUIRED), "No currently signed in user."));
    }
    final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
    // Ensure the order in which tasks are executed properly destructures the user.
    return signOutIdps(context).continueWithTask(task -> {
        // Propagate exception if there was one
        task.getResult();
        if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
            Log.w(TAG, "Google Play services not available during delete");
            return Tasks.forResult((Void) null);
        }
        final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
        List<Task<?>> credentialTasks = new ArrayList<>();
        for (Credential credential : credentials) {
            credentialTasks.add(client.delete(credential));
        }
        return Tasks.whenAll(credentialTasks).continueWith(task1 -> {
            Exception e = task1.getException();
            Throwable t = e == null ? null : e.getCause();
            if (!(t instanceof ApiException) || ((ApiException) t).getStatusCode() != CommonStatusCodes.CANCELED) {
                // doesn't mean fully deleting the user failed.
                return task1.getResult();
            }
            return null;
        });
    }).continueWithTask(task -> {
        // Propagate exception if there was one
        task.getResult();
        return currentUser.delete();
    });
}
Also used : Scope(com.google.android.gms.common.api.Scope) Arrays(java.util.Arrays) Bundle(android.os.Bundle) UserInfo(com.google.firebase.auth.UserInfo) NonNull(androidx.annotation.NonNull) GoogleApiUtils(com.firebase.ui.auth.util.GoogleApiUtils) DrawableRes(androidx.annotation.DrawableRes) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider) GoogleAuthProvider(com.google.firebase.auth.GoogleAuthProvider) GoogleSignIn(com.google.android.gms.auth.api.signin.GoogleSignIn) RestrictTo(androidx.annotation.RestrictTo) Locale(java.util.Locale) Map(java.util.Map) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ProviderAvailability(com.firebase.ui.auth.util.data.ProviderAvailability) Log(android.util.Log) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) IdentityHashMap(java.util.IdentityHashMap) FirebaseAuthProvider(com.google.firebase.auth.FirebaseAuthProvider) FirebaseUser(com.google.firebase.auth.FirebaseUser) Set(java.util.Set) FacebookAuthProvider(com.google.firebase.auth.FacebookAuthProvider) CredentialRequest(com.google.android.gms.auth.api.credentials.CredentialRequest) StyleRes(androidx.annotation.StyleRes) LoginManager(com.facebook.login.LoginManager) FlowParameters(com.firebase.ui.auth.data.model.FlowParameters) Preconditions(com.firebase.ui.auth.util.Preconditions) List(java.util.List) Tasks(com.google.android.gms.tasks.Tasks) Nullable(androidx.annotation.Nullable) AuthResult(com.google.firebase.auth.AuthResult) PhoneNumberUtils(com.firebase.ui.auth.util.data.PhoneNumberUtils) ApiException(com.google.android.gms.common.api.ApiException) Context(android.content.Context) ProviderUtils(com.firebase.ui.auth.util.data.ProviderUtils) GithubAuthProvider(com.google.firebase.auth.GithubAuthProvider) Intent(android.content.Intent) ExtraConstants(com.firebase.ui.auth.util.ExtraConstants) TwitterAuthProvider(com.google.firebase.auth.TwitterAuthProvider) HashMap(java.util.HashMap) Parcel(android.os.Parcel) Task(com.google.android.gms.tasks.Task) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AuthMethodPickerActivity(com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity) CredentialUtils(com.firebase.ui.auth.util.CredentialUtils) CredentialsClient(com.google.android.gms.auth.api.credentials.CredentialsClient) StringDef(androidx.annotation.StringDef) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) Parcelable(android.os.Parcelable) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) TextUtils(android.text.TextUtils) CallSuper(androidx.annotation.CallSuper) CommonStatusCodes(com.google.android.gms.common.api.CommonStatusCodes) AuthCredential(com.google.firebase.auth.AuthCredential) Credential(com.google.android.gms.auth.api.credentials.Credential) EmailAuthProvider(com.google.firebase.auth.EmailAuthProvider) Collections(java.util.Collections) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) FirebaseApp(com.google.firebase.FirebaseApp) RetentionPolicy(java.lang.annotation.RetentionPolicy) CredentialsClient(com.google.android.gms.auth.api.credentials.CredentialsClient) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) AuthCredential(com.google.firebase.auth.AuthCredential) Credential(com.google.android.gms.auth.api.credentials.Credential) List(java.util.List) ArrayList(java.util.ArrayList) FirebaseUser(com.google.firebase.auth.FirebaseUser) ApiException(com.google.android.gms.common.api.ApiException) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) ApiException(com.google.android.gms.common.api.ApiException) NonNull(androidx.annotation.NonNull)

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