23
23
import android .support .annotation .Nullable ;
24
24
import android .support .annotation .StyleRes ;
25
25
import android .support .annotation .VisibleForTesting ;
26
+ import android .support .v4 .app .FragmentActivity ;
26
27
27
28
import com .facebook .login .LoginManager ;
28
29
import com .firebase .ui .auth .ui .FlowParameters ;
29
30
import com .firebase .ui .auth .ui .idp .AuthMethodPickerActivity ;
31
+ import com .firebase .ui .auth .util .CredentialTaskApi ;
30
32
import com .firebase .ui .auth .util .CredentialsApiHelper ;
31
33
import com .firebase .ui .auth .util .GoogleApiClientTaskHelper ;
34
+ import com .firebase .ui .auth .util .GoogleSignInHelper ;
32
35
import com .firebase .ui .auth .util .Preconditions ;
33
36
import com .firebase .ui .auth .util .signincontainer .SmartLockBase ;
34
37
import com .google .android .gms .auth .api .Auth ;
@@ -313,10 +316,12 @@ public static int getDefaultTheme() {
313
316
* Signs the current user out, if one is signed in.
314
317
*
315
318
* @param activity The activity requesting the user be signed out.
316
- * @return a task which, upon completion, signals that the user has been signed out
317
- * ({@code result.isSuccess()}, or that the sign-out attempt failed unexpectedly
318
- * ({@code !result.isSuccess()}).
319
+ * @return a task which, upon completion, signals that the user has been signed out ({@code
320
+ * result.isSuccess()}, or that the sign-out attempt failed unexpectedly ({@code
321
+ * !result.isSuccess()}).
322
+ * @deprecated use {@link #signOut(FragmentActivity)} instead
319
323
*/
324
+ @ Deprecated
320
325
public Task <Void > signOut (@ NonNull Activity activity ) {
321
326
// Get helper for Google Sign In and Credentials API
322
327
GoogleApiClientTaskHelper taskHelper = GoogleApiClientTaskHelper .getInstance (activity );
@@ -325,7 +330,7 @@ public Task<Void> signOut(@NonNull Activity activity) {
325
330
.addApi (Auth .GOOGLE_SIGN_IN_API , GoogleSignInOptions .DEFAULT_SIGN_IN );
326
331
327
332
// Get Credentials Helper
328
- CredentialsApiHelper credentialsHelper = CredentialsApiHelper .getInstance (taskHelper );
333
+ CredentialTaskApi credentialsHelper = CredentialsApiHelper .getInstance (taskHelper );
329
334
330
335
// Firebase Sign out
331
336
mAuth .signOut ();
@@ -359,8 +364,62 @@ public Void then(@NonNull Task<GoogleApiClient> task) throws Exception {
359
364
* silently.
360
365
*
361
366
* @param activity the calling {@link Activity}.
367
+ * @deprecated use {@link #delete(FragmentActivity)} instead
362
368
*/
369
+ @ Deprecated
363
370
public Task <Void > delete (@ NonNull Activity activity ) {
371
+ // Initialize SmartLock helper
372
+ GoogleApiClientTaskHelper gacHelper = GoogleApiClientTaskHelper .getInstance (activity );
373
+ gacHelper .getBuilder ().addApi (Auth .CREDENTIALS_API );
374
+ CredentialTaskApi credentialHelper = CredentialsApiHelper .getInstance (gacHelper );
375
+
376
+ return getDeleteTask (credentialHelper );
377
+ }
378
+
379
+ /**
380
+ * Signs the current user out, if one is signed in.
381
+ *
382
+ * @param activity the activity requesting the user be signed out
383
+ * @return A task which, upon completion, signals that the user has been signed out ({@link
384
+ * Task#isSuccessful()}, or that the sign-out attempt failed unexpectedly !{@link
385
+ * Task#isSuccessful()}).
386
+ */
387
+ public Task <Void > signOut (@ NonNull FragmentActivity activity ) {
388
+ // Get Credentials Helper
389
+ GoogleSignInHelper credentialsHelper = GoogleSignInHelper .getInstance (activity );
390
+
391
+ // Firebase Sign out
392
+ mAuth .signOut ();
393
+
394
+ // Disable credentials auto sign-in
395
+ Task <Status > disableCredentialsTask = credentialsHelper .disableAutoSignIn ();
396
+
397
+ // Google sign out
398
+ Task <Status > signOutTask = credentialsHelper .signOut ();
399
+
400
+ // Facebook sign out
401
+ LoginManager .getInstance ().logOut ();
402
+
403
+ // Wait for all tasks to complete
404
+ return Tasks .whenAll (disableCredentialsTask , signOutTask );
405
+ }
406
+
407
+ /**
408
+ * Delete the use from FirebaseAuth and delete any associated credentials from the Credentials
409
+ * API. Returns a {@link Task} that succeeds if the Firebase Auth user deletion succeeds and
410
+ * fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
411
+ * silently.
412
+ *
413
+ * @param activity the calling {@link Activity}.
414
+ */
415
+ public Task <Void > delete (@ NonNull FragmentActivity activity ) {
416
+ // Initialize SmartLock helper
417
+ CredentialTaskApi credentialHelper = GoogleSignInHelper .getInstance (activity );
418
+
419
+ return getDeleteTask (credentialHelper );
420
+ }
421
+
422
+ private Task <Void > getDeleteTask (CredentialTaskApi credentialHelper ) {
364
423
FirebaseUser firebaseUser = FirebaseAuth .getInstance ().getCurrentUser ();
365
424
if (firebaseUser == null ) {
366
425
// If the current user is null, return a failed task immediately
@@ -370,11 +429,6 @@ public Task<Void> delete(@NonNull Activity activity) {
370
429
// Delete the Firebase user
371
430
Task <Void > deleteUserTask = firebaseUser .delete ();
372
431
373
- // Initialize SmartLock helper
374
- GoogleApiClientTaskHelper gacHelper = GoogleApiClientTaskHelper .getInstance (activity );
375
- gacHelper .getBuilder ().addApi (Auth .CREDENTIALS_API );
376
- CredentialsApiHelper credentialHelper = CredentialsApiHelper .getInstance (gacHelper );
377
-
378
432
// Get all SmartLock credentials associated with the user
379
433
List <Credential > credentials = SmartLockBase .credentialsFromFirebaseUser (firebaseUser );
380
434
@@ -557,8 +611,8 @@ public SignInIntentBuilder setTosUrl(@Nullable String tosUrl) {
557
611
* <p>If no providers are explicitly specified by calling this method, then the email
558
612
* provider is the default supported provider.
559
613
*
560
- * @param idpConfigs a list of {@link IdpConfig}s, where each {@link IdpConfig} contains
561
- * the configuration parameters for the IDP.
614
+ * @param idpConfigs a list of {@link IdpConfig}s, where each {@link IdpConfig} contains the
615
+ * configuration parameters for the IDP.
562
616
* @see IdpConfig
563
617
*/
564
618
public SignInIntentBuilder setProviders (@ NonNull List <IdpConfig > idpConfigs ) {
0 commit comments