Log out or Switch Accounts using Parse Twitter/Facebook Authentication - android

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.

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?

Related

Facebook SDK in Android always calling onCancel

I'm using Facebook SDK v4.6
I'm trying to setup a GraphAPI request class, it will communicate to Facebook Graph API if AccessToken is available. If not, it will pass an error to my Auth class which will initiate the login process
I'm using the code below to start the login process
LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("public_profile, user_photos, user_videos"));
However, the callback onCancel is always triggered whenever I do so, resulting to my application not being able to go through the Graph API process
I'm using a Facebook account which is an administrator for the Facebook app. Also the permissions user_photos and user_videos are already approved in Facebook side, so I don't think that's the problem.
Has anyone experienced the same problem?
I've been trying to look here for solution but majority of what I see is to call logout first before logging-in, but is that even correct?
I tried it on device without Facebook app installed, it repeatedly prompt the login dialog even though the user already logged-in previously (i concluded it's to be expected since we logged-out, but I wouldn't want user to repeatedly log-in after access token is expired) or is there no other way?
First make sure that,
App Id integrated with you app and App Id in Dashboard are the same or not.
Facebook user you are trying to login is a developer of your app.
(Because some permissions like 'publish_actions' will work with
developer account only not with the test user.)
Login function and Graph request should be called with main thread
of your app.
These are the issues i have faced. Still if you can't solve the issue , go through Facebook documentation once again.

how to test Facebook Login for my mobile app

I am adding Facebook login to my app so to get permission to post photos for users. Having created the code, I now want to test that it works. So naturally I am using my own Facebook again to see that the system works. The first time I went through, I found some stuff I didn't like. So I made the changes. Now that I want to test again using my Facebook again, when I login, Facebook keeps telling me that I already gave the app permission. I tried uninstalling the app and then re-install, just in case it was caching locally. But that didn't help. So my question is: how do I get to reuse my account to login and request the permissions again? I hope the question is clear. If not, please ask for clarification.
I am experiencing this problem with android. But I am guessing it's similar for iOS, so I use both tags.
Open the following page in your browser: https://www.facebook.com/settings?tab=applications
Your App should be in that list, just remove it to test the authorization again.

Facebook Android SDK, prompt user authentication to switch sessions

This is kinda hard to explain. I'm building an application on android which is supposed to be used in a meeting in like a "stand" so people would submit some feedback after the meeting. Please notice there's a bunch of people who is going to use this application on the same device.
The application is gonna be used from different users on the same device and all of them are supposed to login with their Facebook account before continuing. For security reasons, I would love to have a way to distroy a Facebook session after a poll is submitted or simply, every time a new poll is issued, when the user is requiered to login on Facebook, I would like to force Facebook to prompt an authentication dialog (username and password again) even though there's an active session.
I've looked everywhere and I have found nothing. I know there's a way to request on Facebook a extensed permission to logout, but please notice this permission needs to be approved after logging in, so if a user, after logging in, just decide not to approve this permission, this session is going to be there until a browser is opened and a logout is performed from the Facebook site.
I've also thought on destroying a browser cookies but I don't know if is there such a permission on the android SDK to perform this.
Please, if any body has any idea on to get rid of this issue, I would really appreciate any suggestion or work around.
I believe you can do this with the Facebook SDK for Android 3.0 (beta).
You can turn off SSO (by using the SUPPRESS_SSO behavior) which should bring up a web dialog every time. And once the user is done interacting with your app, you can just call session.closeAndClearTokenInformation()
Cookies are not preserved when using the dialog login.

Use Facebook authentication for an Android application

I am working on an application where I need to integrate the social functionality of Facebook.
What I want is to know if the user is already connected to Facebook through a Facebook application or some other application that uses Facebook, and use this authentication. That means that if the user is already connect to Facebook through his device I recognize that and use it in my application - not ask the user for a new login.
Is it possible?
I found a lot stuff in the web, but nothing is related to that. I already downloaded the facebook SDK and added it to my project. I saw that there is a method (facebook.getAccessToken()) to get the access token, but I think I can use it only if the user do his first login in my application.
Any help would be great.
Thanks.
That means that if the user is already connect to Facebook through his device I recognize that and use it in my application - not ask the user for a new login.
Yes it is possible..This is called as Single-Sign-On in facebook , by default Single-Sign-On is enabled. One and only thing you have to do is that you need to generate Hash Key and Register with your Application created in Facebook.
Also it is possible to disable Single-Single-On by passing an extra parameter as below :
authenticatedFacebook.authorize(context PERMISSIONS,-1,new LoginListener());
-1 - refers disabling SSO
Single-Sign-On is clearly explained in Facebook Documentation..

More advanced android facebook example

I'm having some problems with facebook integration on my android app. I've looked at the examples that come with the api and i can do the things shown in those ok. But i'm having problems with other things such as getting single sign on to work properly, authentication across multiple activities in the app and loading a facebook page (non-api call) without being asked to log in again.
Anyone have examples that show these?
When making API calls, you usually need to include the access_token parameter that was issued when the user authenticated. This is how facebook knows who you are when you make requests.
Similarly, when loading facebook pages (not using the API), you have to remember to send the cookies Facebook sent when the user logged in. Normally the browser keeps track of these automatically, but in your program or app you might have to handle them manually.
I don't have experience with Android specifically, and I don't know what you're using to load and render facebook pages, but knowing how facebook is keeping track of logged-in users should give you an idea of where to start. A google search or two should get you on your way.
Go to facebook.java class and change package name com.facebook.katana to com.facebook.katanaaa or any one of your own choice. This worked for me .

Categories

Resources