Android Facebook app logout issue - android

My app uses Facebook SDK to post status updates. ALso there is a logout feature. I can login the first time the app is run. I can post status msg in facebook successfully. But once i logout , the subsequent runs and attempts to update status i encounter error from facebook saying "An error occured. Please try again later". I have noticed that the authorize method on subsequent attempts to login ( after the first logout) tries to use the same accessToken and accessExpires ( although i have set them to null and 0 respectively in the logout method) and in turn isSessionValid() method returns true for me. And hence the facebook server throws me this error.
Can anyone please tell me how to fix this bug/issue?

Facebook android SDK sets authtoken and expires_in in shared preferences, so when you logout you need to delete them from there.
Also, any time your app starts you have to validate the saved token making a call to graph api "me", if there is any exception you have to delete saved token and reauthorize. This is because the token might be invalidated (for example when the user changes their password).
hope this helps

Related

Microsoft ADAL acquireTokenSilentSync fails

The token generated by the ADAL is having an expiry of 1 hour. To create the token the app is calling the ADAL method acquireToken. When reopening the app or engaging with the app which was in background/idle for more than 1 hour, the token has to be refreshed. This refresh should happen in the background without user consent. For this, the app is calling the ADAL method acquireTokenSilentSync. This function is throwing an exception an ADAL exception AuthenticationException. Due to this, the app has to be force-closed so that the token will be created again once reopening. Logs are below
Token cache item contains empty refresh token, cannot continue refresh token request ver:3.0.2 Android 28 null
Microsoft.ADAL.request_id: 34533-b84f-45ae-a4f5-29e7h6789d02
Microsoft.ADAL.api_error_code: AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED
Microsoft.ADAL.is_frt: false
Microsoft.ADAL.device_id: lSZf/vWb4AcUTIgbKXDVlQ7jYmBGmLPEMLwHYQao3C4=
Microsoft.ADAL.cache_event_count: 3
[2020-05-14 05:11:21 - 344267-f177-48f8-ad39-ec085udh240c] AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED:Prompt is not allowed and failed to get token. No result returned from acquireTokenSilent ver:3.0.2 Android 28 null
The acquireTokenSilentSync function will first look at the cache and automatically checks for the token expiration. Additionally, if no suitable access token is found in the cache, but refresh token is available, the function will use the refresh token automatically. This method will not show UI for the user. If prompt is needed, the method will return an exception. The Error prompt you are receiving says the Token cache is empty, make sure token is available in the Cache

Parse signup doesn't authenticate the user correctly

I encountered a very strange error when signing up a user using android 6 on a specific device.
The signup process works perfectly and the user is registered on Parse database. The code checks and if ParseUser.getCurrentUser() != null then the app sends the user to the main page and this all works till here.
However, I noticed that user is not able to send any requests to the server and it all rejects in the main activity and user can't even logout. The error I receive when logging out is:
com.parse.ParseRequest $ParseRequestException: This user is not allowed to add a field to _User. You can change this setting in the Data Browser.
It seems like the authenticated user object is not matched with the original user's token on server and that is why this user get ACL errors.
I am using Parse default signup and login functions and this has happened only on one device using android 6 so far. Any guess on what could cause this issue and how can I resolve this issue?
ParseACL roleACL = new ParseACL();
roleACL.setPublicReadAccess(true);
Add these lines after the user Parse.initialize() function. It allow user to create column in the table from mobile. Make sure the user is logged in otherwise it gives error.

Facebook access token request gets cancelled

I'm trying to implement Facebook login in my android app. The problem is that the request to get the access token always gets cancelled when I'm using the native facebook app. When I added this line (forces using a webview):
LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY);
The request is successful. Can anybody tell me how to fix this?
I finally resolved the issue by calling the logOut() of the LoginManager. Apparently if the app is still logged in to Facebook, it will cancel the request.

Unable to get valid Session Token after ParseFacebookUtils.logInWithReadPermissionsInBackground signed up a new user

Hi I'm trying to implement a new app using Parse login with facebook feature.
I followed the Guide to use facebook login feature and all went ok.
Documentation states
Sessions represent an instance of a user logged into a device. Sessions are automatically created when users log in or sign up.
The problem is that I never get a valid session token when ParseFacebookUtils.logInWithReadPermissionsInBackground(...) returns (and signs up) a User which is newly created on the Parse platform (thus User.isNew() is true).
Inspecting the Data dashboard I can see correctly the new _User entry but there's no entry for _Session class, whereas I should find the one with createdWith="signup" for my _User.
As a side effect when trying to logout a newly created user i get a com.parse.ParseException: Parse::UserCannotBeAlteredWithoutSessionError because, obviously, the newly created user doesn't get any session token.
If instead I perform the same operation for the same user after its creation (and therefore the User only logs in into Parse) I get a valid session token and everything's ok (which means there's a _Session object with createdWith="login" associated with the _user object).
Is this a bug or something not expected to occur? Or am I missing something?
Thanks!
Currently using:
facebook-android-sdk:4.0.1 +
ParseFacebookUtilsV4-1.9.1.jar +
Parse 1.9.0 jar

Android FQL Query error

I was successfully making an FQL query earlier today. Now when I try to make the same query I am getting the following message.
"error_code":190,"error_msg":"Error validating access token: The session has been invalidated because the user has changed the password."
I am making the query on my own account, and my password has not been changed. Any suggestions for why this may be happening?
Now I am getting this error.
"Error validating access token: Session does not match current stored session. This may be because the user changed the password since the time the session was created or Facebook has changed the session for security reasons."
Based on above comments, this will be this issue.
The Single Sign On (SSO) in Android allows a user to authorise your app, and once they have done that they will be signed straight in on subsequent visits if they've signed in to Facebook for any application on the phone/tablet.
The downside of this is that the SSO remembers the token and if the token becomes invalidated (by a user de-authorising the app or by them changing password or other details), it will try to use it anyway. You MUST check for those two errors specifically as "isSessionValid() will return true, even though it's not. If you catch one of those two errors, you call the authorize method again.
So, in your case, trap that error, and call authorize().
Documentation from Facebook: http://developers.facebook.com/docs/mobile/android/build/#sso

Categories

Resources