Skip to content

Commit cb0e4c3

Browse files
author
“Akshay
committed
[MOB - 5874] - Schedule auth refresh when auth null
Schedule a 10 second auto refresh for auth handler if auth token is found null when initializing. Also, when authHandler receives a authToken from handler in its handler, a similar null check will schedule 10 second refresh throwing a onTokenRegistrationFailure. This callback should allow them to refresh authToken.
1 parent 03d8a69 commit cb0e4c3

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,13 @@ private void retrieveEmailAndUserId() {
347347
_email = prefs.getString(IterableConstants.SHARED_PREFS_EMAIL_KEY, null);
348348
_userId = prefs.getString(IterableConstants.SHARED_PREFS_USERID_KEY, null);
349349
_authToken = prefs.getString(IterableConstants.SHARED_PREFS_AUTH_TOKEN_KEY, null);
350-
if (_authToken != null) {
351-
getAuthManager().queueExpirationRefresh(_authToken);
350+
if (config.authHandler != null) {
351+
if (_authToken != null) {
352+
getAuthManager().queueExpirationRefresh(_authToken);
353+
} else {
354+
IterableLogger.d(TAG, "Auth token found as null. Scheduling token refresh in 10 seconds...");
355+
getAuthManager().scheduleAuthTokenRefresh(10000);
356+
}
352357
}
353358
} catch (Exception e) {
354359
IterableLogger.e(TAG, "Error while retrieving email/userId/authToken", e);

iterableapi/src/main/java/com/iterable/iterableapi/IterableAuthManager.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public String call() throws Exception {
4949
public void onSuccess(String authToken) {
5050
if (authToken != null) {
5151
queueExpirationRefresh(authToken);
52+
} else {
53+
IterableLogger.w(TAG, "Auth token received as null. Calling the handler in 10 seconds");
54+
//TODO: Make this time configurable and in sync with SDK initialization flow for auth null scenario
55+
scheduleAuthTokenRefresh(10000);
56+
authHandler.onTokenRegistrationFailed(new Throwable("Auth token null"));
57+
return;
5258
}
5359
IterableApi.getInstance().setAuthToken(authToken);
5460
pendingAuth = false;
@@ -88,6 +94,9 @@ public void queueExpirationRefresh(String encodedJWT) {
8894
}
8995
} catch (Exception e) {
9096
IterableLogger.e(TAG, "Error while parsing JWT for the expiration", e);
97+
authHandler.onTokenRegistrationFailed(new Throwable("Auth token decode failure. Scheduling auth token refresh in 10 seconds..."));
98+
//TODO: Sync with configured time duration once feature is available.
99+
scheduleAuthTokenRefresh(10000);
91100
}
92101
}
93102

@@ -102,7 +111,7 @@ void reSyncAuth() {
102111
}
103112
}
104113

105-
private void scheduleAuthTokenRefresh(long timeDuration) {
114+
void scheduleAuthTokenRefresh(long timeDuration) {
106115
timer = new Timer(true);
107116
try {
108117
timer.schedule(new TimerTask() {

0 commit comments

Comments
 (0)