Skip to content

Commit de3f6fe

Browse files
committed
upgrade play-services-auth to 21.2.0
This removes all the smartlock/credentials functionality from the library.
1 parent bab9313 commit de3f6fe

35 files changed

+205
-765
lines changed

app/build.gradle.kts

+10
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ dependencies {
8383
implementation(Config.Libs.Androidx.cardView)
8484
implementation(Config.Libs.Androidx.customTabs)
8585

86+
// Found this on StackOverflow: https://stackoverflow.com/a/75298544/5861618
87+
constraints {
88+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
89+
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
90+
}
91+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
92+
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
93+
}
94+
}
95+
8696
implementation(Config.Libs.Misc.glide)
8797
annotationProcessor(Config.Libs.Misc.glideCompiler)
8898

auth/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ dependencies {
7373
implementation(Config.Libs.Androidx.customTabs)
7474
implementation(Config.Libs.Androidx.constraint)
7575

76-
implementation(Config.Libs.Androidx.lifecycleExtensions)
7776
annotationProcessor(Config.Libs.Androidx.lifecycleCompiler)
7877

7978
implementation(platform(Config.Libs.Firebase.bom))

auth/src/main/AndroidManifest.xml

-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@
3939
android:exported="false"
4040
android:theme="@style/FirebaseUI.Transparent" />
4141

42-
<activity
43-
android:name=".ui.credentials.CredentialSaveActivity"
44-
android:label=""
45-
android:exported="false"
46-
android:theme="@style/FirebaseUI.Transparent" />
47-
4842
<activity
4943
android:name=".ui.email.RecoverPasswordActivity"
5044
android:label="@string/fui_title_recover_password_activity"

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

+83-112
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,17 @@
1919
import android.os.Bundle;
2020
import android.os.Parcel;
2121
import android.os.Parcelable;
22-
import android.text.TextUtils;
2322
import android.util.Log;
2423

2524
import com.facebook.login.LoginManager;
2625
import com.firebase.ui.auth.data.model.FlowParameters;
2726
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
28-
import com.firebase.ui.auth.util.CredentialUtils;
2927
import com.firebase.ui.auth.util.ExtraConstants;
3028
import com.firebase.ui.auth.util.GoogleApiUtils;
3129
import com.firebase.ui.auth.util.Preconditions;
3230
import com.firebase.ui.auth.util.data.PhoneNumberUtils;
3331
import com.firebase.ui.auth.util.data.ProviderAvailability;
3432
import com.firebase.ui.auth.util.data.ProviderUtils;
35-
import com.google.android.gms.auth.api.credentials.Credential;
36-
import com.google.android.gms.auth.api.credentials.CredentialRequest;
37-
import com.google.android.gms.auth.api.credentials.CredentialsClient;
3833
import com.google.android.gms.auth.api.signin.GoogleSignIn;
3934
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
4035
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
@@ -45,7 +40,6 @@
4540
import com.google.android.gms.tasks.Tasks;
4641
import com.google.firebase.FirebaseApp;
4742
import com.google.firebase.auth.ActionCodeSettings;
48-
import com.google.firebase.auth.AuthCredential;
4943
import com.google.firebase.auth.AuthResult;
5044
import com.google.firebase.auth.EmailAuthProvider;
5145
import com.google.firebase.auth.FacebookAuthProvider;
@@ -269,34 +263,6 @@ public static int getDefaultTheme() {
269263
return R.style.FirebaseUI_DefaultMaterialTheme;
270264
}
271265

272-
/**
273-
* Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials, not
274-
* for saving since we don't have access to the password.
275-
*/
276-
private static List<Credential> getCredentialsFromFirebaseUser(@NonNull FirebaseUser user) {
277-
if (TextUtils.isEmpty(user.getEmail()) && TextUtils.isEmpty(user.getPhoneNumber())) {
278-
return Collections.emptyList();
279-
}
280-
281-
List<Credential> credentials = new ArrayList<>();
282-
for (UserInfo userInfo : user.getProviderData()) {
283-
if (FirebaseAuthProvider.PROVIDER_ID.equals(userInfo.getProviderId())) {
284-
continue;
285-
}
286-
287-
String type = ProviderUtils.providerIdToAccountType(userInfo.getProviderId());
288-
if (type == null) {
289-
// Since the account type is null, we've got an email credential. Adding a fake
290-
// password is the only way to tell Smart Lock that this is an email credential.
291-
credentials.add(CredentialUtils.buildCredentialOrThrow(user, "pass", null));
292-
} else {
293-
credentials.add(CredentialUtils.buildCredentialOrThrow(user, null, type));
294-
}
295-
}
296-
297-
return credentials;
298-
}
299-
300266
/**
301267
* Signs the user in without any UI if possible. If this operation fails, you can safely start a
302268
* UI-based sign-in flow knowing it is required.
@@ -339,43 +305,44 @@ public Task<AuthResult> silentSignIn(@NonNull Context context,
339305
}
340306

341307
// If Play services are not available we can't attempt to use the credentials client.
342-
if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
308+
// if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
309+
// TODO(hackathon): figure out if we want to do silent sign in or not.
343310
return Tasks.forException(
344311
new FirebaseUiException(ErrorCodes.PLAY_SERVICES_UPDATE_CANCELLED));
345-
}
346-
347-
return GoogleApiUtils.getCredentialsClient(context)
348-
.request(new CredentialRequest.Builder()
349-
// We can support both email and Google at the same time here because they
350-
// are mutually exclusive. If a user signs in with Google, their email
351-
// account will automatically be upgraded (a.k.a. replaced) with the Google
352-
// one, meaning Smart Lock won't have to show the picker UI.
353-
.setPasswordLoginSupported(email != null)
354-
.setAccountTypes(google == null ? null :
355-
ProviderUtils.providerIdToAccountType(GoogleAuthProvider
356-
.PROVIDER_ID))
357-
.build())
358-
.continueWithTask(task -> {
359-
Credential credential = task.getResult().getCredential();
360-
String email1 = credential.getId();
361-
String password = credential.getPassword();
362-
363-
if (TextUtils.isEmpty(password)) {
364-
return GoogleSignIn.getClient(appContext,
365-
new GoogleSignInOptions.Builder(googleOptions)
366-
.setAccountName(email1)
367-
.build())
368-
.silentSignIn()
369-
.continueWithTask(task1 -> {
370-
AuthCredential authCredential = GoogleAuthProvider
371-
.getCredential(
372-
task1.getResult().getIdToken(), null);
373-
return mAuth.signInWithCredential(authCredential);
374-
});
375-
} else {
376-
return mAuth.signInWithEmailAndPassword(email1, password);
377-
}
378-
});
312+
// }
313+
314+
// return GoogleApiUtils.getCredentialsClient(context)
315+
// .request(new CredentialRequest.Builder()
316+
// // We can support both email and Google at the same time here because they
317+
// // are mutually exclusive. If a user signs in with Google, their email
318+
// // account will automatically be upgraded (a.k.a. replaced) with the Google
319+
// // one, meaning Smart Lock won't have to show the picker UI.
320+
// .setPasswordLoginSupported(email != null)
321+
// .setAccountTypes(google == null ? null :
322+
// ProviderUtils.providerIdToAccountType(GoogleAuthProvider
323+
// .PROVIDER_ID))
324+
// .build())
325+
// .continueWithTask(task -> {
326+
// Credential credential = task.getResult().getCredential();
327+
// String email1 = credential.getId();
328+
// String password = credential.getPassword();
329+
//
330+
// if (TextUtils.isEmpty(password)) {
331+
// return GoogleSignIn.getClient(appContext,
332+
// new GoogleSignInOptions.Builder(googleOptions)
333+
// .setAccountName(email1)
334+
// .build())
335+
// .silentSignIn()
336+
// .continueWithTask(task1 -> {
337+
// AuthCredential authCredential = GoogleAuthProvider
338+
// .getCredential(
339+
// task1.getResult().getIdToken(), null);
340+
// return mAuth.signInWithCredential(authCredential);
341+
// });
342+
// } else {
343+
// return mAuth.signInWithEmailAndPassword(email1, password);
344+
// }
345+
// });
379346
}
380347

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

396-
Task<Void> maybeDisableAutoSignIn = playServicesAvailable
397-
? GoogleApiUtils.getCredentialsClient(context).disableAutoSignIn()
398-
: Tasks.forResult((Void) null);
399-
400-
maybeDisableAutoSignIn
401-
.continueWith(task -> {
402-
// We want to ignore a specific exception, since it's not a good reason
403-
// to fail (see Issue 1156).
404-
Exception e = task.getException();
405-
if (e instanceof ApiException
406-
&& ((ApiException) e).getStatusCode() == CommonStatusCodes
407-
.CANCELED) {
408-
Log.w(TAG, "Could not disable auto-sign in, maybe there are no " +
409-
"SmartLock accounts available?", e);
410-
return null;
411-
}
412-
413-
return task.getResult();
414-
});
363+
// TODO(hackathon) : disable auto sign in ?
364+
// Task<Void> maybeDisableAutoSignIn = playServicesAvailable
365+
// ? GoogleApiUtils.getCredentialsClient(context).disableAutoSignIn()
366+
// : Tasks.forResult((Void) null);
367+
368+
// maybeDisableAutoSignIn
369+
// .continueWith(task -> {
370+
// // We want to ignore a specific exception, since it's not a good reason
371+
// // to fail (see Issue 1156).
372+
// Exception e = task.getException();
373+
// if (e instanceof ApiException
374+
// && ((ApiException) e).getStatusCode() == CommonStatusCodes
375+
// .CANCELED) {
376+
// Log.w(TAG, "Could not disable auto-sign in, maybe there are no " +
377+
// "SmartLock accounts available?", e);
378+
// return null;
379+
// }
380+
//
381+
// return task.getResult();
382+
// });
415383

416384
return Tasks.whenAll(
417-
signOutIdps(context),
418-
maybeDisableAutoSignIn
385+
signOutIdps(context)
386+
// maybeDisableAutoSignIn
419387
).continueWith(task -> {
420388
task.getResult(); // Propagate exceptions
421389
mAuth.signOut();
@@ -440,7 +408,8 @@ public Task<Void> delete(@NonNull final Context context) {
440408
"No currently signed in user."));
441409
}
442410

443-
final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
411+
// TODO(hackathon): Fetch the credentials for this user
412+
// final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
444413

445414
// Ensure the order in which tasks are executed properly destructures the user.
446415
return signOutIdps(context).continueWithTask(task -> {
@@ -451,27 +420,29 @@ public Task<Void> delete(@NonNull final Context context) {
451420
return Tasks.forResult((Void) null);
452421
}
453422

454-
final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
455-
List<Task<?>> credentialTasks = new ArrayList<>();
456-
for (Credential credential : credentials) {
457-
credentialTasks.add(client.delete(credential));
458-
}
459-
return Tasks.whenAll(credentialTasks)
460-
.continueWith(task1 -> {
461-
Exception e = task1.getException();
462-
Throwable t = e == null ? null : e.getCause();
463-
if (!(t instanceof ApiException)
464-
|| ((ApiException) t).getStatusCode() !=
465-
CommonStatusCodes.CANCELED) {
466-
// Only propagate the exception if it isn't an invalid account
467-
// one. This can occur if we failed to save the credential or it
468-
// was deleted elsewhere. However, a lack of stored credential
469-
// doesn't mean fully deleting the user failed.
470-
return task1.getResult();
471-
}
472-
473-
return null;
474-
});
423+
// TODO(hackathon): Fetch the credentials for this user
424+
// final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
425+
// List<Task<?>> credentialTasks = new ArrayList<>();
426+
// for (Credential credential : credentials) {
427+
// credentialTasks.add(client.delete(credential));
428+
// }
429+
// return Tasks.whenAll(credentialTasks)
430+
// .continueWith(task1 -> {
431+
// Exception e = task1.getException();
432+
// Throwable t = e == null ? null : e.getCause();
433+
// if (!(t instanceof ApiException)
434+
// || ((ApiException) t).getStatusCode() !=
435+
// CommonStatusCodes.CANCELED) {
436+
// // Only propagate the exception if it isn't an invalid account
437+
// // one. This can occur if we failed to save the credential or it
438+
// // was deleted elsewhere. However, a lack of stored credential
439+
// // doesn't mean fully deleting the user failed.
440+
// return task1.getResult();
441+
// }
442+
//
443+
// return null;
444+
// });
445+
return null;
475446
}).continueWithTask(task -> {
476447
task.getResult(); // Propagate exception if there was one
477448
return currentUser.delete();

0 commit comments

Comments
 (0)