19
19
import android .os .Bundle ;
20
20
import android .os .Parcel ;
21
21
import android .os .Parcelable ;
22
- import android .text .TextUtils ;
23
22
import android .util .Log ;
24
23
25
24
import com .facebook .login .LoginManager ;
26
25
import com .firebase .ui .auth .data .model .FlowParameters ;
27
26
import com .firebase .ui .auth .ui .idp .AuthMethodPickerActivity ;
28
- import com .firebase .ui .auth .util .CredentialUtils ;
29
27
import com .firebase .ui .auth .util .ExtraConstants ;
30
28
import com .firebase .ui .auth .util .GoogleApiUtils ;
31
29
import com .firebase .ui .auth .util .Preconditions ;
32
30
import com .firebase .ui .auth .util .data .PhoneNumberUtils ;
33
31
import com .firebase .ui .auth .util .data .ProviderAvailability ;
34
32
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
33
import com .google .android .gms .auth .api .signin .GoogleSignIn ;
39
34
import com .google .android .gms .auth .api .signin .GoogleSignInAccount ;
40
35
import com .google .android .gms .auth .api .signin .GoogleSignInOptions ;
45
40
import com .google .android .gms .tasks .Tasks ;
46
41
import com .google .firebase .FirebaseApp ;
47
42
import com .google .firebase .auth .ActionCodeSettings ;
48
- import com .google .firebase .auth .AuthCredential ;
49
43
import com .google .firebase .auth .AuthResult ;
50
44
import com .google .firebase .auth .EmailAuthProvider ;
51
45
import com .google .firebase .auth .FacebookAuthProvider ;
@@ -269,34 +263,6 @@ public static int getDefaultTheme() {
269
263
return R .style .FirebaseUI_DefaultMaterialTheme ;
270
264
}
271
265
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
266
/**
301
267
* Signs the user in without any UI if possible. If this operation fails, you can safely start a
302
268
* UI-based sign-in flow knowing it is required.
@@ -339,43 +305,44 @@ public Task<AuthResult> silentSignIn(@NonNull Context context,
339
305
}
340
306
341
307
// 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.
343
310
return Tasks .forException (
344
311
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
+ // });
379
346
}
380
347
381
348
/**
@@ -393,29 +360,30 @@ public Task<Void> signOut(@NonNull Context context) {
393
360
Log .w (TAG , "Google Play services not available during signOut" );
394
361
}
395
362
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
+ // });
415
383
416
384
return Tasks .whenAll (
417
- signOutIdps (context ),
418
- maybeDisableAutoSignIn
385
+ signOutIdps (context )
386
+ // maybeDisableAutoSignIn
419
387
).continueWith (task -> {
420
388
task .getResult (); // Propagate exceptions
421
389
mAuth .signOut ();
@@ -440,7 +408,8 @@ public Task<Void> delete(@NonNull final Context context) {
440
408
"No currently signed in user." ));
441
409
}
442
410
443
- final List <Credential > credentials = getCredentialsFromFirebaseUser (currentUser );
411
+ // TODO(hackathon): Fetch the credentials for this user
412
+ // final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
444
413
445
414
// Ensure the order in which tasks are executed properly destructures the user.
446
415
return signOutIdps (context ).continueWithTask (task -> {
@@ -451,27 +420,29 @@ public Task<Void> delete(@NonNull final Context context) {
451
420
return Tasks .forResult ((Void ) null );
452
421
}
453
422
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 ;
475
446
}).continueWithTask (task -> {
476
447
task .getResult (); // Propagate exception if there was one
477
448
return currentUser .delete ();
0 commit comments