9

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.

Community
  • 1
  • 1
Khalos
  • 2,335
  • 1
  • 23
  • 38
  • 1
    I am curious now since you mentioned my answer on the other similar question as to what your use case is for your application? What behavior do you want to have? Do you want the parse user to always stay the same and have the user use multiple twitter accounts to get to the same parse user? Is this just for testing purposes? Basically I'm having trouble understanding what type of application would want their user to have to perform the actions you're describing. – craigts Dec 12 '15 at 03:57
  • @craigts My use case is this: I want to log in with my twitter account to use the app. My friend comes along and wants to try it out. I sign out of my app, and my friend can sign in using their twitter account. When my friend signs out, if either of us log in again, we get our original account. – Khalos Dec 12 '15 at 19:13
  • 1
    diving into the docs it definitely seems parse does not support this scenario. I think the only solutions specific to this problem are to 1) bug Parse to implement this use case, 2) change the Parse code yourself, or 3) manually handle the Twitter and Facebook auth yourself. A suggestion that avoids this problem would be to try and set up your app so that it makes more sense for the 'friend' in your scenario to download and try the app themselves. Perhaps offer some sort of incentive to both the user and their friend. – craigts Dec 14 '15 at 21:25
  • 1
    @craigts This use case seems like the only sane way to handle authentication though. If I log out of my app, as a user, I expect to be logged out. I don't expect anyone to be able to just click 'Log in with Facebook/Twitter' and be brought right back in without any confirmation. What if I logged in using the wrong Twitter account? There's no way to switch without uninstalling the app? That seems silly. I'm sorry if this sounds argumentative, I don't mean it that way at all. Thank you for your help! – Khalos Dec 15 '15 at 01:26
  • I'm also facing the same problem. I hope you would have solved this. Can you please help me to fix this? – Karthik Aug 08 '16 at 14:26
  • @Karthik Unfortunately I did not. With the announcement that Parse.com was being shut down, I decided to abandon the platform. On the plus side now that it's open source someone could probably fix this issue and submit a PR. – Khalos Aug 09 '16 at 00:47

1 Answers1

1

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?

Stefan Medack
  • 2,731
  • 26
  • 32
  • I also have a class that extends `ParseUser`. Calling `logOutInBackground()` should be the same regarless of whether it's called in an Activity or Service, but I will give it a try. I am using the latest version of the Parse SDK (1.11.0). – Khalos Dec 15 '15 at 01:21