Skip to content

Commit aed4e88

Browse files
committed
wip: clear credman state after signOut and UserDeletion
1 parent 7231cf5 commit aed4e88

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

+28-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.content.Context;
1818
import android.content.Intent;
1919
import android.os.Bundle;
20+
import android.os.CancellationSignal;
2021
import android.os.Parcel;
2122
import android.os.Parcelable;
2223
import android.text.TextUtils;
@@ -32,6 +33,7 @@
3233
import com.firebase.ui.auth.util.data.PhoneNumberUtils;
3334
import com.firebase.ui.auth.util.data.ProviderAvailability;
3435
import com.firebase.ui.auth.util.data.ProviderUtils;
36+
import com.google.android.gms.auth.api.identity.Identity;
3537
import com.google.android.gms.auth.api.signin.GoogleSignIn;
3638
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
3739
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
@@ -68,6 +70,7 @@
6870
import java.util.Locale;
6971
import java.util.Map;
7072
import java.util.Set;
73+
import java.util.concurrent.Executors;
7174

7275
import androidx.annotation.CallSuper;
7376
import androidx.annotation.DrawableRes;
@@ -76,6 +79,9 @@
7679
import androidx.annotation.RestrictTo;
7780
import androidx.annotation.StringDef;
7881
import androidx.annotation.StyleRes;
82+
import androidx.credentials.ClearCredentialStateRequest;
83+
import androidx.credentials.CredentialManagerCallback;
84+
import androidx.credentials.exceptions.ClearCredentialException;
7985

8086
/**
8187
* The entry point to the AuthUI authentication flow, and related utility methods. If your
@@ -281,6 +287,26 @@ public Task<Void> signOut(@NonNull Context context) {
281287
Log.w(TAG, "Google Play services not available during signOut");
282288
}
283289

290+
// TODO(thatfiredev): add this logic to delete() too
291+
ClearCredentialStateRequest clearRequest = new ClearCredentialStateRequest();
292+
GoogleApiUtils.getCredentialManager(context)
293+
.clearCredentialStateAsync(
294+
clearRequest,
295+
new CancellationSignal(),
296+
Executors.newSingleThreadExecutor(),
297+
new CredentialManagerCallback<>() {
298+
@Override
299+
public void onResult(Void unused) {
300+
301+
}
302+
303+
@Override
304+
public void onError(@NonNull ClearCredentialException e) {
305+
306+
}
307+
}
308+
);
309+
284310
return signOutIdps(context).continueWith(task -> {
285311
task.getResult(); // Propagate exceptions if any.
286312
mAuth.signOut();
@@ -342,11 +368,8 @@ private Task<Void> signOutIdps(@NonNull Context context) {
342368
if (ProviderAvailability.IS_FACEBOOK_AVAILABLE) {
343369
LoginManager.getInstance().logOut();
344370
}
345-
if (GoogleApiUtils.isPlayServicesAvailable(context)) {
346-
return GoogleSignIn.getClient(context, GoogleSignInOptions.DEFAULT_SIGN_IN).signOut();
347-
} else {
348-
return Tasks.forResult((Void) null);
349-
}
371+
// TODO(thatfiredev): This doesn't need to be a Task anymore
372+
return Tasks.forResult((Void) null);
350373
}
351374

352375
/**

auth/src/main/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivity.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import androidx.credentials.exceptions.GetCredentialException
8686
import com.firebase.ui.auth.AuthUI.EMAIL_LINK_PROVIDER
8787
import com.firebase.ui.auth.util.ExtraConstants.GENERIC_OAUTH_BUTTON_ID
8888
import com.firebase.ui.auth.util.ExtraConstants.GENERIC_OAUTH_PROVIDER_ID
89+
import com.firebase.ui.auth.util.GoogleApiUtils
8990
import com.google.android.libraries.identity.googleid.GetGoogleIdOption
9091
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
9192
import com.google.android.libraries.identity.googleid.GoogleIdTokenParsingException
@@ -105,7 +106,7 @@ class AuthMethodPickerActivity : AppCompatBase() {
105106
// For demonstration, assume that CredentialManager provides a create() method.
106107
private val credentialManager by lazy {
107108
// Replace with your actual CredentialManager instance creation.
108-
CredentialManager.create(this)
109+
GoogleApiUtils.getCredentialManager(this)
109110
}
110111

111112
companion object {

auth/src/main/java/com/firebase/ui/auth/util/GoogleApiUtils.java

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import androidx.annotation.NonNull;
1111
import androidx.annotation.RestrictTo;
12+
import androidx.credentials.CredentialManager;
1213

1314
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
1415
public final class GoogleApiUtils {
@@ -25,4 +26,9 @@ public static boolean isPlayServicesAvailable(@NonNull Context context) {
2526
public static SignInClient getSignInClient(@NonNull Context context) {
2627
return Identity.getSignInClient(context);
2728
}
29+
30+
@NonNull
31+
public static CredentialManager getCredentialManager(@NonNull Context context) {
32+
return CredentialManager.create(context);
33+
}
2834
}

auth/src/main/java/com/firebase/ui/auth/viewmodel/credentialmanager/CredentialManagerHandler.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import android.app.Application
44
import android.content.Context
55
import androidx.lifecycle.viewModelScope
66
import androidx.credentials.CreatePasswordRequest
7-
import androidx.credentials.CredentialManager
87
import androidx.credentials.CreateCredentialResponse
98
import androidx.credentials.exceptions.CreateCredentialException
109
import com.firebase.ui.auth.ErrorCodes
1110
import com.firebase.ui.auth.FirebaseUiException
1211
import com.firebase.ui.auth.IdpResponse
1312
import com.firebase.ui.auth.data.model.Resource
13+
import com.firebase.ui.auth.util.GoogleApiUtils
1414
import com.firebase.ui.auth.viewmodel.AuthViewModelBase
1515
import com.google.firebase.auth.FirebaseUser
1616
import kotlinx.coroutines.launch
1717

1818
class CredentialManagerHandler(application: Application) :
1919
AuthViewModelBase<IdpResponse>(application) {
2020

21-
private val credentialManager = CredentialManager.create(application)
21+
private val credentialManager = GoogleApiUtils.getCredentialManager(application)
2222
private var response: IdpResponse? = null
2323

2424
fun setResponse(newResponse: IdpResponse) {

0 commit comments

Comments
 (0)