telenordigital / connect-android-sdk

Android SDK for CONNECT ID
https://telenordigital.github.io/id-docs.telenordigital.com/
Other
16 stars 14 forks source link

Logout callback #36

Closed infinityzero closed 8 years ago

infinityzero commented 8 years ago

We can call ConnectSdk.logout() to log out which is making two HTTP requests to revoke both access token and refresh token but callback feature is not exist when two HTTP requests is finished.

public static void logout() {
    Validator.sdkInitialized();
    sConnectIdService.revokeTokens(sContext);
}
public void revokeTokens(Context context) {
    connectApi.revokeToken(
            clientId,
            getAccessToken(),
            new ResponseCallback() {
        @Override
        public void success(Response response) {
        }

        @Override
        public void failure(RetrofitError error) {
            Log.e(ConnectUtils.LOG_TAG, "Failed to call revoke access token on API", error);
        }
    });
    connectApi.revokeToken(
            clientId,
            getRefreshToken(),
            new ResponseCallback() {
        @Override
        public void success(Response response) {
        }

        @Override
        public void failure(RetrofitError error) {
            Log.e(ConnectUtils.LOG_TAG, "Failed to call revoke refresh token on API", error);
        }
    });
    tokenStore.clear();
    currentTokens = null;
    idToken = null;
    ConnectUtils.sendTokenStateChanged(false);
    final CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.removeAllCookies(null);
    } else {
        CookieSyncManager.createInstance(context);
        cookieManager.removeAllCookie();
    }
}

My app needs to listen logout completion callback to make some actions such as navigate to login screen when success or prompt to error message when failed.

Could you please add for logout completion callback?

jorunfa commented 8 years ago

Yes, that makes sense. I will look into it soon.

jorunfa commented 8 years ago

After more consideration I think it would be best to leave this functionality as it is.

It is not vital that you successfully revoke the tokens at the end point, just that you clear them locally will be enough for the times where the async http calls fails. Therefore you should just take the user to the login screen directly after calling ConnectSdk.logout().