Skip to content

Commit

Permalink
update flow expired token
Browse files Browse the repository at this point in the history
  • Loading branch information
Arief Nur Putranto committed May 2, 2024
1 parent 002554c commit fdf6e9f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.qiscus.sdk.chat.core.data.model.QiscusRefreshToken;
import com.qiscus.sdk.chat.core.data.remote.QiscusApi;
import com.qiscus.sdk.chat.core.data.remote.QiscusPusherApi;
import com.qiscus.sdk.chat.core.event.QiscusRefreshTokenEvent;
import com.qiscus.sdk.chat.core.event.QiscusUserEvent;
import com.qiscus.sdk.chat.core.service.QiscusNetworkCheckerJobService;
import com.qiscus.sdk.chat.core.service.QiscusSyncJobService;
Expand Down Expand Up @@ -1135,6 +1136,12 @@ public void onSuccess(QiscusRefreshToken refreshToken) {
@Override
public void onError(Throwable throwable) {
QiscusErrorLogger.print(throwable);
//need to relogin
EventBus.getDefault().post(
new QiscusRefreshTokenEvent(
401, "Unauthorized"
)
);
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,31 @@ private static void handleResponse(int code, JSONObject jsonResponse) throws JSO
JSONObject jsonObject = jsonResponse.getJSONObject("error");

autoRefreshToken(code, jsonObject);
sendEvent(code, jsonObject);
}

private static void autoRefreshToken(int code, JSONObject jsonObject) throws JSONException {
if (QiscusCore.isAutoRefreshToken()
&& code == EXPIRED_TOKEN
&& jsonObject.getString("message").equals(TOKEN_EXPIRED_MESSAGE)
) {
QiscusCore.refreshToken(null);
QiscusCore.refreshToken(new QiscusCore.SetRefreshTokenListener() {
@Override
public void onSuccess(QiscusRefreshToken refreshToken) {

}

@Override
public void onError(Throwable throwable) {
//need to relogin
EventBus.getDefault().post(
new QiscusRefreshTokenEvent(
401, "Unauthorized"
)
);
}
});
}else{
sendEvent(code, jsonObject);
}
}

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ chatVersionPatch=0

# === qiscus chat-core library version ===
chatCoreVersionMajor=1
chatCoreVersionMinor=7
chatCoreVersionPatch=1
chatCoreVersionMinor=8
chatCoreVersionPatch=0

# === qiscus default base url
BASE_URL_SERVER="https://api.qiscus.com/"
Expand All @@ -54,12 +54,12 @@ QISCUS_SDK_APP_ID="sdksample"

# === properties for androidx
android.useAndroidX=true
android.enableJetifier=true
android.enableJetifier=true
#android.enableR8=true

libraryGroupId=com.qiscus.sdk
libraryArtifactId=chat-core
libraryVersion=1.7.1
libraryVersion=1.8.0

libraryGroupIdChat=com.qiscus.sdk
libraryArtifactIdChat=chat
Expand Down

0 comments on commit fdf6e9f

Please sign in to comment.