|
2 | 2 |
|
3 | 3 | import android.util.Base64;
|
4 | 4 |
|
5 |
| -import androidx.annotation.Nullable; |
6 | 5 | import androidx.annotation.VisibleForTesting;
|
7 | 6 |
|
8 | 7 | import com.iterable.iterableapi.util.Future;
|
@@ -35,44 +34,37 @@ public class IterableAuthManager {
|
35 | 34 | }
|
36 | 35 |
|
37 | 36 | public synchronized void requestNewAuthToken(boolean hasFailedPriorAuth) {
|
38 |
| - requestNewAuthToken(hasFailedPriorAuth, null); |
39 |
| - } |
40 |
| - |
41 |
| - public synchronized void requestNewAuthToken(boolean hasFailedPriorAuth, @Nullable final IterableHelper.SuccessAuthHandler onSuccess) { |
42 | 37 | if (authHandler != null) {
|
43 | 38 | if (!pendingAuth) {
|
44 | 39 | if (!(this.hasFailedPriorAuth && hasFailedPriorAuth)) {
|
45 | 40 | this.hasFailedPriorAuth = hasFailedPriorAuth;
|
46 | 41 | pendingAuth = true;
|
47 | 42 | Future.runAsync(new Callable<String>() {
|
48 |
| - @Override |
49 |
| - public String call() throws Exception { |
50 |
| - return authHandler.onAuthTokenRequested(); |
51 |
| - } |
52 |
| - }).onSuccess(new Future.SuccessCallback<String>() { |
53 |
| - @Override |
54 |
| - public void onSuccess(String authToken) { |
55 |
| - if (authToken != null) { |
56 |
| - queueExpirationRefresh(authToken); |
57 |
| - } |
58 |
| - |
59 |
| - IterableApi.getInstance().setAuthToken(authToken); |
60 |
| - pendingAuth = false; |
61 |
| - reSyncAuth(); |
62 |
| - |
63 |
| - if (onSuccess != null) { |
64 |
| - onSuccess(authToken); |
65 |
| - } |
66 |
| - } |
67 |
| - }) |
68 |
| - .onFailure(new Future.FailureCallback() { |
69 |
| - @Override |
70 |
| - public void onFailure(Throwable throwable) { |
71 |
| - IterableLogger.e(TAG, "Error while requesting Auth Token", throwable); |
72 |
| - pendingAuth = false; |
73 |
| - reSyncAuth(); |
74 |
| - } |
75 |
| - }); |
| 43 | + @Override |
| 44 | + public String call() throws Exception { |
| 45 | + return authHandler.onAuthTokenRequested(); |
| 46 | + } |
| 47 | + }).onSuccess(new Future.SuccessCallback<String>() { |
| 48 | + @Override |
| 49 | + public void onSuccess(String authToken) { |
| 50 | + if (authToken != null) { |
| 51 | + queueExpirationRefresh(authToken); |
| 52 | + } |
| 53 | + IterableApi.getInstance().setAuthToken(authToken); |
| 54 | + pendingAuth = false; |
| 55 | + reSyncAuth(); |
| 56 | + authHandler.onTokenRegistrationSuccessful(authToken); |
| 57 | + } |
| 58 | + }) |
| 59 | + .onFailure(new Future.FailureCallback() { |
| 60 | + @Override |
| 61 | + public void onFailure(Throwable throwable) { |
| 62 | + IterableLogger.e(TAG, "Error while requesting Auth Token", throwable); |
| 63 | + authHandler.onTokenRegistrationFailed(throwable); |
| 64 | + pendingAuth = false; |
| 65 | + reSyncAuth(); |
| 66 | + } |
| 67 | + }); |
76 | 68 | }
|
77 | 69 | } else if (!hasFailedPriorAuth) {
|
78 | 70 | //setFlag to resync auth after current auth returns
|
|
0 commit comments