32
32
import com .firebase .ui .auth .util .data .PhoneNumberUtils ;
33
33
import com .firebase .ui .auth .util .data .ProviderAvailability ;
34
34
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 ;
38
35
import com .google .android .gms .auth .api .signin .GoogleSignIn ;
39
36
import com .google .android .gms .auth .api .signin .GoogleSignInAccount ;
40
37
import com .google .android .gms .auth .api .signin .GoogleSignInOptions ;
@@ -269,115 +266,6 @@ public static int getDefaultTheme() {
269
266
return R .style .FirebaseUI_DefaultMaterialTheme ;
270
267
}
271
268
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
-
300
- /**
301
- * Signs the user in without any UI if possible. If this operation fails, you can safely start a
302
- * UI-based sign-in flow knowing it is required.
303
- *
304
- * @param context requesting the user be signed in
305
- * @param configs to use for silent sign in. Only Google and email are currently supported, the
306
- * rest will be ignored.
307
- * @return a task which indicates whether or not the user was successfully signed in.
308
- */
309
- @ NonNull
310
- public Task <AuthResult > silentSignIn (@ NonNull Context context ,
311
- @ NonNull List <IdpConfig > configs ) {
312
- if (mAuth .getCurrentUser () != null ) {
313
- throw new IllegalArgumentException ("User already signed in!" );
314
- }
315
-
316
- final Context appContext = context .getApplicationContext ();
317
- final IdpConfig google =
318
- ProviderUtils .getConfigFromIdps (configs , GoogleAuthProvider .PROVIDER_ID );
319
- final IdpConfig email =
320
- ProviderUtils .getConfigFromIdps (configs , EmailAuthProvider .PROVIDER_ID );
321
-
322
- if (google == null && email == null ) {
323
- throw new IllegalArgumentException ("No supported providers were supplied. " +
324
- "Add either Google or email support." );
325
- }
326
-
327
- final GoogleSignInOptions googleOptions ;
328
- if (google == null ) {
329
- googleOptions = null ;
330
- } else {
331
- GoogleSignInAccount last = GoogleSignIn .getLastSignedInAccount (appContext );
332
- if (last != null && last .getIdToken () != null ) {
333
- return mAuth .signInWithCredential (GoogleAuthProvider .getCredential (
334
- last .getIdToken (), null ));
335
- }
336
-
337
- googleOptions = google .getParams ()
338
- .getParcelable (ExtraConstants .GOOGLE_SIGN_IN_OPTIONS );
339
- }
340
-
341
- // If Play services are not available we can't attempt to use the credentials client.
342
- if (!GoogleApiUtils .isPlayServicesAvailable (context )) {
343
- return Tasks .forException (
344
- 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
- });
379
- }
380
-
381
269
/**
382
270
* Signs the current user out, if one is signed in.
383
271
*
@@ -393,41 +281,22 @@ public Task<Void> signOut(@NonNull Context context) {
393
281
Log .w (TAG , "Google Play services not available during signOut" );
394
282
}
395
283
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
- });
284
+ Task <Void > maybeDisableAutoSignIn = Tasks .forResult ((Void ) null );
415
285
416
286
return Tasks .whenAll (
417
287
signOutIdps (context ),
418
288
maybeDisableAutoSignIn
419
289
).continueWith (task -> {
420
- task .getResult (); // Propagate exceptions
290
+ task .getResult (); // Propagate exceptions if any.
421
291
mAuth .signOut ();
422
292
return null ;
423
293
});
424
294
}
425
295
426
296
/**
427
- * Delete the use from FirebaseAuth and delete any associated credentials from the Credentials
428
- * API. Returns a {@link Task} that succeeds if the Firebase Auth user deletion succeeds and
429
- * fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
430
- * silently.
297
+ * Delete the user from FirebaseAuth.
298
+ *
299
+ * <p>Any associated saved credentials are not explicitly deleted with the new APIs.
431
300
*
432
301
* @param context the calling {@link Context}.
433
302
*/
@@ -440,40 +309,8 @@ public Task<Void> delete(@NonNull final Context context) {
440
309
"No currently signed in user." ));
441
310
}
442
311
443
- final List <Credential > credentials = getCredentialsFromFirebaseUser (currentUser );
444
-
445
- // Ensure the order in which tasks are executed properly destructures the user.
446
312
return signOutIdps (context ).continueWithTask (task -> {
447
- task .getResult (); // Propagate exception if there was one
448
-
449
- if (!GoogleApiUtils .isPlayServicesAvailable (context )) {
450
- Log .w (TAG , "Google Play services not available during delete" );
451
- return Tasks .forResult ((Void ) null );
452
- }
453
-
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
- });
475
- }).continueWithTask (task -> {
476
- task .getResult (); // Propagate exception if there was one
313
+ task .getResult (); // Propagate exception if there was one.
477
314
return currentUser .delete ();
478
315
});
479
316
}
0 commit comments