|
17 | 17 | import androidx.annotation.NonNull;
|
18 | 18 | import androidx.annotation.Nullable;
|
19 | 19 | import com.google.android.gms.tasks.Task;
|
| 20 | +import com.google.android.gms.tasks.Tasks; |
20 | 21 | import com.google.firebase.FirebaseApp;
|
21 | 22 | import com.google.firebase.auth.GetTokenResult;
|
22 | 23 | import com.google.firebase.auth.internal.IdTokenListener;
|
23 | 24 | import com.google.firebase.auth.internal.InternalAuthProvider;
|
24 |
| -import com.google.firebase.firestore.FirebaseFirestoreException; |
25 |
| -import com.google.firebase.firestore.FirebaseFirestoreException.Code; |
| 25 | +import com.google.firebase.firestore.util.Executors; |
26 | 26 | import com.google.firebase.firestore.util.Listener;
|
| 27 | +import com.google.firebase.firestore.util.Logger; |
27 | 28 |
|
28 | 29 | /**
|
29 | 30 | * FirebaseAuthCredentialsProvider uses Firebase Auth via {@link FirebaseApp} to get an auth token.
|
|
37 | 38 | */
|
38 | 39 | public final class FirebaseAuthCredentialsProvider extends CredentialsProvider {
|
39 | 40 |
|
| 41 | + private static final String LOG_TAG = "FirebaseAuthCredentialsProvider"; |
| 42 | + |
40 | 43 | private final InternalAuthProvider authProvider;
|
41 | 44 |
|
42 | 45 | /**
|
@@ -85,19 +88,21 @@ public synchronized Task<String> getToken() {
|
85 | 88 | // Take note of the current value of the tokenCounter so that this method can fail (with a
|
86 | 89 | // FirebaseFirestoreException) if there is a token change while the request is outstanding.
|
87 | 90 | final int savedCounter = tokenCounter;
|
88 |
| - return res.continueWith( |
| 91 | + return res.continueWithTask( |
| 92 | + Executors.DIRECT_EXECUTOR, |
89 | 93 | task -> {
|
90 | 94 | synchronized (this) {
|
91 | 95 | // Cancel the request since the token changed while the request was outstanding so the
|
92 | 96 | // response is potentially for a previous user (which user, we can't be sure).
|
93 | 97 | if (savedCounter != tokenCounter) {
|
94 |
| - throw new FirebaseFirestoreException( |
95 |
| - "getToken aborted due to token change", Code.ABORTED); |
| 98 | + Logger.debug(LOG_TAG, "getToken aborted due to token change"); |
| 99 | + return getToken(); |
96 | 100 | }
|
97 |
| - if (!task.isSuccessful()) { |
98 |
| - throw task.getException(); |
| 101 | + |
| 102 | + if (task.isSuccessful()) { |
| 103 | + return Tasks.forResult(task.getResult().getToken()); |
99 | 104 | } else {
|
100 |
| - return task.getResult().getToken(); |
| 105 | + return Tasks.forException(task.getException()); |
101 | 106 | }
|
102 | 107 | }
|
103 | 108 | });
|
|
0 commit comments