Skip to content

Commit

Permalink
upgrade play-services-auth to 21.2.0
Browse files Browse the repository at this point in the history
This removes all the smartlock/credentials functionality from the library.
  • Loading branch information
thatfiredev committed Aug 21, 2024
1 parent bab9313 commit de3f6fe
Show file tree
Hide file tree
Showing 35 changed files with 205 additions and 765 deletions.
10 changes: 10 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ dependencies {
implementation(Config.Libs.Androidx.cardView)
implementation(Config.Libs.Androidx.customTabs)

// Found this on StackOverflow: https://stackoverflow.com/a/75298544/5861618
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
}
}

implementation(Config.Libs.Misc.glide)
annotationProcessor(Config.Libs.Misc.glideCompiler)

Expand Down
1 change: 0 additions & 1 deletion auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ dependencies {
implementation(Config.Libs.Androidx.customTabs)
implementation(Config.Libs.Androidx.constraint)

implementation(Config.Libs.Androidx.lifecycleExtensions)
annotationProcessor(Config.Libs.Androidx.lifecycleCompiler)

implementation(platform(Config.Libs.Firebase.bom))
Expand Down
6 changes: 0 additions & 6 deletions auth/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
android:exported="false"
android:theme="@style/FirebaseUI.Transparent" />

<activity
android:name=".ui.credentials.CredentialSaveActivity"
android:label=""
android:exported="false"
android:theme="@style/FirebaseUI.Transparent" />

<activity
android:name=".ui.email.RecoverPasswordActivity"
android:label="@string/fui_title_recover_password_activity"
Expand Down
195 changes: 83 additions & 112 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;

import com.facebook.login.LoginManager;
import com.firebase.ui.auth.data.model.FlowParameters;
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
import com.firebase.ui.auth.util.CredentialUtils;
import com.firebase.ui.auth.util.ExtraConstants;
import com.firebase.ui.auth.util.GoogleApiUtils;
import com.firebase.ui.auth.util.Preconditions;
import com.firebase.ui.auth.util.data.PhoneNumberUtils;
import com.firebase.ui.auth.util.data.ProviderAvailability;
import com.firebase.ui.auth.util.data.ProviderUtils;
import com.google.android.gms.auth.api.credentials.Credential;
import com.google.android.gms.auth.api.credentials.CredentialRequest;
import com.google.android.gms.auth.api.credentials.CredentialsClient;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
Expand All @@ -45,7 +40,6 @@
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.ActionCodeSettings;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.EmailAuthProvider;
import com.google.firebase.auth.FacebookAuthProvider;
Expand Down Expand Up @@ -269,34 +263,6 @@ public static int getDefaultTheme() {
return R.style.FirebaseUI_DefaultMaterialTheme;
}

/**
* Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials, not
* for saving since we don't have access to the password.
*/
private static List<Credential> getCredentialsFromFirebaseUser(@NonNull FirebaseUser user) {
if (TextUtils.isEmpty(user.getEmail()) && TextUtils.isEmpty(user.getPhoneNumber())) {
return Collections.emptyList();
}

List<Credential> credentials = new ArrayList<>();
for (UserInfo userInfo : user.getProviderData()) {
if (FirebaseAuthProvider.PROVIDER_ID.equals(userInfo.getProviderId())) {
continue;
}

String type = ProviderUtils.providerIdToAccountType(userInfo.getProviderId());
if (type == null) {
// Since the account type is null, we've got an email credential. Adding a fake
// password is the only way to tell Smart Lock that this is an email credential.
credentials.add(CredentialUtils.buildCredentialOrThrow(user, "pass", null));
} else {
credentials.add(CredentialUtils.buildCredentialOrThrow(user, null, type));
}
}

return credentials;
}

/**
* Signs the user in without any UI if possible. If this operation fails, you can safely start a
* UI-based sign-in flow knowing it is required.
Expand Down Expand Up @@ -339,43 +305,44 @@ public Task<AuthResult> silentSignIn(@NonNull Context context,
}

// If Play services are not available we can't attempt to use the credentials client.
if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
// if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
// TODO(hackathon): figure out if we want to do silent sign in or not.
return Tasks.forException(
new FirebaseUiException(ErrorCodes.PLAY_SERVICES_UPDATE_CANCELLED));
}

return GoogleApiUtils.getCredentialsClient(context)
.request(new CredentialRequest.Builder()
// We can support both email and Google at the same time here because they
// are mutually exclusive. If a user signs in with Google, their email
// account will automatically be upgraded (a.k.a. replaced) with the Google
// one, meaning Smart Lock won't have to show the picker UI.
.setPasswordLoginSupported(email != null)
.setAccountTypes(google == null ? null :
ProviderUtils.providerIdToAccountType(GoogleAuthProvider
.PROVIDER_ID))
.build())
.continueWithTask(task -> {
Credential credential = task.getResult().getCredential();
String email1 = credential.getId();
String password = credential.getPassword();

if (TextUtils.isEmpty(password)) {
return GoogleSignIn.getClient(appContext,
new GoogleSignInOptions.Builder(googleOptions)
.setAccountName(email1)
.build())
.silentSignIn()
.continueWithTask(task1 -> {
AuthCredential authCredential = GoogleAuthProvider
.getCredential(
task1.getResult().getIdToken(), null);
return mAuth.signInWithCredential(authCredential);
});
} else {
return mAuth.signInWithEmailAndPassword(email1, password);
}
});
// }

// return GoogleApiUtils.getCredentialsClient(context)
// .request(new CredentialRequest.Builder()
// // We can support both email and Google at the same time here because they
// // are mutually exclusive. If a user signs in with Google, their email
// // account will automatically be upgraded (a.k.a. replaced) with the Google
// // one, meaning Smart Lock won't have to show the picker UI.
// .setPasswordLoginSupported(email != null)
// .setAccountTypes(google == null ? null :
// ProviderUtils.providerIdToAccountType(GoogleAuthProvider
// .PROVIDER_ID))
// .build())
// .continueWithTask(task -> {
// Credential credential = task.getResult().getCredential();
// String email1 = credential.getId();
// String password = credential.getPassword();
//
// if (TextUtils.isEmpty(password)) {
// return GoogleSignIn.getClient(appContext,
// new GoogleSignInOptions.Builder(googleOptions)
// .setAccountName(email1)
// .build())
// .silentSignIn()
// .continueWithTask(task1 -> {
// AuthCredential authCredential = GoogleAuthProvider
// .getCredential(
// task1.getResult().getIdToken(), null);
// return mAuth.signInWithCredential(authCredential);
// });
// } else {
// return mAuth.signInWithEmailAndPassword(email1, password);
// }
// });
}

/**
Expand All @@ -393,29 +360,30 @@ public Task<Void> signOut(@NonNull Context context) {
Log.w(TAG, "Google Play services not available during signOut");
}

Task<Void> maybeDisableAutoSignIn = playServicesAvailable
? GoogleApiUtils.getCredentialsClient(context).disableAutoSignIn()
: Tasks.forResult((Void) null);

maybeDisableAutoSignIn
.continueWith(task -> {
// We want to ignore a specific exception, since it's not a good reason
// to fail (see Issue 1156).
Exception e = task.getException();
if (e instanceof ApiException
&& ((ApiException) e).getStatusCode() == CommonStatusCodes
.CANCELED) {
Log.w(TAG, "Could not disable auto-sign in, maybe there are no " +
"SmartLock accounts available?", e);
return null;
}

return task.getResult();
});
// TODO(hackathon) : disable auto sign in ?
// Task<Void> maybeDisableAutoSignIn = playServicesAvailable
// ? GoogleApiUtils.getCredentialsClient(context).disableAutoSignIn()
// : Tasks.forResult((Void) null);

// maybeDisableAutoSignIn
// .continueWith(task -> {
// // We want to ignore a specific exception, since it's not a good reason
// // to fail (see Issue 1156).
// Exception e = task.getException();
// if (e instanceof ApiException
// && ((ApiException) e).getStatusCode() == CommonStatusCodes
// .CANCELED) {
// Log.w(TAG, "Could not disable auto-sign in, maybe there are no " +
// "SmartLock accounts available?", e);
// return null;
// }
//
// return task.getResult();
// });

return Tasks.whenAll(
signOutIdps(context),
maybeDisableAutoSignIn
signOutIdps(context)
// maybeDisableAutoSignIn
).continueWith(task -> {
task.getResult(); // Propagate exceptions
mAuth.signOut();
Expand All @@ -440,7 +408,8 @@ public Task<Void> delete(@NonNull final Context context) {
"No currently signed in user."));
}

final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
// TODO(hackathon): Fetch the credentials for this user
// final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);

// Ensure the order in which tasks are executed properly destructures the user.
return signOutIdps(context).continueWithTask(task -> {
Expand All @@ -451,27 +420,29 @@ public Task<Void> delete(@NonNull final Context context) {
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) {
// Only propagate the exception if it isn't an invalid account
// one. This can occur if we failed to save the credential or it
// was deleted elsewhere. However, a lack of stored credential
// doesn't mean fully deleting the user failed.
return task1.getResult();
}

return null;
});
// TODO(hackathon): Fetch the credentials for this user
// 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) {
// // Only propagate the exception if it isn't an invalid account
// // one. This can occur if we failed to save the credential or it
// // was deleted elsewhere. However, a lack of stored credential
// // doesn't mean fully deleting the user failed.
// return task1.getResult();
// }
//
// return null;
// });
return null;
}).continueWithTask(task -> {
task.getResult(); // Propagate exception if there was one
return currentUser.delete();
Expand Down
Loading

0 comments on commit de3f6fe

Please sign in to comment.