Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log out or Switch Accounts using Parse Twitter/Facebook Authentication

I am using parse.com's Android API and have added Facebook/Twitter login support. This is working fine.

The tricky part appears to be logging out.

If I log in to my app using Twitter:

ParseTwitterUtils.logIn(UserLoginActivity.this, twitterLoginCallback);

Or using Facebook:

ParseFacebookUtils.logInWithReadPermissionsInBackground(UserLoginActivity.this, null, facebookLoginCallback);

I am prompted in a web dialog to enter my twitter credentials and then allow or deny access to my app. Once I allow it, I am able to log in successfulyl and I have access to my screen name. All is well!

When I try to log out of my ParseUser, I do get logged out. However, if I click either the Facebook or Twitter login button again, I am pre-authenticated as my previous account, I can't switch accounts.

I have tried:

  • Checking Chrome and Browser and neither are logged in to Twitter.
  • Logging out of the native Twitter/Facebook app

My login logic started as simply:

ParseUser.logOut();

For Twitter I have tried

  • Uninstalling my application - This does fix it but is not an ideal solution.
  • Not calling Parse.enableLocalDatastore(this); in my Application as suggested here: https://stackoverflow.com/a/26338326/494356
  • Unlinking the Twitter account as suggested here: https://stackoverflow.com/a/34052718/494356. This also has the bad side effect of creating a new ParseUser each time (but still for the same Twitter account)
  • I have tried changing permissions from 'Read Only` to 'Read and Write' as suggested here https://stackoverflow.com/a/27714159/494356. (Why this would matter doesn't really make sense to me anyway)
  • I have tried setting the AuthToken to null ParseTwitterUtils.getTwitter().setAuthToken(null); ParseTwitterUtils.getTwitter().setAuthTokenSecret(null);

For Facebook I have tried

  • Uninstalling my application - This does not solve the problem.
  • Using the Facebook SDK Logout Features:

    AccessToken.setCurrentAccessToken(null);

    Profile.setCurrentProfile(null);

    LoginManager.getInstance().logOut();

  • There used to be a Session.closeAndClearTokenInformation() as suggested here. But Facebook has Deprecated the Session class and it is no longer in the SDK.

  • Unlinking the Facebook account as suggested here. Again this causes duplicate ParseUsers and I am still able to log in using the saved credentials.

I would really appreciate any answers or suggestions. Even if you can only answer for either Twitter or Facebook but not both I would still love to hear it.

like image 576
Khalos Avatar asked Dec 05 '15 05:12

Khalos


People also ask

How to switch accounts on Facebook?

Click on the account switcher icon at the top. In case you haven’t added any additional Facebook account, click on Add account. Enter your login details. Later, when you need to switch accounts, tap on the account listed under the account switcher icon. Tip: To remove an account, click on the small cross icon on the account name.

How do I log out of all accounts on Twitter?

If you want to sign out of the account you’re currently viewing, click the “Log Out” button. If you want to remove every account, select the “Manage Accounts” button. Finally, click the “Log Out Of All Accounts” to sign out of every Twitter profile authenticated on your computer.

How do I switch between Twitter accounts?

Switch between Twitter Accounts Now that you have signed in to multiple Twitter accounts, you can easily switch between them. Start by heading to Twitter’s website using your computer and checking that you’re signed in to your primary account. Next, click on your profile in the bottom-left corner.

What is account switcher on Facebook and messenger?

It’s a great and fastest way to log out and log in to more than one Facebook or Messenger account. When you switch accounts, you will receive notifications only for the account in which you are logged in. The account switcher feature is available only on facebook.com desktop version. The feature isn’t available on Facebook mobile apps.


1 Answers

In our App the login/logout process works fine for Facebook, E-Mail and even an own build google login. I can tell you the differences I see on the first look and maybe one of it does the trick for you.

First of all we do not work with the ParseUser instance directly in our code, but have a MyUser class that extends ParseUser. Second of all the login logic is encapsulated in a background service and not called directly in our Activity. That probably won't fix the problem. But in the background service we also cache the MyUser instance, retrieve it if we need it and use that instance to logout the user (MyUser.logOut()). And it is set to null after the logout.

Last but not least: are you running the latest versions of the Parse SDK?

like image 53
Stefan Medack Avatar answered Oct 19 '22 22:10

Stefan Medack