Skip to content

Twitter Session Even After Logout are Persistent #644

@chiragbhatia94

Description

@chiragbhatia94

My environment

  • Android device: Moto G3
  • Android OS version: Nougat 7.1.1
  • Google Play Services version: 10.2.98
  • Firebase/Play Services SDK version: 1.2.0
  • FirebaseUI version: 1.2.0

Describe the problem:
Once a user logs in using twitter as a provider. Its twitter session is persistent even after he logs out of the firebase account.

Changes required in
com.firebase.ui.auth.provider.TwitterProvider

Proposed solution:
It can be removed by flushing the cookies everytime we call TwitterProvider.startLogin function

This reduces the effort for logging out every time you want to login using different user account
This is similar to what it is there in GoogleProvider

Relevant Code:

Problem starts here
@OverRide
public void startLogin(Activity activity) {
mTwitterAuthClient.authorize(activity, this);
}

Solution
@SuppressWarnings("deprecation")
private static void clearCookies(Context context) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        Log.d(TAG, "Using clearCookies code for API >=" + String.valueOf(Build.VERSION_CODES
                .LOLLIPOP_MR1));
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        Log.d(TAG, "Using clearCookies code for API <" + String.valueOf(Build.VERSION_CODES
                .LOLLIPOP_MR1));
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}

@OverRide
public void startLogin(Activity activity) {
clearCookies(activity);
mTwitterAuthClient.authorize(activity, this);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions